This repository is deprecated; please follow the main search page or use the ‘Related code repos’ widget on the right side of the current page.

genie-config-diff

published

One of the most common questions network engineers have to figure out is "What configuration changed?". Genie from Cisco makes answering this question super easy. And as a bonus, it can do far as well!

In this repo will provide you a quick example walkthrough how you can use this tool in your own environment.

Prerequisites

  • You can run this code against your own lab devices, but the code included is built leveraging the following DevNet Always On Sandboxes
  • You'll need Python 3.4-3.7 installed and working.
  • You'll need a macOS or Linux environment to run the examples
    • Windows users can leverage Window Subsystem for Linux

Setting Up your Workstation

  1. Clone down the repo and change to the directory.

    git clone https://github.com/hpreston/genie-config-diff
    cd genie-config-diff
  2. Setup Python Virtual Env

    python3 -m venv venv 
    source venv/bin/activate
    pip install -r requirements.txt 
  3. If you're going to leverage the DevNet Sandboxes, the file sandbox-testbed.yaml is ready to go, feel free to take a look at it.

  4. If you'd like to use your own lab gear you'll need to create a testbed file for your lab. Check the docs for how to create one, or just use sandbox-testbed.yaml as a template.

Capturing the "Gold Config"

In order to find changes in the configuration, you need to capture a gold config. One is included in the repository in the folder sample_gold_config, but you can also capture one of your own like this.

  1. Simply learn config using Genie CLI.

    genie learn config --testbed-file sandbox-testbed.yaml --output gold_config
  2. If you look in the gold_config folder, you'll find 3 files for each device in the topology.

    • connection_DEVICE.txt - Raw console connection log for device
    • config_iosxe_DEVICE_console.txt - Raw device output from the configuration capture
    • config_iosxe_DEVICE_ops.txt - A JSON file created for the configuration

Making Some Network Change

Now to change something that we want to find... you could wait around for something to change, but that could take a while. Instead, go ahead and make a change.

Option 1: DIY with CLI

You can simply log into any of the sandbox devices we are working with using the connection info provide in the testbed or DevNet portal and use typical CLI commands to make some changes.

Option 2: Run one of the Provided Scripts

In this repo I've provided a script that will make a configuration change on one or more of the devices for you. I won't tell you what the changes are (but you could certainly look at the script) so you'll be surprised when you run the test.

  1. Simply run this script to make the change.

    python change_device_config.py

Finding the Change!

Now for the good part, let's find the change.

  1. Re-learn the current configuration. You need to provide a new value for the output.

    genie learn config --testbed-file sandbox-testbed.yaml --output changed
  2. Now find the diff between the gold_config and changed.

    genie diff gold_config changed
    
    

    # Output +==============================================================================+ | Genie Diff Summary between directories gold_config/ and changed/ | +==============================================================================+ | File: config_iosxe_csr1000v-1_ops.txt | | - Diff can be found at ./diff_config_iosxe_csr1000v-1_ops.txt | |------------------------------------------------------------------------------| | File: config_iosxr_iosxr_ops.txt | | - Diff can be found at ./diff_config_iosxr_iosxr_ops.txt | |------------------------------------------------------------------------------| | File: config_nxos_sbx-n9kv-ao_ops.txt | | - Diff can be found at ./diff_config_nxos_sbx-n9kv-ao_ops.txt | |------------------------------------------------------------------------------|

  3. The output of the command shows you where the diffences are, and you can check the files referenced for the specific changes.

    --- gold_config/config_iosxe_csr1000v-1_ops.txt
    +++ changed/config_iosxe_csr1000v-1_ops.txt
    +Current configuration : 9351 bytes: 
    +interface Loopback1001: 
    + description GenieLoop1001: 
    + no ip address: 
    +interface Loopback1184: 
    + description New Interface Created with Genie change: 
    + no ip address: 
    -Current configuration : 9191 bytes: 

Use Case

Cisco pyATS | Genie includes tools that enable network engineers to capture a snapshot of an environment and compare that snapshot to different configurations. This helps engineers answer one of the most common networking questions: what has changed?

This code provides a quick example of a walkthrough that demonstrates how you can use this tool in your own environment.

Objectives

  • This use case captures the "Gold Config" configuration scenario, where you want to re-use a known configuration repeatedly.
  • By continually testing changes in the network configurations, it finds any differences between the Gold config and a changed config.
  • pyATS is a foundation-layer test framework. It is designed to provide a reasonable end-to-end test environment for developers to write use cases.
  • Genie extends its capabilities and specializing in network device automation & validation.
View code on GitHub

Code Exchange Community

Get help, share code, and collaborate with other developers in the Code Exchange community.View Community
Disclaimer:
Cisco provides Code Exchange for convenience and informational purposes only, with no support of any kind. This page contains information and links from third-party websites that are governed by their own separate terms. Reference to a project or contributor on this page does not imply any affiliation with or endorsement by Cisco.