This repository contains all pyATS DevNet Automation Exchange submission.
Step 1: Create a Python Virtual Environment
In a new terminal window:
# go to your workspace directory # (or where you typical work from) cd ~/workspace# create python virtual environment python3 -m venv pyats
# activate virtual environment cd pyats source bin/activate
# update your pip/setuptools pip install --upgrade pip setuptools
Step 2: Install pyATS & Genie
# install our packages
pip install pyats[full]
Note:
The install target
pyATS[full]
performs a full installation, that is,
including the core framework pyATS, the standard libraries Genie, and
additional components such as RobotFramework support etc.
Step 3: Clone This Repository
# clone this repo git clone git@github.com:CiscoTestAutomation/DevNetAutomationExchange.git# cd to the directory cd DevNetAutomationExchange
and now you should be ready to get going!
More information in guide on how to install it and get started with it.
Shut all the interfaces of a provided device
How can I shut all the interfaces on a specific device.
At Cisco Live, an attendee asked me this very question. He had to shut multiple devices, but wanted to make sure it would not affect his production network. Though, he did not want to waste his time shutting thousand of interfaces manually.
We sat together, and coded this small but very useful script.
This script becomes very important when wanting to decomission a device. It allow to make sure the network is performing as expecting without this device being operational. However, it can be brought back in a few seconds if needed.
The "Un shut" configuration is provided at the end of the run, to quickly revert if needed.
Other ideas to enhance this script could be:
This script requires pyATS. Follow the instruction on the previous page.
Then you will need a Testbed file. Follow this guide on how to create one.
A testbed file is a way to represent your devices. It contains the devices name, credentials and ip address on how to reach it. You can find a testbed example here.
To execute it, just do the following:
# Shut all interfaces of csr1000v-1
python shutinterfaces.py --testbed-file testbed.yaml --devices csr1000v-1
# Shut all interfaces of csr1000v-1 and nx-osv-1
python shutinterfaces.py --testbed-file testbed.yaml --devices csr1000v-1 nx-osv-1
# Shut all interfaces of csr1000v-1 Except Loopback0 and Loopback1
python shutinterfaces.py --testbed-file ../../training/genie-bootcamp/tb.yaml --devices csr1000v-1 --exclude csr1000v-1:Loopback0,Loopback1
This script works on all Cisco main OS (XR, IOSXE, NXOS and IOS).
There is 3 arguments to this scripts
--testbed-file: pyATS Testbed file (Mandatory argument)
--devices: Space separed device name to shut interfaces on. Must exists in the testbed file (Mandatory argument)
--exclude: Interfaces to NOT shut. Example --exclude device_name1:int1 int2 int3 device_name2:int3 int5 (Optional argument)
This Code Exchange will work on any DevNet sandbox - For example on the CML Entreprise Lab
If you have questions, concerns, bug reports, etc., please create an issue against this repository.
This project was written and is maintained by the following individuals:
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community