Avatar

If you followed my post from last week, now your pyATS setup is ready and we can start learning about its capabilities. Rather than reading about it, let’s see how it actually works and the value it brings. But let’s start at the beginning…

Execute a command on a network device

This first demo is the most basic one and will show you how to use pyATS to execute a simple command on a certain network device. In this case you will see in your screen how this script executes a show version on a CSR1000v.

You can review its content and see it executes the following steps:

  1. Load the required pyATS and Genie libraries
  2. Load the pyATS testbed definition from file
  3. Select a specific device from the testbed
  4. Connect to that device via SSH and configure the connection to be automation-friendly (disable logging, change terminal width/length, no timeout)
  5. Execute a command on that device

Please remember you must have a reserved sandbox with your VIRL simulations running and be connected to it via VPN. Please see my previous post for further information on how to complete the environment setup.

As mentioned in the last post we will use containers for our demos, but you might choose to use your own local environment and get similar results.

If you decide to go with Docker, please run the demo with an interactive container (-it) that will be automatically deleted after execution (–rm) and pass it a mapped volume from the local directory in your workstation to the container (-v $PWD:/pyats/demos/). When the container starts it will automatically execute the specified python script.

$ docker run -it --rm \
  -v $PWD:/pyats/demos/ \
  --env-file env.list \
  ciscotestautomation/pyats:latest \
  python3 /pyats/demos/1-pyats-intro.py

How is this cool?

I know, I know… I can hear you thinking: “how is this cool?!?”. Well, basically you have been able to run a script that automatically connects to one device and executes one command on it. Nothing fancy there, I know, BUT… what if you could do the same for a large list of devices? Imagine you needed to run that same command in 1,000 devices. Or maybe you had to run multiple commands in a myriad of devices. pyATS allows you to easily do it, and only requires you to provide the testbed and python script. pyATS will take care of everything else while you go play guitar.

Let’s try something else…

Consolidate info from devices with different CLI

In this case you will use not only pyATS, but also the Genie libraries to compile interface counters from devices with different platform/OS across the network and then check if there are any CRC errors in them.

Julio Gomez NetDevOps part 13

Our python script will use the same function to compile CRC errors information from 2 different devices with different CLI (ie. CSR1000v and Nexus switch). Genie determines the platform/OS from the testbed file definition and its parsers provide independence from the underlying device type. Genie uses models to determine the specific commands and format that need to be used for each feature in each platform/OS, and how to map the outcome to the specific fields in the resulting structured data.

Get ready to run the demo

Please review its content and you will see the following steps to execute:

  1. Load the required pyATS and Genie libraries
  2. Define a common and reusable function that obtains all interface counters from a single device
    o If not connected to the device, connect to it via SSH
    o Learn info about those device interfaces to parse and return it as structured data
  3. Load the pyATS and Genie testbeds definition from file
  4. Select a specific device from the testbed
  5. Call the function defined previously to obtain all interface counters from that device
  6. Select another device, with a different CLI
  7. Call the same function, defined previously, to obtain all interface counters from that device
  8. Merge all interface details from these 2 different platform/OS devices (with different CLIs), into a single source (python dictionary)
  9. Loop through the compiled data in that single source and show CRC errors for every interface

Run the demo with an interactive container (-it) that will be automatically deleted after execution (–rm) and pass it a mapped volume from your workstation to the container (-v $PWD:/pyats/demos/). When the container starts it will automatically execute the specified python script.

$ docker run -it --rm \
-v $PWD:/pyats/demos/ \
--env-file env.list \
ciscotestautomation/pyats:latest \
python3 /pyats/demos/2-genie-intro.py

Now this is starting to get more interesting, right? Using Genie we have been able to re-use exactly the same function code to connect to devices supporting different CLIs, extract the required info from them and consolidate all that info into structured data we can now use in a programmatic way for our own specific interests. So cool!

See you in a couple of weeks for our next set of pyATS demos, stay tuned!

You can find all the blogs in both my DevOps and NetDevOps series here. Any questions or comments please let me know in the comments section below, or via Twitter or LinkedIn.

Additional resources:


We’d love to hear what you think. Ask a question or leave a comment below.
And stay connected with Cisco DevNet on social!

Twitter @CiscoDevNet | Facebook | LinkedIn

Visit the new Developer Video Channel



Authors

Julio Gomez

Programmability Lead, EMEAR

Systems Engineers