Requirements

Getting started

Most of the examples you will see in this post were executed in Python
interactive mode. At the end of this post you will also find a CLI
application which is able to get, create, delete and update Infoblox
objects. For now let’s see how this is done step-by-step.

If your Infoblox instance is using a self-signed SSL certificate you
would want to set session.verify to False, otherwise your requests
will fail. If your Infoblox instance is using a signed certificate
from an official CA you can skip setting the session.verify
attribute.

Let’s also set the URL to the Infoblox WAPI, which is where our
requests will be send to:

>>>url='https://infoblox.example.org/wapi/v1.1/'

Okay, now we are ready to start sending our WAPI requests to the
Infoblox instance. In the next sections of this post we will see how
to get, create, update and delete objects from Infoblox.

Getting objects from Infoblox

In order to get Infoblox objects we need to use the HTTP GET
method. This is how we could get all Infoblox network objects.

>>>r=session.get(url+'network')

Let’s check if our request was successful or not:

>>>r.status_code200

The HTTP code 200 means that our request was successful, so we could
now see what the result was as well:

From the output above you can see the networks we have in Infoblox,
the network view and also the object reference for each network
object. The object reference in the output above is what we need to
pass when we need to update or delete an Infoblox object. Later in
this post we will see how to do that as well.

Creating objects in Infoblox

In order to create a new Infoblox object you need to use the HTTP
POST method. This is how we could create a new Infoblox network:

Upon a successful object creation in Infoblox the result we will
receive is the new object’s reference. In the above output you can see
the object reference of our new network 192.168.2.0/24. Let’s verify
that it actually exists in Infoblox.

>>>printsession.get(url+'network').content[{"_ref":"network/ZG5zLm5ldHdvcmskMTAuMjMuOTYuMC8yNC8w:192.168.0.0/24/default","network":"192.168.0.0/24","network_view":"default"},{"_ref":"network/ZG5zLm5ldHdvcmskMTAuMjMuMTA4LjAvMjQvMA:192.168.1.0/24/default","network":"192.168.1.0/24","network_view":"default"},{"_ref":"network/ZG5zLm5ldHdvcmskMTkyLjE2OC4yLjAvMjQvMA:192.168.2.0/24/default","comment":"This is a new comment","network":"192.168.2.0/24","network_view":"default"}]

As you can see from the output above we have successfully updated our
network object.

Removing objects from Infoblox

In order to remove an object from Infoblox we need to use the HTTP
DELETE method. When removing an object from Infoblox we need to pass
the object reference as well.

This is how we could remove the example network object we recently
created in the previous section:

Wrapping it up

By now you should know how to get, create, update and delete objects
from an Infoblox instance. Running commands in the Python interactive
mode is useful when testing, learning something new or just debugging
an issue, but generally you would want all of the above to be handled
by some tool.

For that purpose I’ve made a Python script which is able to get,
create, update and remove objects from Infoblox server, which you can
find at the Github repository listed below.