Tag Archives: python

Evolving Technologies – Scripting

scripting

Network management tools often create more frustration for network engineers than problem they can solve. This is true for a number of reasons, including:

  • Many of them are difficult to install and maintain
  • They are often proprietary and support only a single vendor
  • They often lack scalability and reliability

As a result, many engineers give up and instead rely on the command-line interface (CLI) to manage individual switches. An increasing number of network engineers stretch the limitations of those tools by writing scripts in TCL, Perl, Python or other languages.

Of course these engineers are not writing sophisticated software, just scripts that allow them to scale certain tasks, such as reconfiguring multiple switches using a screen scraping of CLI commands.

Scripting is a critical component of many Software Defined Networking (SND) implementations – including that of Cisco Systems with the Application Centric Infrastructure (ACI).

We know that in this technology, Cisco likes to use REST as the Northbound API. Yet Cisco engineers prefer to use Python instead of sending plain vanilla REST calls. This is because Python allows the parsing of command line options and configurations. Of course it is possible to use Python with sample scripts to turn XML into REST calls, but this approach requires formatting the XML configuration files according to the ACI object model. This results in scripts that are shared requiring administrators to have knowledge of this ACI object model.

The Python SDK for ACI permits the creation of scripts with configuration files and command line options that anyone skilled in networking can use. The ACI SDK provides models that enable you to perform all the operations that the Cisco ACI fabric offers with several advantages:

  • Python can parse configuration files in whichever format you prefer
  • The SDK APIs can be identical over time, while the specific format of the XML object model can change
  • You can perform more sophisticated conditional operations, string manipulations, etc

Learning Python – Lesson 1: Getting Started!

Why Do This?

Python is a simple programming language capable of big things. It features wide support across network devices.

There are many reasons you should consider learning Python – here are just some of them:

  • It is fun!
  • You might not have learned a programming language in a long, long time.
  • Python is often used in Software Defined Networking (SDN) Environments.
  • Did I mention it is fun?
  • Python is now a requirement for many professional certifications from companies like Cisco, Juniper, AWS, and more

The First Application

I hope you enjoy my notes on my learning here at AJSNetworking.com. I am using various resources to help you, but the primary one I would love for you to follow along with is the CBT Nuggets course:

Python Programming

I am on a Mac – which provides the luxury of having Python built right in (just like Linux). For those of you on Windows – head over to python.org/download.

For composing my Python applications – I am using the BBEdit from BareBones.com. After thirty days of the full version, you can continue to use it free for your text editing work. Advanced functionality like Web authoring goes away, but no big deal for me.

I will use BBEdit to create my first Python application! How exciting. 🙂 Here it is.

print “Hello World!”

print “This is awesome!” 

print “I am a programmer!”

I will save this complex program 😉 as a file named ex1.py.

I will now run this application in the Terminal application in Mac OS. This is done with the command:

python ex1.py Python

Make sure you are in the directory where that file exists of course!

Interested in what version of Python you are running?

Try this command:

python –version

I just discovered I am running Python 2.X.

Final Thoughts

This is an excellent time to practice with some of your directory and file management skills from within Terminal. I found myself using the following commands in this first application and its execution:

  • mkdir – Make a directory
  • cd – Change directory
  • ls – List the contents of a directory

Thanks for reading and I hope your first Python application was a success as well.

Do you have questions? We are standing by – just use the comments area below.