Reply
Highlighted
Accepted Solution

REST API python examples

community Employee
Employee
Posts: 73
31260     0

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

Re: REST API python examples

[ Edited ]
Adviser
Posts: 341
31261     0

http://community.infoblox.com/t5/DNS-DHCP-IPAM/WAPI-Web-API-Sample-Code-for-NIOS/m-p/105/highlight/t...

 

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh

Re: REST API python examples

community Employee
Employee
Posts: 73
31261     0

 

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

community Employee
Employee
Posts: 73
31261     0

Re: REST API python examples

JHopkins
Techie
Posts: 5
31261     0

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

JHopkins
Techie
Posts: 5
31261     0

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

JHopkins
Techie
Posts: 5
31261     0

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

MNagarajan
Techie
Posts: 2
31261     0
Hi All, Were you able to crack the issue. I am struck up in the same place. I used the scripts in "http://www.infoblox.com/community/content/getting-started-infoblox-web-api-wapi" and got below error... Traceback (most recent call last): File "C:\Manoj\Net MRI - SM Integration\Python Scripts\Sample_2.py", line 46, in return_results = json.loads(response.content) File "C:\Python27\lib\json\__init__.py", line 338, in loads return _default_decoder.decode(s) File "C:\Python27\lib\json\decoder.py", line 366, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded Kindly advise...

API to get target device for a Interface

MNagarajan
Techie
Posts: 2
31261     0
Hi Team, Can you provide me the API, which will provide the list of end-devices connected to a network element. For example, if a switch has 48 interface ports, i want to get the devices connected to all 48 ports. Regards, Manoj N.

NetMRI or NIOS API?

Adviser
Posts: 130
31261     0

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

EWatson
Techie
Posts: 5
31261     0

dropbox files not found. Can you update link?

Corrected link to sample WAPI Python code

[ Edited ]
Adviser
Posts: 130
31261     0

Re: REST API python examples

Authority
Posts: 40
31261     0

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

Adviser
Posts: 267
31261     0
Nidhi, I'll look into the community link issue shortly! We recently migrated to a new platform and there may be a few files that need to be found. Thank you for your patience!

Eric
If you appreciate my efforts, please give me a kudo ↓ or Accept as solution to help others find it faster.

Re: REST API python examples

NHolguin
Techie
Posts: 2
31261     0

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 ]
Adviser
Posts: 267
31261     0

@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...

If you appreciate my efforts, please give me a kudo ↓ or Accept as solution to help others find it faster.

Re: REST API python examples

Authority
Posts: 37
31261     0

This link is still 404.

Re: REST API python examples

Adviser
Posts: 267
31261     0

Use this link... and you'll find the files:

 

http://community.infoblox.com/t5/DNS-DHCP-IPAM/WAPI-Web-API-Sample-Code-for-NIOS/m-p/105/highlight/t...

 

If you appreciate my efforts, please give me a kudo ↓ or Accept as solution to help others find it faster.
Showing results for 
Search instead for 
Do you mean 

Recommended for You