Reputation: 383
I have a collection of network objects in my Infoblox (IPAM) server and would like to allocate an IP address from one of them based on a search into their extattr fields.
Each network object has an extended attribute named CITYCODE, and many networks have the same value for that code. I want to allocate an IP address from any of those networks.
How can I use the next_available_ip function to create a record:host object, where the IPV4ADDR is determined by the next_available_ip function?
Upvotes: 0
Views: 1617
Reputation: 383
Answering my own question because it took some poking with other example code I found to get one that worked exactly right for me.
First you need a JSON body that specifies the fully qualified name of the new record:host. For my purposes I'm just generating random values. Note, that the domain must already exist (likely as a zone:auth object).
If the domain does not already exist you'll get the error: "The action is not allowed. A parent was not found."
Instead of specifying an actual ipv4addr, instead specify the target object and the function you will run against it. Since we want to run the next_available_ip function, the object is network.
The search we want to do is against an extensible attribute, so the _object_parameters are set to say "find networks that have an extensible attribute called -CITYCODE- with value -MZAPPKAK-. The asterisk is important and must be kept.
BODY='
{
"name" : "staticip-d4260ed7-3101-4034-0f79-056b72b2c5f0.some-domain-that-exists.com",
"ipv4addrs : [
{
"ipv4addr" : {
"_object" : "network",
"_object_function" : "next_available_ip",
"_object_parameters" : {"*CITYCODE" : "MZAPPKAK"},
"_object_field" : "value",
"_result_field" : "ips",
"_parameters" : {"num" : 1}
}
}
]
}
curl \
'https://1.2.3.4/wapi/v2.2.1/record:host' \
-H 'Content-Type: application/json' \
-d "$BODY"
The result code should be 201, and the result body will be a REF to the record:host that was created. Do a standard GET on the returned REF to learn what IP was found and placed on the record.
Upvotes: 1