Learn How We Can Help You Keep Teleworkers Protected During the COVID-19 Crisis

API & Integration

Reply
Highlighted

Infoblox API - python module

Techie
Posts: 11
19559     0

Just put together a python module. Thought it might be interesting to the community

https://github.com/Infoblox-Development/Infoblox-API-Python

 

Highlighted

Thanks!

Techie
Posts: 2
19560     0

Hi Igor,

Thanks for making this available on GitHub, I really appreciate it.

Highlighted

This is really nice, thanks!

Adviser
Posts: 133
19560     0

I skimmed through the code for this on Github. This looks very nice: a comprehensive set of methods, good use of the requests module, and lots of error handling. I think it would also serve as a good guide to people looking to learn how the Infoblox API works with Python, even if they end up not using the code as-is.

My one question: Are you planning to write any unit tests for this code? Besides whatever use they would be in keeping the code up to date, I think they could also be useful to people looking to confirm that their own API setup was working correctly. (For example, that they are using the right API version, that the userid has the proper permissions, and so on.)

Highlighted

We actually use this code in

Techie
Posts: 11
19560     0

We actually use this code in a couple of projectcs in the company. I just finally got some time to shape it a bit and put some more methods which we plan to use in the future. All methods are tested. I'll publish an intergration with OpenStack. Will publish URL here as well. Hopefully we will upgrade our IBA's soon so I have a chance to put a new code to deal with race conditions for get_next_available_ip.

Highlighted

Integration with OpenStack

Techie
Posts: 11
19560     0

Integration with OpenStack

https://github.com/OpenStack-Development/Nova-fixed-ip-management

We use this code in our OpenStack dev environment to develop, test, and maintain our cloud images so we can utilize Horizon dashboard for image tests.

 

Highlighted

Thanks For Sharing - And A Question

Techie
Posts: 1
19560     0

Great code! Thanks for posting for all to use! I'm getting a JSON error...can anyone point me in the right direction?

[root@swack-redhat Infoblox-API-Python]# python -V
Python 2.6.6

[root@swack-redhat Infoblox-API-Python]# cat swack1.py
#!/usr/bin/python

import infoblox

iba_api = infoblox.Infoblox('infoblox', 'srvinfoblox', [snip], '1.0', 'internal', 'default', False)

try:
    host = iba_api.get_host_by_ip('172.20.19.10')
    print host
except Exception as e:
    print e

[root@swack-redhat Infoblox-API-Python]# python swack1.py
No JSON object could be decoded

Highlighted

Most likely authentication

Techie
Posts: 11
19560     0

Most likely authentication problem or WAPI version is not matching.

Try to add ValueError exception in infoblox.py in get_host_by_ip method. The method code should be ending like the following:

######################

except ValueError:
       raise Exception(r)

except Exception:

        raise

#####################

 

If you see <Response [401]> - this is an authentication issue

If it's <Response [400]> - most likely WAPI version issue. Look which WAPI your IBA supports an use that one.

Meantime, I'll fix exceptions in github code to catch JSON ValueError exception.

 

Highlighted

get_host_by_ip

Techie
Posts: 5
19560     0

i have the following:

import infoblox

iba_api = infoblox.Infoblox('gridmaster.uncc.edu', 'user', 'password', '2.0', 'internal', 'default')
try:
    ip_v4 = iba_api.get_host_by_ip('10.18.0.10')
        print ip_v4

 

Looking in infoblox.py it looks like 'names' should be returning the hostnames associated to the ip address. Should my "print ip_v4" be returning the hostnames? If not, what value should I print to see the returned hostname(s)?

 

I'm very new to Python and APIs. 

Highlighted

and this is why the IB Community...

[ Edited ]
Techie
Posts: 5
19560     0

Two months since the last post and not a peep, not even a cursory "good lock on getting an answer" comment by an Infoblox employee.

Infoblox, you need to improve your customer support. You have a great product but you're going to kill yourself as a company with bad customer support.

 

[Did this get anyone's attention?]

Highlighted

Calling Igor Feoktistov?

Adviser
Posts: 133
19560     0

Apologies for the delay in responding. Note that these forums aren't intended as a replacement for the formal Infoblox customer support mechanism (at support.infoblox.com). I can't speak for other Infoblox employees who participate in the forums, but I respond to questions in my spare time because I like answering questions; my actual job is working with our US government customers.

In any case your question is about the infoblox.py code created by Igor Feoktistov, who is not an Infoblox employee. (So in this case at least Infoblox support would not have been able to help.) I haven't used his code myself (which is one reason I didn't comment on your question when you posted it), but from looking at the original source it appears that the function get_host_by_ip() should return an array of hostnames, so printing that returned value should get you something like

['host1.example.com', 'host2.example.com', 'host3.example.com']

assuming that there are three hosts associated with the IP address in question.

Are you not seeing that, or are you seeing an error message of some sort? If you can post the complete source of your program and its output I'd be glad to take a look at it. (Or perhaps Igor is still reading the forums and can respond.)

Highlighted

Working example of your code

Adviser
Posts: 133
19560     0

OK, I was able to get a version of your code running on my own lab grid. Here's what I did:

First, I downloaded a copy of Igor Feoktistov's infoblox.py program from https://raw.githubusercontent.com/Infoblox-Development/Infoblox-API-Python/master/infoblox.py and saved it into a file infoblox.py.

Next I created a separate file example.py in the same directory, containing the following code:

import infoblox

iba_api = infoblox.Infoblox('gm.example.com', 'admin', 'infoblox', '2.1', 'internal', 'default', False)
try:
    hosts = iba_api.get_host_by_ip('192.168.0.3')
    print hosts
except Exception as e:
    print e

Then I ran the example code:

python example.py

It produced the following output:

[u'host1.example.com', u'host2.example.com']

In this case I had two host records defined, one for "host1.example.com" and one for "host2.example.com", both pointing to the IP address 192.198.0.3. If I had only one host record defined for that IP address (the usual case) then the program would have printed the following:

[u'host1.example.com']

(The "u" characters in front of the hostnames mean that they are Unicode strings, i.e., they could contain non-ASCII characters. Also, to print the first hostname in the array you can refer to hosts[0].)

One major difference from your code is that I added a final parameter False to the call to get_hosts_by_ip(). This tells the function that you don't want to verify the SSL certificate of the grid master you're connecting to. (This is the case for most Infoblox installations, since people generally don't bother to get and install real SSL certificates from a public CA.)

Showing results for 
Search instead for 
Do you mean 

Recommended for You