08-23-2017 01:31 PM
Looking for an API command that would allow me to GET "next-available-network". This would be used when subnetting a larger network into dedicated project LANs. This would be used based on a range or possible EA. For example a network range of 10.0.0.0 to 10.0.100.0 would be used for dedicated project network ranging in size from a /29 to a /24 and sliced up accordingly. I want use the command to GET and assign the next available network of a specified size. By assign I mean assigning a Name, VLAN ID, and other EA's such as site location. I would also be using some like Get "last_host_IP" to assign the network gateway. Does anyone know if commands like these exist? My end goal is to not only make the network reservations in Infoblox but to also take the output and use it in an autoprovising tool such as StackStorm to make network hardware configurations.
Currently all this is done via a manual process, identifying the network, filing in a net_add.csv file and importing it though the Infoblox GUI. Then of course logging into all the appropriate network devices to make the configuration changes manually.
09-05-2017 09:45 AM
Looking for an API command that would allow me to GET "next-available-network". This would be used when subnetting a larger network into dedicated project LANs. This would be used based on a range or possible EA. For example a network range of 10.0.0.0 to 10.0.100.0 would be used for dedicated project network ranging in size from a /29 to a /24 and sliced up accordingly.
There is no single built-in API operation to assign a "next available" network based on an extensible attribute or a range. However it is possible to find and create the "next available" network within an existing network or network container. For example, if you have an existing network container (or network) for 10.0.0.0/16, the following command will find and create the next available /24 network within that container/network:
curl -k1 -u admin -X POST 'https://gm.example.com/wapi/v2.7/network?network=func:nextavailablenetwork:10.0.0.0/16,24'
This command will return an object reference to the newly-created network (e.g., "network/ZG5zLm5ldHdvcmskMTAuMi4wLjAvMjQvMA:10.0.2.0/24/default"), and you can then use that object reference to assign extensible attributes to the network and perform other operations like creating a host record for a gateway at the beginning of the network.
You can also search for a suitable network container or network first (e.g., based on their EA values), get an object reference, and then use that object reference when finding and creating the "next available" network. For example, you can use a command like the following to find all network containers belonging to the finance department (i.e., the network container has an extensible attribute 'Department' with value of 'Finance'):
curl -k1 -u admin -X GET 'https://gm.example.com/wapi/v2.7/networkcontainer?*Department=Finance'
and then you can pick a suitable network container from the resulting list. Suppose the 10.0.0.0/16 network container is one of those returned, and has the object reference "networkcontainer/ZG5zLm5ldHdvcmtfY29udGFpbmVyJDEwLjAuMC4wLzgvMA:10.0.0.0/16/default". Then the following command would be equivalent to the original command above, and would find and create the next available /24 network in 10.0.0.0/16:
curl -k1 -u admin -X POST 'https://gm.example.com/wapi/v2.7/network?network=func:nextavailablenetwork:networkcontainer/ZG5zLm5ldHdvcmtfY29udGFpbmVyJDEwLjAuMC4wLzgvMA:10.0.0.0/16/default,24'
Finding the next available network within a network range (e.g., 10.0.0.0-10.0.100.0) would be a bit more involved. One way to do it would be to find the next available network within 10.0.0.0/16, check the network address of the created network to see if it is higher than 10.0.100.0, and if so then delete it and return an error.
A couple of final notes: First, the above commands assume you have only a single network view ("default"). If you have multiple network views (which is uncommon) you'll need to explicitly specify the view in which you want to search for and create networks.
Second when you search for networks matching a given criterion (e.g., having a particular EA value) you'll need to do two searches, one for network containers and one for (leaf) networks. I believe that when you create a new network using "func:nextavailablenetwork" as shown above it doesn't matter if the network you're searching within is a network container or a regular network. If I recall correctly, when the new network is created the parent network will automatically be converted into a network container. But in general I think it will be easier and less troublefree if you pre-create the parent networks as network containers.
Finally, I tested the examples above on NIOS 8.2 (WAPI version 2.7). They should work on earlier versions of NIOS/WAPI, as long as they support the "nextavailablenetwork" function. Check your WAPI manual to be sure.