Getting_Started_SDWAN

In Cisco SD-WAN vManage 19.2 change have been made that requires the use of a token in the headers for any API interaction to work

This public repo contains python code that can be used to interact with the Cisco SD-WAN vManage REST API. The environment is pre-configured to access the Cisco DevNet Reservable Sandbox for SD-WAN fabric.You can edit the variables in the environment to point to your own vManage instance. The code contains REST API calls to authenticate, get a list of devices that are part of the SD-WAN fabric. Cisco SD-WAN vManage 19.2.2.

Sandbox Image

Python Environment Setup

It is recommended that this code be used with Python 3.6. It is highly recommended to leverage Python Virtual Environments (venv).

Follow these steps to create and activate a venv.

OS X or Linux

virtualenv venv --python=python3.6
source venv/bin/activate

Install the code requirements

pip install -r requirements.txt

API authentication Process

  • Send POST request for authentication with vManage web server.
  • Method: POST
  • Request URL:  https://vmanage-ip:vmanage/j_security_check
  • POST Request Payload: {'j_username' : username, 'j_password' : password}

API authentication Process

  • Once login is successful run GET request to retrieve token and add it to session headers of subsequent API calls. 
  • Method: GET
  • Request URL: https://vmanage-ip:vmanage/dataservice/client/token
  • Store the response token value in session headers “sess.headers['X-XSRF-TOKEN']”

Getting / Printing Device Information

  • Method: GET
  • Request URL: https://vmanage-ip:vmanage/dataservice/device

Example Output

Code Image

About me

Stuart is a Senior Developer Advocate, public speaker, author and DevNet Expert #2022005

Find me here: LinkedIn / Twitter / bigevilbeard.io

Use Case

This sample Python code uses the Cisco SD-WAN REST API to connect to vManage, retrieve a list of devices under management, and display that list.

The Cisco SD-WAN REST API is a programmatic interface for controlling, configuring, and monitoring the Cisco SD-WAN devices in an overlay network. You access the REST API through the vManage web server. The API is documented on the vManage host, and you can access the documentation by using your browser to navigate to https://<vmanage-ip-address>/apidocs. Additional API documentation can be found in the Cisco SD-WAN Product Documentation.

Objectives

  • Explore how the Cisco SD-WAN REST API allows the user to configure, control, and monitor SD-WAN devices in an overlay network.
  • Does the authentication process using Vmanage API.
  • Automatically retrieve inventory data from vManage and list a summary of all devices in the network.

Requirements

It is recommended that this code be used with Python 3.6. It is highly recommended to leverage Python Virtual Environments (venv).

Tutorial

Learning Labs

Using Python to interact with the Cisco SD-WAN REST API

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.