published

Genie_Webex Project

Validate/Maintain Network Devices Configuration

This project combines two Cisco solution : Webex Teams and Genie/pyATS. The goal is to check the state of the routers if there is any change in the desired configuration. Cisco Webex Teams is used to receive alerts for the result: Configuration change or not. Genie/pyATS is used to test and compare the configuration with its functions and APIs. Here are the links for more information about Webex Teams and Genie/pyATS:

Webex Teams :

https://www.webex.com/team-collaboration.html

and to use the Webex APIs :

https://developer.webex.com/

To get started with Genie/pyATS :

https://pubhub.devnetcloud.com/media/genie-docs/docs/cookbooks/index.html

Topology and Simulation

Here is the topology used to test this project:

Topology

GNS3 was used with Cisco routers equipped with IOS images and a Linux machine as admin since the framework Genie/PyATS works only on Linux or Mac OSX. However, you can use the Windows Subsystem for Linux (WSL, as the case used in this project). This allows to test the project even if we do not have recent versions of GNS3 or EVE-NG with IOS-XE which consumes resources (RAM and CPU). However, you can test this project using your own emulator or the DevNet SANDBOX Cisco Modeling Labs (CML). You just need to modify the parameters concerning the information about the devices used in the connex.yml file (IP addresses, users, IOS type, ...). Here is the link for the SANDBOX catalogs, just choose the one from Cisco Modeling Labs : https://devnetsandbox.cisco.com/RM/Topology.

Packages installation and Requierements

The best practice is to leverage Python Virtual Environments (env). Please follow these steps to clone the Git repository and create and active the virtual environment:

git clone https://github.com/cherifimehdi/Genie_Webex.git
cd Genie_Webex
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt

As the packages used are found in requirements.txt file, alternatively, you can install the packages as follows:

pip3 install pyats[full]
pip3 install requests
pip3 install requests-toolbelt

Note :

You must create a Webex Teams Space in order to test this project. Please refer to https://developer.webex.com/ to learn more how to use APIs to create Spaces and manage messages.

How to use the project

Note :

You must create the Golden_Config folder before running multi_golden_config.py script in order to save the golden configuration in the desired configuration state of the devices.
If you use the golden configuration files provided for each router used in this project (Refer to Golden_Config folder), you need to create RSA Keys to enable SSH. The credentials used could be found in connex.yml file.

Feel free to change the parameters in connex.yml file according to your devices configuration and types (os, ip, credentials,...)

In multi_config_stat.py, I used Disk0 to store the startup-config (golden configuration in desired state), you must change it according to your device configuration. To save it, use the command : copy running-config disk0:startup-config in each device. The following figure shows the content of Disk0 for R1 router:

startup-config_R1

Please update the access_token and room_id in multi_config_stat.py according to your setting in Webex Teams.

Before running the test, please ensure that you run the multi_golden_config.py script in order to ensure the golden configuration (Desired configuration) in the folder Golden_Config for comparison purposes.

python3 multi_golden_config.py

Golden config

The configuration is saved as string dictionary as indicated in the following figure.

R3 golden_config

Test and Results

Here the flowchart of the project scenario :

Flowchart

Scenario in case no change

Here we run the script multi_config_stat.py

python3 multi_config_stat.py

Here the result in Genie_Webex space

No_change

Scenario in case of change

In this case a loopback interface is configured in R2 as follows :

lo0_R2

Then we run the script multi_config_stat.py again:

python3 multi_config_stat.py

Here the result sended to Webex Teams space:

After_change

Here the content of the file change_R2.txt

change_R2.txt

The golden configuration restoring process is applied (by exploiting the command configure replace disk0:startup-config force) as indicated in the following figure:

startup-config_restoring_R2

About me

Active Cisco CCAI Instructor and Network Engineering Trainer. Part of Cisco DevNet Class 2020. Cisco DevNet Code Exchange and Automation Exchange Contributor.
I am interesting in all about NetDevOps, Networking programmability and automation. I am a Cisco contents fan.

Contact Me

LinkedIn

GitHub

Credly

Twitter

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.