Reply

Next vaialble ip for a subnet

Authority
Posts: 21
11922     0

Hi All

 

I am trying to get the next availble IP for a subnet and reserve it.

 

https://ddi.sss.test.net/wapi/v2.10.5/network/ZG5zLm5ldHdvcmskMTAuMTI0LjExLjAvMjcvMA:10.124.11.0/27/default?_function=next_available_ip&_return_as_object=1 -d {num:1}

But it is giving me error like below

 

    "Error": "AdmConProtoError: Invalid value for _return_as_object: 1 -d {num:1}",
    "code": "Client.Ibap.Proto",
    "text": "Invalid value for _return_as_object: 1 -d {num:1}"

i tried changing things but getting different different errors. taken the _ref for the subnet also.

Please help me in this.

Re: Next vaialble ip for a subnet

Adviser
Posts: 181
11922     0

Hi,

 

You would need to do a POST operation to get the next available IP.

curl -k -u admin:infoblox -H 'content-type: application/json' -X POST "https://grid-
master/wapi/v2.11/network/ZG5zLm5ldHdvcmskMTcyLjIxLjEwLjAvMjQvMA:172.21.10.0/24/default?_function
=next_available_ip&_return_as_object=1" -d '{"num":1}' 

You can find the example here.

 

Hope this is helpful,

Thanks & Regards,

Krishna

Re: Next vaialble ip for a subnet

Authority
Posts: 21
11922     0

Thanks for your response. but i am usign postman for the request and when i am adding

-d '{"num":1}'

 at the end i am getting below error: 

    "Error": "AdmConProtoError: Invalid value for _return_as_object: 1 -d '{\"num\":1}' ",
    "code": "Client.Ibap.Proto",
    "text": "Invalid value for _return_as_object: 1 -d '{\"num\":1}' "

Re: Next vaialble ip for a subnet

Adviser
Posts: 181
11922     0

Hi,

 

In case of Postman, you would have to specify this in the Body section, and not as part of the URL.

Community-WAPI-POSTman.png

Regards,

Krishna Vasudevan

Re: Next vaialble ip for a subnet

[ Edited ]
Moderator
Moderator
Posts: 321
11922     0

I'd recommend a multiple body request, to retrieve the container ref and generate the new network, all in a single call.

 

Also I'd recommend using Postman variables for the gridmaster IP and WAPI version so they can be adjusted as needed for all calls.

 

The request type is POST and the url is https://{{gridmaster}}/wapi/{{version}}/request

 

The body is:

[
  {
    "method":"GET",
    "object":"networkcontainer",
    "data": {
  		"network": "10.0.0.0/8"
  	},
  	"assign_state": {"my_ref": "_ref" },
    "enable_substitution": true,
    "discard": true
  },
  {
    "method":"POST",
	"object": "network",
	"enable_substitution": true,
	"data": {
      "network": "func:nextavailablenetwork:##STATE:my_ref:##,24",
      "comment": "Created by Next Available Network"
	}
  }
]

 

Here's what it looks like in Postman, with a successful response shown in the response body:

 

next-network.png

Re: Next vaialble ip for a subnet

Authority
Posts: 21
11923     0

Thanks for the response @krishna. one more thing i need help is same request further i will use this url in powershell script like below

$url = "https://ddi.sss.st-gin.net/wapi/v2.10.5/network"
$Result = Invoke-RestMethod -Uri $url -Method Get -Credential $creds -Headers $headers -ContentType 'application/json'

So in this case where i have to mention the in the body, so how to do that

num:1

Re: Next vaialble ip for a subnet

Adviser
Posts: 181
11923     0

Hi,

 

You would need to specify it as part of the body parameter.

 

$url = "https://grid-master/wapi/v2.11/network/ZG5zLm5ldHdvcmskMTkyLjE2OC4xMS4wLzI0LzA:192.168.11.0/24/default?_function=next_available_ip" 
$pwd = ConvertTo-SecureString "pwd" -AsPlainText -Force 
$creds = New-Object Management.Automation.PSCredential ('admin', $pwd) 
$num_details = @{ 
  num=1} 
$body = $num_details | ConvertTo-Json 
Invoke-RestMethod -Uri $url -Method POST -Credential $creds -ContentType 'application/json' -Body $body 

Regards,

Krishna

Re: Next vaialble ip for a subnet

Authority
Posts: 21
11923     0

Thanks a lot @Krishna for your help.

Re: Next vaialble ip for a subnet

New Member
Posts: 1
11923     0

Do you know if the next_available_ip function is getting the IP address from the IP range specified in the DHCP scope?

 

The reason for my question is that I am getting "Cannot find 1 available IP address(es) in this network." error but we are seeing a lot of available IP addresses in the UI > IPAM view.

Re: Next vaialble ip for a subnet

New Member
Posts: 2
11923     0

Hi!

Is't possible to use tags to fetch next availible IP address in some way? My thoughtwas to tag multiple network and from query tag IPAM fetch next availible ip from those network that is taged equal.
Or if there is any other way of doing im very much interested.

 

Thanks in advance

Patric

 

Re: Next vaialble ip for a subnet

Superuser
Posts: 65
11923     0

You can do this using the multiple body request discussed above. In this example, I search on tow EAs, Site and Building, to identify the network and then find the next available IP in that network:

[
  {
    "method": "GET",
    "object": "network",
    "data": 
    {
      "*Site": "HQ",
      "*Building": "Two"
    },
    "assign_state": 
    {
      "netw_ref": "_ref"
    },
    "discard": true
  },
  {
    "method": "POST",
    "object": "##STATE:netw_ref:##",
    "args": 
    {
      "_function": "next_available_ip"
    },
    "enable_substitution": true
  }
]
Showing results for 
Search instead for 
Did you mean: 

Recommended for You