published

image

pyATS DevNet Automation Exchange Submissions

This repository contains all pyATS DevNet Automation Exchange submission.

General Information

Repository content

Requirements

  • Mac OSX, Linux or Windows 10 WSL
  • Python 3.6, 3.7 or 3.8
  • Network connectivity (for downloading PyPI packages)

Preparation Instructions

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.

Use Case

ShutAllInterfaces

Shut all the interfaces of a provided device

Theme

Use Case Description

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:

  • Take operation snapshot of the surounding device, to make sure nothing important has been lost. This would automatically let the user know of what has changed.
  • Connect to each device in parallel
  • Do the shut for each device in parallel
  • Use device.api to simplify the code and share re-usable libraries to pyATS.

Installation

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.

Usage

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).

Theme

Arguments

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)

DevNet Sandbox

This Code Exchange will work on any DevNet sandbox - For example on the CML Entreprise Lab

Getting help

If you have questions, concerns, bug reports, etc., please create an issue against this repository.

Author(s)

This project was written and is maintained by the following individuals:

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.