NX-API Part 1

I thought I’d start with a quick “how to” demo for Cisco’s Nexus9000 NX-API.  Since I’m not in marketing I probably won’t do too many videos.  However, for NX-API I really wanted to capture everyone’s attention and what better way then in video format!

Below is the code snippet from the video:


import requests
import json

"""
Modify these please
"""
url='IP_ADDRESS'
switchuser='USERNAME'
switchpassword='PASSWORD'

myheaders={'content-type':'application/json-rpc'}
payload=[{
    "jsonrpc": "2.0",
    "method": "cli",
    "params": {
       "cmd": "show version",
       "version": 1
    },
    "id": 1
}]
response = requests.post(url,data=json.dumps(payload), headers=myheaders,auth=(switchuser,switchpassword)).json()

# pretty print the JSON object
print json.dumps(response , sort_keys=True, indent=4, separators=(',', ': '))
Advertisements

One thought on “NX-API Part 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s