- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
11-23-2012 09:56 AM
Hi,
Just wondering if anyone had any examples of using the REST API with python. I mainly would like to know how to work out where to add a new A record and PTR record based on given domain name etc..
Thanks
Solved! Go to Solution.
Re: REST API python examples
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-18-2013 01:34 PM
Here are some examples with the Network object. You can try this in an interactive mode with the Python interpreter. It is not much use as a script as it just creates the network, does some search and modification and then deletes the same network.
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
03-18-2013 01:36 PM
Here is a link to some sample code:
http://dl.dropbox.com/u/43461561/infoblox/samples/python-wapi-sample.zip
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-26-2013 11:40 AM
Hi,
I'm brand-new to Infoblox devices and have only been working with one for a couple of days. When I try to use the sample script directly above (with a few minor modifications to make the results more verbose) to access the device , I'm getting the results in between the <<<<< markings.
Note: I'm using guest account credentials with read-only privileges, so I'm only trying to execute read-only operations.
<<<<<
***** Searching for the new network with an exact search string... *****
status code: 200
reason: OK
encoding: utf-8
text: <body onload="document.redirect.submit()">
<noscript>
<html>
<head>
<title>JavaScript required.</title>
</head>
<body>
<table align="center" valign="center" style="width:100%;">
<tbody >
<tr>
<td align="center" valign="center" width="100%" height="15%" style="padding: 5px; text-align: center; font-family: arial, sans-s
erif; font-size:12px; font-weight:bold; color: #FFFFFF; background-color: #800000 ">
Warning: JavaScript disabled or browser does not support JavaScript. To work properly, this page requires JavaScript to be ena
bled.
</td>
</tr>
</tbody>
</table>
</body>
</html>
</noscript>
<form name=redirect
method=POST target=_top
action="/netmri/config/userAdmin/login.tdf">
<input type=hidden name=mode value="LOGIN-FORM">
</form>
content: <body onload="document.redirect.submit()">
<noscript>
<html>
<head>
<title>JavaScript required.</title>
</head>
<body>
<table align="center" valign="center" style="width:100%;">
<tbody >
<tr>
<td align="center" valign="center" width="100%" height="15%" style="padding: 5px; text-align: center; font-family: arial, sans-s
erif; font-size:12px; font-weight:bold; color: #FFFFFF; background-color: #800000 ">
Warning: JavaScript disabled or browser does not support JavaScript. To work properly, this page requires JavaScript to be ena
bled.
</td>
</tr>
</tbody>
</table>
</body>
</html>
</noscript>
<form name=redirect
method=POST target=_top
action="/netmri/config/userAdmin/login.tdf">
<input type=hidden name=mode value="LOGIN-FORM">
</form>
No JSON object could be decoded
***** Done searching for the new network with an exact search string. *****
<<<<<<
The other Python sample script, which performs similar operations - again, read only operations in my context - gives me this result:
<<<<<<
Received response = 302 Found
Request finished with error, response code: 302 Found
Error message: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="/netmri/config/userAdmin/login.tdf">here</a>.</p>
<hr>
<address>Apache/2.2.22 (Fedora) Server at 10.22.4.230 Port 443</address>
</body></html>
Created with ref: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="/netmri/config/userAdmin/login.tdf">here</a>.</p>
<hr>
<address>Apache/2.2.22 (Fedora) Server at 10.22.4.230 Port 443</address>
</body></html>
<<<<<
I'm stumped. What am I missing?
Thank You and Kind Regards
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-26-2013 01:43 PM
Also, in parallel with this, the device isn't showing me the WAPI docs when I put the address in the web browser: https://device_address/wapidoc. I'm getting "404 not found". Is the WAPI just not exposed or "activated"?
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-26-2013 03:35 PM
Ugh - never mind. My URL needed to be: http://device_address/api/2.7/devices (or whatever command) instead of what was shown in the sample scripts. Would you guys mind adding some comments in the scripts about changing this URL and where the URL can be found in the device documentation? [Hopefully that's not too tall an order with all the different devices and versions you might be supporting, and the possibly different paths to that information.]
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
04-08-2015 07:29 AM
API to get target device for a Interface
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-26-2015 01:45 AM
NetMRI or NIOS API?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-26-2015 01:02 PM
Manoj: Are you using the NetMRI appliance or a Network Insight appliance? (Network Insight runs as part of a DDI grid, and implements the rough equivalent of the NetMRI Switch Port Management functions.) If you're running NetMRI I suggest you ask people in the Network Automation forum; I don't have any real experience with the NetMRI API. However if you're running a a Network Insight appliance I can check to see if the NIOS Web API will do what you want.
Error 404
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-09-2015 11:02 AM
dropbox files not found. Can you update link?
Corrected link to sample WAPI Python code
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-17-2015 08:33 AM
Hi All,
I'm trying to access the link give here""http://www.infoblox.com/community/content/getting-started-infoblox-web-api-wap" but page not found error is coming. has something being changed recently?
Also the below link is not working..I need tutorail related to webapis.
https://community.infoblox.com/resource/getting-started-infoblox-web-api-wapi#ProgrammingResources
Please advise?
Nidhi
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-17-2015 08:53 AM
Eric
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-17-2015 01:14 PM
Here is a python 3 example:
infoblox/wapi.py
import requests from requests.auth import HTTPBasicAuth requests.packages.urllib3.disable_warnings() class Infoblox(): def __init__(self): self.server = 'infoblox.local' self.wapiver = '/wapi/v1.7.3/' self.user = 'user' self.password = 'pass' def __enter__(self): """Start a session with Infoblox All requests sent during the session will be authenticated with the ibapauth cookie. """ url = 'https://' + self.server + self.wapiver s = requests.session() s.get(url, auth=HTTPBasicAuth(self.user, self.password), verify=False) self.session = s return self def __exit__(self, exc_type, exc_val, exc_tb): """Logout and close the session""" url = 'https://' + self.server + self.wapiver + 'logout' self.session.post(url) self.session.close() def call(self, object, args, method, data=None): """Construct and send an API call""" url = 'https://' + self.server + self.wapiver + object r = self.session.request(method, url, params=args, data=data) return r.json()
lookup
#!/usr/bin/env python3 from pprint import pprint import argparse import infoblox def lookup(ip): """Search for DHCP lease with ip """ with infoblox.Infoblox() as ib: return_fields = 'binding_state,client_hostname,ends,hardware,network,' \ 'never_ends,next_binding_state,server_host_name,starts,uid' query = {'address': ip, '_return_fields+': return_fields} lease = ib.call('lease', args=query, method='GET') return lease if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("ip") args = parser.parse_args() pprint(lookup(args.ip))
Re: REST API python examples
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-17-2015 05:25 PM - edited 09-17-2015 05:34 PM
@NSrivastava wrote:
Hi All,
I'm trying to access the link give here""http://www.infoblox.com/community/content/getting-started-infoblox-web-api-wap" but page not found error is coming. has something being changed recently?
Also the below link is not working..I need tutorail related to webapis.
https://community.infoblox.com/resource/getting-started-infoblox-web-api-wapi#ProgrammingResources
Please advise?
Nidhi
Hi Nidhi,
It looks like you've got an old page bookmarked. We recently moved a large number of files, and migrated the community to a new platform. You can now find those files under the "Download" section - specifically in the DNS-DHCP-IPAM area here: http://community.infoblox.com/t5/DNS-DHCP-IPAM/WAPI-Web-API-Sample-Code-for-NIOS/m-p/105/highlight/t...
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
10-07-2015 07:06 AM
This link is still 404.
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
10-09-2015 08:21 AM
Use this link... and you'll find the files:
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-31-2018 06:46 AM
Just interested in this question, if there is something, then write me please at PM
Re: REST API python examples
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-04-2019 12:40 PM
link is no longer valid.