API & Integration

Reply
Accepted Solution

Get Next Available IP and Reserve

RdeVries_2
Techie
Posts: 6
3594     0

Does the WAPI allow a single call to get the next available IP and Reserve?

 

VitalQIP had an API call that would return the next available IP address and immediately reserve it if desired. This is great way to avoid potential race conditions.

 

 

I was able to request the next available IP in InfoBlox via: 

 

/network/<reference>?_function=next_available_ip&num=1

 

but I don't see any way to immediately reserve it. Is this possible?

 

Thank you.

 

   Richard

Re: Get Next Available IP and Reserve

Moderator BRampling
Moderator
Posts: 69
3594     0

This is definitely possible. I shamelessly stole this example from the "Definitive list of REST examples" post here:

 

https://community.infoblox.com/t5/API-Integration/The-definitive-list-of-REST-examples/td-p/1214

 

Add a HOST with next_available IP address from a network

 POST /wapi/v1.2/record:host
 Content-Type: application/json

    { "name":"wapi.test.org",
      "ipv4addrs":[
          {
             "ipv4addr":"func:nextavailableip:10.1.1.0/24"
          }
        ]
    }

You can do this with almost any kind of record that uses the "ipv4addr" field such as a fixed address, Host record, A record, etc. There are more details in the post I linked above.

Re: Get Next Available IP and Reserve

RdeVries_2
Techie
Posts: 6
3594     0

Thank you, going to give that a shot!

Re: Get Next Available IP and Reserve

RdeVries_2
Techie
Posts: 6
3594     0

Would you happen to know if there is an XML equivelant payload for this?

 

I tried this, but it doesn't work:

 

      <value type="object">
        <name>test.mydomain.org</name>
        <ipv4addrs>
          <list>
            <value type="object">
              <ipv4addr>$func:nextavailableip:10.11.12.0/32</ipv4addr>
            </value>
          </list>
        </ipv4addrs>
      </value>

 

Error is:

 

Invalid value for ipv4addr: "$func:nextavailableip:10.11.12.0/32": Invalid IPv4 address

 

Thank you.

Re: Get Next Available IP and Reserve

AutoMyNet
Techie
Posts: 2
3594     0

I get the same error when trying to run that REST call. Has anyone gotten that one to work properly?

Re: Get Next Available IP and Reserve

AutoMyNet
Techie
Posts: 2
3594     0
Figured out I was using too old of a WAPI version. Was trying v1.2 like most of the examples on the REST examples thread - started using a later version and it worked fine.

Re: Get Next Available IP and Reserve

[ Edited ]
berridgd
Techie
Posts: 11
3594     0

I have been using this function to retrieve IPs from one of our subnets but I've ran into an issue. After making the rest call three times it fails on the fourth with the following error...

 

"text": "Cannot find 1 available IP address(es) in this range."

 

This is strange because if I look at the IP Map in the IPAM view through the web console there are at least 25 unused IPs in the subnet. Why does the WAPI say there are none?

Re: Get Next Available IP and Reserve

Adviser
Posts: 57
3594     0

If the message indicates there are no more available addresses in the range, you are likely requesting addresses within a DHCP range or a reserved range, and not within the full network.

 

Can you post an example of the code you're using?

Highlighted

Re: Get Next Available IP and Reserve

[ Edited ]
berridgd
Techie
Posts: 11
3594     0

Sure, I am doing a POST to the url "/fixedaddress?_return_fields=ipv4addr" with the following JSON payload...

 

 

{"name": fqdn,
 "ipv4addr":"func:nextavailableip:10.1.1.11-10.1.1.250",
  'mac':'00:00:00:00:00:00'};

 

I did it this way to skip the first 10 IPs in the subnet. It is a DHCP range but the web console is showing a lot of unused addresses and the WAPI is still complaining that there are none. Maybe I'm completely misunderstanding the meaning of 'unused' in the Infoblox world.

 

Re: Get Next Available IP and Reserve

[ Edited ]
berridgd
Techie
Posts: 11
3595     0

After a little bit more digging I've noticed that the IP addresses that are being picked up from the WAPI call have a Lease state of 'Free' where as all of the other unused IP addresses have a Lease state of 'Abandoned'.

Showing results for 
Search instead for 
Do you mean 

Recommended for You