Network Automation | NoCode 101

Jeremy Schulman
Network Automaniac
Published in
5 min readOct 21, 2019

Over the years I’ve mentored many network engineers on how to get started with network automation. I do not believe network engineers need to become developers, but I do believe they can learn basic skills. The first step in this process is to show network engineers how to use the CLI commands they know and love, but use them without having to SSH into the devices.

The goal is to slowly migrate network engineers off the device CLI and be more comfortable using Python as a power-tool.

My primary tool during this process is to introduce IPython. I also use vendor provided python libraries that allow them to execute CLI command and obtain the output in CLI text. I do not teach writing complete Python programs. Instead I show how to use IPython so they can interactively run single python commands, and slowly build up small re-usable snippets. They can then use IPython to load these snippets whenever they need to. I like to call this approach “No Coding

This article goes through an example of how I do this type of training. The use-case: “Given an end-host IP address, and optionally a mac-address, find the switch and interface where this end-host is attached on a L2 VLAN network”.

Getting to Know IPython

IPython is a command line interpreter that has a CLI look-and-feel to it. There are a few key features to highlight:

  • TAB complete — allows you to type in part of what you want and the IPython shows you the available options, similar to being on a device CLI
  • ? for Help — Putting a ? before anything and hitting return will give you help information about it
  • Copy-Paste — You can copy and paste into the IPython shell just like you could with the CLI. This allows you to write some python in an editor like Pycharm, and then drop it into IPython. This approach allows you to quickly create code snippets without having to write full programs
  • Up-Arrow & History — As you are typing in IPython, you can correct mistakes by using the Up-Arrow to go back. You can even use a history command to see everything you’ve done so far, so you could then retrieve the code and re-execute it

David Bombal produced a very good video tutorial, which I recommend you watch: https://www.youtube.com/watch?v=9msAkdBOzJY

NoCode with pyATS

In this article I am going to continue to use Cisco DevNet pyATS Genie software. I’ve already created a python file that allows me to quickly connect to any device without having to create a Testbed. You can find this code repo here. I begin by starting ipython with the -i flag to remain in interactive mode. I also pass the filename of the code I want to initially run.

I can then use the function connect_device() that is defined in the quickstart-notestbed.py file to create a Genie Device instance and connect to the device.

I can then use the Device.execute() command to run any CLI command and obtain the CLI text output. While pyATS has may parsers, the first step is to use the same CLI commands the network engineer is familiar with.

Let’s say that my end-host IP address is 10.100.200.150, and I want to use the CLI command “show ip arp 10.200.200.150”, I would do:

This step teaches how to create a variable, find_ipaddr, to store the IP address (In [8]) and then how to use that variable to insert it into the CLI command (In [9]). I can then print the CLI output, just as I would see it on the device CLI (In [10]).

As a next step, I could then re-run the same command, but this time filter only out the line we actually want. I can use the Up-Arrow to get back to the line of code shown as In [9], and then add a CLI pipe-filter (In [14]):

Next I split the CLI output into pieces so that I can then use these variable in the Device.execute() command.

Using the macaddr variable (In [20]) I can find that value in the MAC address-table to determine the interface where it was learned.

I can see this MAC address was learned on Port-Channel1. I would then have to run further commands to track down where Po1 is connected, login to that device, and repeat and continue the process of running Device.execute(), extracting the pieces we need, using them to run through the next set of show commands, until I ultimately arrive at the device interface connecting to the end-host.

Getting Started without Coding

I believe the first step in teaching network automation to traditional network engineers is to enable them to continue to use the CLI commands they know, while building their python skills, with the purpose to migrate them off the actual device CLI. In this article I covered the basic starting techniques:

  1. Use IPython for an interactive experience, rather than writing complete programs
  2. Use vendor libraries that provide a way to run CLI commands and obtain the text output
  3. Introduce basic python skills to parse and extract data from the CLI text

I like to call this approach No Coding because network engineers do not need to write complete programs that try to account for all scenarios and failure conditions. Using IPython for an interactive experience allows them to run code, see the output, and take corrective action. This approach has in my experience been far more effective than trying to teach coding complete programs. Give it a try and let me know what you think!

Reference Links

--

--

Jeremy Schulman
Network Automaniac

Senior Network Automation Engineer, Major League Baseball