Cisco announced their entry into the Software Defined Networking (SDN) arena with OnePK in early 2013. If you haven’t heard of Cisco’s OnePK yet, please read their introductions before continuing (only because they do a better job of explaining it than I do):

It took Cisco a while to deliver something tangible after the initial announcement, but it was certainly worth the wait. Cisco has a large amount of resources for onePK that range from videos, tutorials, code examples, SDKs in 3 languages (Java, C, python), and full API docs. I’ve been digging through these resources and there is plenty of good info to get people started with SDN.

I have obviously taken interest in their python SDK to see what sort of things I can automate and plan to write a series of posts as I learn. There’s a lot of potential as to what can be done with OnePK, so I will just be touching on the tip of the iceberg I’m sure. Just thinking off the top of my head, I’m imaging starting off with some scripts/apps with the following functionality:

  • Polling basic router/switch status information about interfaces, routes, CPU, memory, etc.
  • Interface statistics reports with QoS policy rules.
  • Web app that offers basic interface and ACL management for basic provisioning.
  • Monitoring tool that uses OnePK event listeners with configured actions, such as changing routes or creating alerts.

Just while I was thinking of these few ideas I quickly realized that so much more can be done. I’m happy starting with these basic ideas and I’m sure apps will get more complex as I get more familiar with OnePK and python alike. As I write scripts I will be making new posts to explain them and also keeping them in one handy GitHub repo here. As I start to create bigger apps (like the web app provisioning tool) I will probably create stand-alone repos just for those, so keep an eye out for that.

Getting Started

Here are the steps to get started developing with python and OnePK

Documentation Woes

I’d like to give you a warning that Cisco’s main onep API docs can be a pain to sift through. I don’t think the python SDK was written by someone who works with python everyday (but I could be way off-base and if so, I apologize). There are complex classes and enumerations used where much simpler methods could be used. You’ll see in examples later how many objects have to be created just to get an interface list or RIB information. I usually start off finding what I want with the examples included in the SDK and then make use of python’s dir() and help() functions to figure out what is going on with each returned object.

If you’re interested in harnessing the power of python to control your network elements, please follow my blog and learn with me as I dive into the world of SDN and Cisco’s OnePK.

Series NavigationOnePK – Connecting to a Network Element >>

This article has 4 comments

  1. amit

    Hi Mat,

    You have great series going on for onepk. One of the things I am interested in knowing is – in what format is the output returned? I understand that a TLS connection is established and we can do something like ne.get_interface_list() but in the background, it should be sending CLI command of the sort “show ip interface brief”. Then the onepk libaries would be parsing this output and presenting that to our Python programs.

    I am trying to do a similar thing using Python Paramiko (this avoids me having to upgrade my devices) and executing CLI commands but the inherent problem I face time to time is having to put things like time.sleep(5) for the CLI commands to finish executing. Not to mention, capture and parse output which is nasty and a pain in the backside.

    Do you know if the libraries also do the similar things like wait for commands to finish executing and then screen scape?

    – Amit.

    1. Mat

      Hi Amit,

      It’s my understanding that the OnePK library is retrieving the data from the IOS devices in a more integrated way than parsing CLI output. Since the onep service is running on the devices, it can access and return the data in a different format than the CLI outputs. For example, when you use the ne.get_interface_list(), the method is returning a python list of interface objects that contain more details than a simple show ip int bri and show run int gix/x.

      CLI scraping is what we’re stuck with for pre-OnePK (IOS 15+) and I’ve run into the same issues with using .sleep(). You might want to check out the Pexpect module as it seems to have more intelligence in regards to waiting on output and data that requires continuation (like pressing the space bar on show int status).

      I hope that helps!

Leave a Reply

Your email address will not be published. Required fields are marked *