Reply
Accepted Solution

Get Next Available IP and Reserve

RdeVries_2
Techie
Posts: 6
867     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: 87
867     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
867     0

Thank you, going to give that a shot!

Re: Get Next Available IP and Reserve

RdeVries_2
Techie
Posts: 6
867     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
867     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
867     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
867     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: 99
867     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?

Re: Get Next Available IP and Reserve

[ Edited ]
berridgd
Techie
Posts: 11
867     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
867     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'.

Highlighted

Re: Get Next Available IP and Reserve

DarkLite1
Techie
Posts: 2
867     0

s there a way to get one of the 'Abandoned' ones?

Re: Get Next Available IP and Reserve

TTiscareno Community Manager
Community Manager
Posts: 361
868     0

Abandoned leases are only used when free leases have been exhausted. If you are concerned about abandoned leases, you will want to investigate why they are in this state because these indicate that IP conflicts are being detected by the DHCP server or clients and may point to a problem on your network. It could be that a separate device is responding to lease requests and causing conflicts to occur, roque DHCP server on the network, clients that are configured with static IP's from the DHCP range, or even a device that is responding to ping or ARP broadcast requests that are used to determine if an IP is free or in use.

 

An easy way to tell if you have an actual problem is to clear the abandoned leases and see if they come back again. Starting in NIOS version 8.4.0, this can be done via the CLI:

 

Infoblox> delete leases without_ends --state ABANDONED

 

Otherwise, this can be done via script or individually via the GUI.

 

Regards,

Tony

Showing results for 
Search instead for 
Do you mean 

Recommended for You