pyATS & Genie – Network Engineers Transform!


May 28, 2019 - 4 Comments

One of the questions that gets asked most often around NetDevOps is,

“I love the concept of NetDevOps, but I’m not a
software developer. I’ve been a network engineer for X years,
and I don’t know how to code…where do I  start?”

You can start with Python. It’s a great programming language that is easy to read, easy to write, powerful yet intuitive. It comes out-of-the-box with many great packages and modules required for network automation, and has consistently ranked as one of the top programming languages of the decade. Even Cisco is teaching you Python!

But picking up programming can be challenging. It takes time to master a language, even more to understand its various design paradigms and pick the right tool (e.g., paramiko, netmiko, or pexpect), and then build reusable functions and libraries to drive your network devices.

So, is Python THE answer?

The short answer is yes, but you don’t have to start with the language – that might be a bit dry. To dive into network automation and NetDevOps by starting with Python dicts, functions, and classes is a bit like getting into baking and going straight to the wheat mill. Instead, consider getting the right cake mix as a first step and see your end product take shape – go down the path of customization and tinkering only when you dig deeper, and gain comfort in the art.

pyATS | Genie: Command Line

Build using Python, Cisco pyATS & Genie comes out of the box with ready-to-use libraries, and step-by-step guides on how to leverage the power of these libraries, catering to engineers of all kinds of needs and skill levels.

For starters, the built-in shell interface enables you to harness the power of Genie libraries and dabble into the world of network automation without any programming expertise. The command requires only a YAML input file that describes your testbed/device connectivity and credentials information.

pyATS 1

From there on, you can use the Genie parse command to process any of the 1000+ (and counting) parsers that Genie features out of the box.

pyATS 2

pyATS 2_3

This command connects to your testbed device, issues the provided CLI command, find & invokes the right parser for this platform, and returns the parsed data structure in JSON format.

This, in conjunction with Genie diff command, allows you to make quick yet stateful comparisons of your device operational states pre/post changes. Imagine for instance, that you kept a copy of your known-good device operational state in a repository. When your network is misbehaving, probe again and compare:

pyATS-2_4

As opposed to a typical text comparison editors that highlights EVERYTHING that has changed,

pyATS_2_5

The Genie diff engine generates a human-readable Linux diff-like syntax of exactly what changed, based on the parsed data-structure object in Python.

Siming_2_6

This stateful parsed data structure comparison takes into account dynamic values (such as counters, timestamps, uptimes), and automatically excludes them from the output. The result enables you to immediately pin point the issue at hand, and resolve as needed.

But wait! It gets even better

Genie isn’t just a library of open-source parsers. Above the parsing layer, Genie represents networks devices and their features with its own YANG-inspired Python object models. These higher level models are designed to be programmer-friendly, and agnostic across different Network OS/Platforms. You can use them to easily and thoroughly inspect your network for whole-feature based operational state changes.

pyATS_2_7

Diff output:

pyATS_2_8

In the above example, our topology experienced an unknown failure that led to total traffic loss. Armed with Genie, you can immediate determine that Ethernet2/1 on our Nexus switch lost connectivity, leading to the loss of all OSPF neighbors.

How cool is that?

Sum Up

Python is great for network automation, but pyATS & Genie shell commands provides a much easier time to ramp-up and be productive FAST! The three basic commands:

  • genie parse
  • genie learn
  • genie diff

enables any network engineer to immediately perform some degree of stateful DevOps verification/automation without any programming. Combining this with some icing on the cake, Network as Code: storing your configuration and over-time operational state outputs into Git, you now have:

  1. an over-time view of how your network configuration changed
  2. an over-time snapshot of your network’s operational status

Your ability to debug your network’s failures just quadrupled!

Do It Yourself

There’s no better way to learn something than to get your hands dirty. Head over to the pyATS & Genie learning section on DevNet and practice what you’ve just read:

Still want more? Register now for NetDevOps Live! In Season 2, episode 8 of this FREE webinar, we’ll dig deeper in to the world of network automation, and how to test your network, using Cisco pyATS & Genie.



In an effort to keep conversations fresh, Cisco Blogs closes comments after 60 days. Please visit the Cisco Blogs hub page for the latest content.

4 Comments

  1. Hey Mike,

    This is great, i have been trying to wrap my brain around this and I wanted to integrate with normal python script.

    Just wanted to know if I wanted to store the output in some variable for working/good state. The idea is as follow.

    from genie.utils.diff import Diff

    diff = Diff(good_state, bad_state, exclude=list_of_keys_to_ignore)
    diff.findDiff()

    for i in diff.diffs:
    print(str(i))

    Can you please help to determine how can I achieve this ?

  2. Hey Mike,

    I am going through the same process with Prime Infrastructure and creating a YAML file. I plan to use Python and the PI API to pull the device names and IP address and place into a YAML file. Hopefully it works correctly.

  3. Hi Siming,
    We have about 300 devices managed by Cisco Prime Infrastructure and DCNM. How do I go about generating a testbed file for them to use with PyATS and Genie? Thank you very much.

  4. What's this "YAML" thing?

    I can deal w/ Python, but now I have to learn what; Yet Another Modeling Language? Is that what YAML is?

    fjm