record:host and multi-threaded environment

Not applicable
Posts: 1
5386     0



I'm using infoblox rest api (embedded in a bigger java project) to automate some tasks around the ip reservation.and host-record creation.

my scenario:

  1. 1st api call: get next available ip from the given network (next_available_ip)
  2. 2nd api call: create a new host object (record:host constructor with hostname and ip from step 1. as parameters


It works, however is dangerous and not very reliable - could happend that the ip4addr, that should be free (we just obtained it via next_available_ip), has been already used to create a new host record in a parallel thread). Even worse, we recently had an issue where two attempts to create record:host-Objects with different hostnames and the same ip have been started simultaneously and both succeeded, which should not be possible (due to an ip conflict, I assume).


Do you guys know, if there is a single api call to get-free-ip-and-register-a-new-host-record? How to make sure, that the steps needed to create a new host (ptr+a records) are atomic and the whole operation is multi-thread-safe?


Thanks in advance for any hints/links/examples,


RE: record:host with exclude and multi-threaded environment

Posts: 3
5387     0
I have a similar issue and would really appreciate a solution to this issue... I tried the following command, but it failed as well - curl -k -u admin:infoblox -H "Content-Type: application/json" -X POST -d '{"name":"generic-nocl.test.local","ipv4addrs":["ipv4addr":{"_function":"next_available_ip","_object_field":"value","_object":"","_parameters":{"num":1,"exclude":[ ""],}}]}' { "Error": "AdmConProtoError: JSON Decoding: Expecting , delimiter: line 1 column 58 (char 58)", "code": "Client.Ibap.Proto.JSONDecoding", "text": "JSON Decoding: Expecting , delimiter: line 1 column 58 (char 58)" } All I'm trying to do is create a host object using the next available IP and excluding from being used. I followed the instructions as specified on the definitive rest api examples page: Many thanks for the help. I appreciate -

Corrected example using next_available_ip function

Posts: 135
5387     0

My apologies for the delay in responding. Unfortunately the example code that you used from the "Definitive List of REST Examples" post is incorrect, at least for WAPI 2.0. The following curl command works on my (NIOS 7.2) system:

curl --tlsv1 --insecure --user 'admin:infoblox' -H "Content-Type: application/json" -X POST -d '{"name": "", "ipv4addrs": [{"ipv4addr": {"_object_function": "next_available_ip", "_object": "network", "_object_parameters": {"network": ""}, "_result_field": "ips", "_parameters": {"num": 1, "exclude": [""]}}}]}'

The function call mechanism works as follows:

In a normal WAPI call to create a host record the ipv4addr parameter would be followed by a string value (e.g., "") identifying the IP address value. If you want the IP address value to be the result of a function call then you replace the string with a set of key/value pairs enclosed in curly braces, where those pairs identify the name of function to be called, the exact object on which the function is to be called, the parameters to be passed to the function, and the result field to be used from the function. More specifically:

  • _object_function identifies the name of the function to be called, in this case next_available_ip.
  • _object and _object_parameters together identify the object on which the function will be called. The next_available_ip function can be called against either a network object or a range object. In this case we use _object to note that we are calling the next_available_ip function against a network object, and _object_parameters to identify (through a search) the exact network object to use.
  • _result_field identifies the particular field returned from the function call that we wish to use. The next_available_ip function returns the IP address(es) it finds in the field ips, so that's what we use for the value of _result_field.
  • _parameters identifies the parameters to be passed to the function. In this case we pass the parameter num set to the value 1 to return only one address, and the parameter exclude set to the list of addresses we wish to exclude.

Note that alternatively you can use an object reference to specify the object on which to call the function. For example, if you had previously determined that the network you wanted to use had the object reference "network/ZG5zLm5ldHdvcmskMTAuMC4wLjAvMjQvMA:" then you could have used the following curl command instead:

curl --tlsv1 --insecure --user 'admin:infoblox' -H "Content-Type: application/json" -X POST -d '{"name": "", "ipv4addrs": [{"ipv4addr": {"_object_function": "next_available_ip", "_object_ref": "network/ZG5zLm5ldHdvcmskMTAuMC4wLjAvMjQvMA:", "_result_field": "ips", "_parameters": {"num": 1, "exclude": [""]}}}]}'

Simpler way to do atomic "get ip, create host"

Posts: 135
5387     0

For anyone who comes across this thread and reads my post above, I wanted to note that there is a much simpler way to handle the common case of getting an available IP address and creating a host record in a single operation. Here is an example curl command (based on the examples above):

curl --tlsv1 --insecure --user 'admin:infoblox' -H "Content-Type: application/json" -X POST -d '{"name": "", "ipv4addrs": [{"ipv4addr": "func:nextavailableip:"}]}'

The main disadvantage of this method is that you can't specify additional parameters like a list of IP addresses to exclude.

Corrected example using next_available_ip function

Posts: 3
5387     0

Perfect! This worked beautifully... Hey can I plead w/ you to please update the Definitive List of REST Examples page? Smiley Happy
Many thanks. We appreciate

Updating the "definitive list"

Posts: 135
5387     0

Unfortunately I can't update the "definitive list of REST examples" myself because I didn't post the original list and don't have edit rights on the post. However I'll post a followup correction for that particular example.

Re: record:host and multi-threaded environment

Posts: 52
5387     0

I'm looking for a query that will return the open ports that are discovred for a given IP address.


I'm thinking something along the lines of:

But that doesn;t seem to return anything at this point, but I may have an issue with Discovery in general, and I'm opening a ticket for that.


While I wait on the ticket, am I close?

Showing results for 
Search instead for 
Did you mean: 

Recommended for You