Reply

Getting the next available subnet and reserving it

Techie
Posts: 4
4687     0

Hi,

 

I have seen examples of how to get the next available IP and reserve it.  However I am looking for a way to get the next available network and reserve it/mark it as used with comments if possible.

 

I can obtain the next available subnet via the following API call

 

 

curl -k1 -u admin -X POST 'https://infoblox.local/wapi/v2.7/network network=func:nextavailablenetwork:172.16.0.0/24,29'

 

However I'm not sure how to then reserve that entire subnet.

 

Many thanks.]

 

Re: Getting the next available subnet and reserving it

Adviser
Posts: 198
4688     0

Hi,

 

You can use the nextavailablenetwork function while creating a network, as shown below. This will create/reserve the network and add a comment to indicate that it is used.

curl -k -u admin:infoblox -H 'content-type: application/json' -X POST "https://grid-master/wapi/v2.7/network?_return_fields%2B=network,comment&_return_as_object=1" -d '{"network": "func:nextavailablenetwork:192.0.0.0/8,default,24","comment": "Used"}'

Sample output:

{
    "result": {
        "_ref": "network/ZG5zLm5ldHdvcmskMTkyLjAuNS4wLzI0LzA:192.0.5.0/24/default",
        "comment": "Used",
        "network": "192.0.5.0/24",
        "network_view": "default"
    }
}

Hope this is what you are looking for.

Re: Getting the next available subnet and reserving it

Techie
Posts: 9
4688     0
curl -k -u admin:infoblox -H 'content-type: application/json' -X POST "https://grid-master/wapi/v2.7/network?_return_fields%2B=network,comment&_return_as_object=1" -d '{"network": "func:nextavailablenetwork:192.0.0.0/8,default,24","comment": "Used","network_view":"default"}'

Just to clarify, network_view is required if you don't want it falling into the default view.

Re: Getting the next available subnet and reserving it

Techie
Posts: 4
4688     0

Would it be possible to get a python example for the solution ?

 

I'm trying get next available subnet by using the code below but getting the error 

 

#!/usr/bin/python3

import requests


requests.packages.urllib3.disable_warnings()

url = "https://11.1.1.1/wapi/v2.11/network?_return_fields%2B=network&_return_as_object=1"                                                                               work_view":"default"} 

querystring = {"network":{"_object_function":"next_available_network","_result_field":"networks","_object":"network","_object_parameters":{},"_parameters":{"cidr":24}},"net
work_view":"default"}

response = requests.request("POST", url, auth=('cloud-api', 'cloud'), params=querystring,verify=False)
                                                                                                                                                                                                                                                                
print(response.text) 


{ "Error": "AdmConProtoError: Unknown object type ()",
"code": "Client.Ibap.Proto",
"text": "Unknown object type ()"
}

Re: Getting the next available subnet and reserving it

Adviser
Posts: 198
4688     0

Hi,

 

Could you please try the following code:

import requests
requests.packages.urllib3.disable_warnings() # Disable SSL warnings in requests #
url = "https://grid-master/wapi/v2.11/network?_return_fields%2B=network&_return_as_object=1"
payload = "{\"network\":{\"_object_function\":\"next_available_network\",\"_result_field\":\"networks\",\"_object\":\"network\",\"_parameters\":{\"cidr\":24}},\"network_view\":\"default\"}"
headers = {'content-type': "application/json"}
response = requests.request("POST", url, auth=('cloud-api', 'cloud'), data=payload, headers=headers,
verify=False)

Regards,

Krishna Vasudevan

Re: Getting the next available subnet and reserving it

[ Edited ]
Member
Posts: 2
4688     0

Is there a way to request next available network by only specifying the network view & cidr size desired? Example provides requires network view & network container & cidr size. Thanks! 

Re: Getting the next available subnet and reserving it

Adviser
Posts: 464
4688     0

You can use an EA instead with Request

 

curl --location -g --request POST 'https://{{grid_master}}/wapi/v2.7/request' \
--header 'Content-Type: application/json' \
--data-raw '[
{
    "method": "GET",
    "object": "networkcontainer",
    "data": {
            "*SifLoc:": "Texas"
    },
    "assign_state": {
    	"netw_ref": "_ref"
    },
    "discard": true
},
{
	"method": "GET",
	"object": "##STATE:netw_ref:##",
	"enable_substitution": true
    },
    "assign_state": {
        "network": "network"
    },
},

{
    "method": "GET",
    "network": "func:nextavailablenetwork:##STATE:netwk:##,24",
    "network_view": "default"
}
]

'

 

 

 

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

https://sifbaksh.com

Re: Getting the next available subnet and reserving it

Member
Posts: 2
4688     0

Thank you! Will review to see how we may incorporate. Much appreciated! Smiley Happy

Showing results for 
Search instead for 
Did you mean: 

Recommended for You