Viptela ConfigSync is a common framework being developed intended to give a standards based approach to working with REST API for configuration tasks with network equipment. ConfigsSync already includes argument parsing from the CLI, logging facilities, and a config file parser. It also comes pre-built with a few functions to serve as examples on building new purposes for the tool.
Viptela ConfigSync is composed of four files that will be used when interacting with devices: config_sync.py, viptela.py, helpers.py, and viptela.cfg. Each file has a unique purpose in this framework.
This file is the main program for the framework, and the file which will be launched when the application is ready. All three other files are pulled into this file (.py files with import statements and .cfg file is being read as a YAML file into a dictionary).
Launching the example config_sync will do a few automatic functions:
- Pull any arguments from the command line using the argparse library
- Enable logging using the logging library. CLI argument --debug offers enhanced logging.
- Instantiate the ConfigSync object using the .cfg file specified on CLI or 'viptela.cfg' will be used as default.
- Run Example Commands:
- Get Device info for vedges and controllers
- Print vedge and controller data using table output in helper function
- Get all template info
- Print template info using helper function
- Get all running-config for vedge and controllers
- Save vedge and controller info to text file
- Get Device info for vedges and controllers
This file houses all of the viptela related functions. Any function, whether using the SDK or generic REST API calls should be made here. Put any new functions under the ViptelaClient class to fully utilize common elements. Initializing this class only instantiates the object. You have to call the class function login() to get cookies and proper XSRF/CSRF tokens.
This file is used to contain all of the functions that manipulate data received. This can be but not limited to saving data to files, printing data to console, exporting to CSV or Excel, or just computational functions. The main purpose of helpers.py is to keep config_sync.py cleaner.
All config parameters are kept in the .cfg file currently. Future iterations will include getpass and environmental variable support. Specify any required variables and include any additional variables that may be needed for your project. This file is treated as a YAML file when imported into the application, and then converted to a dictionary. Default configuration is shown below. Variable names must be exact.
---
viptela_host: '198.18.133.200'
viptela_username: 'admin'
viptela_password: 'admin'
viptela_port: 8443
Steps to run the ConfigSync application are listed below.
- Copy it locally to your computer. You can download the .zip file from Github or install using 'git clone'. This will create a subdirectory whereever you run it called 'Viptela-ConfigSync'.
git clone https://github.com/tc45/Viptela-ConfigSync.git
- Edit and update the connection parameters in the config file as necessary.
---
viptela_host: '198.18.133.200'
viptela_username: 'admin'
viptela_password: 'admin'
viptela_port: 8443
- Launch config_sync.py from the command line.
python config_sync.py
- Use CLI arguments to change behavior of the app.
(venv) C:\PycharmProjects\Viptela-ConfigSync>python config_sync.py --help
usage: config_sync.py [-h] [--config CONFIG] [--debug]
optional arguments:
-h, --help show this help message and exit
--config CONFIG, -c CONFIG
Path to the configuration file
--debug, -d Display debug logs
The lab has been written to work with Cisco Dcloud out of the box. It can also be ran on Cisco DevNetSandbox with minimal modifications to the .cfg file.
-
Reserve a Dcloud session for Cisco SD-WAN POC Tool Once logged into https://dcloud.cisco.com.
-
Click Catalog, and search for 'SD-WAN POC'. This will bring you to a series of Viptela SD-WAN sessions. Cisco changes the revisions frequently, so use whatever is most current.
-
Reserve the lab and wait for session to show active.
-
You can access the lab using Cisco AnyConnect VPN. The credentials will be under the 'Details' heading when viewing the dcloud session. Login using the specified host/port, username, and password.
-
Once logged in you can either run the application on your host PC, or use the Jumpbox. All other steps are the same.
-
(optional) - Login to the Jumphost using MS Terminal Services client (Start -> Run -> mstsc) on Windows. Enter IP '198.18.133.36'. This IP may change in the future, so be sure to check dcloud for updates. Username is admin.
Password is C1sco12345. -
Go to starting directory (personal choice) and clone the Viptela ConfigSync github repository.
cd c:\Users\Admin\PythonProjects\
git clone https://github.com/tc45/Viptela-ConfigSync.git
cd Viptela-ConfigSync
- Run the application. Debug is optional.
python config-sync.py --debug
To learn more about how to build new modules for this app, or are just curious, check out the Lab guides. Lab guides have been created using Jupyter Labs and are located in the /Labs folder. Jupyter Labs must be installed using 'pip install jupyterlab'. Once installed, run the application using CLI command 'jupyter lab'. Once Jupyter lab is running it will open a browser for you in the project root directory. Browse the directory in /Labs to find .ipynb files which are the Jupyter Lab files.
- Install Jupyter Labs using pip
pip install jupyterlab
- Launch Jupyter Lab. This will open a browser to the starting URL. A link will also be displayed in the CLI.
jupyter lab
-
Locate the lab you want to do using the file explorer window. Jupyter Lab files end in .ipynb
-
Follow instructions in the lab
- Lab00 - Using Viptela ConfigSync.ipynb
- Labs/lab01/Lab 01 - Understanding the framework.ipynb
- Labs/lab02/Lab 02 -
- Labs/lab03/Lab 03 -
- Labs/lab04/Lab 04 -
- Labs/lab05/Lab 05 -