DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1

REST API endpoints that are secured with self-signed
SSL certificates. Next, the script specifies the vManage
hostname and the username and password for this
instance; this example uses the same vManage server
used earlier in this chapter. The code then specifies the
base URL for the vManage REST API endpoint:
https://sandboxsdwan.cisco.com:8443. The code shows
the authentication resource (j_security_check) and the
login credentials, and then the login URL is built as a
combination of the base URL and the authentication API
resource. In the next line, a new request session
instance is created and stored in the SESS variable.


Example 8-10 Python Script Showcasing How to
Interact with the Cisco SD-WAN REST API


Click here to view code image


#! /usr/bin/env python
import json
import requests
from requests.packages.urllib3.exceptions
import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

# Specify Cisco vManage IP, username and
password
VMANAGE_IP = 'sandboxsdwan.cisco.com'
USERNAME = 'devnetuser'
PASSWORD = 'Cisco123!'
BASE_URL_STR =
'https://{}:8443/'.format(VMANAGE_IP)
# Login API resource and login credentials
LOGIN_ACTION = 'j_security_check'
LOGIN_DATA = {'j_username' : USERNAME,
'j_password' : PASSWORD}
# URL for posting login data
LOGIN_URL = BASE_URL_STR + LOGIN_ACTION
# Establish a new session and connect to Cisco
vManage
SESS = requests.session()
LOGIN_RESPONSE = SESS.post(url=LOGIN_URL,
data=LOGIN_DATA, verify=False)
Free download pdf