SDN Quick and Dirty First Steps

So I just attended Cisco Live in San Diego, and for the second year in a row, the buzz is all about SDN (Software Defined Networking).  This can mean a lot of things, kind of like “cloud computing”;  what is that really?   Well this year there was more practical knowledge and a few practical examples.  Through the week I managed to stitch together knowledge from several sessions to accomplish something near a “hello world” in the SDN realm.

What’s the point?  So what I am about to go through will demonstrate pulling a “show ver” off of a nexus (7k/5k/1k).  You say there are lots of ways to do that, and you would be right but this way is much easier than past methods and is very scalable to performing much larger jobs.

First the environment on the client machine.  You need Python,  I have a mac so here are the steps for installing Python on the Mac:

This article says it best:   https://vandadnp.wordpress.com/2014/10/20/building-and-running-python-scripts-with-xcode-6-1/

But here are the broad strokes:

sudo easy_install cmd2

sudo easy_install pip

sudo pip install lxml

sudo pip install pexpect 

sudo pip install requests

Next we need to setup the Nexus switch to accept commands via the NxAPI which is a REST/JSON interface to the CLI.  They promise a NETCONF/YANG model is in the works but not available yet.

On the Nexus

nx-osv-1# conf t

Enter configuration commands, one per line.  End with CNTL/Z.

nx-osv-1(config)# feature nxapi

That’s all there, hey that was easy.

Now the code:

 I got this from

https://github.com/datacenter/nxos

Python Script

#Print Chassis info, Hostname and software version of a given switch.

import json

import requests

print “enter ip address”

ip=raw_input()

my_headers = {‘content-type’: ‘application/json-rpc’}

url = “http://”+ip+”/ins”

username = “cisco”

password = “cisco”

payload=[{“jsonrpc”: “2.0”,

          “method”: “cli”,

          “params”: {“cmd”: “show version”,

                     “version”: 1},

          “id”: 1}

         ]

response = requests.post(url, data=json.dumps(payload), headers=my_headers, auth=(username, password)).json()

#Now Process the response

kick_start_image = response[‘result’][‘body’][‘kickstart_ver_str’]

chassis_id = response[‘result’][‘body’][‘chassis_id’]

hostname =  response[‘result’][‘body’][‘host_name’]

print “ip : {0} is a \”{1}\” with hostname: {2} running software version : {3}”.format(ip , chassis_id, hostname, kick_start_image)

OutPut

alexbaldwin@Alexs-MBP ~/Google Drive/gitrepository/nxos/nxapi/samples> python ./show_version.py

enter ip address

172.16.1.68

ip : 172.16.1.68 is a “NX-OSv Chassis” with hostname: nx-osv-1 running software version : 7.2(0)D1(1) [build 7.2(0)ZD(0.120)]

alexbaldwin@Alexs-MBP ~/Google Drive/gitrepository/nxos/nxapi/samples>

Advertisements
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

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