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

(andrew) #1

Figure 8-14 Getting Device Configuration Templates


Next, let’s use Python to build a script that will go
through the same steps: Log in to vManage, get a list of
all the devices in the SD-WAN fabric, and get a list of all
device templates available. No SDK will be used in this
case; this will help you see the difference between this
code and the Python code you used earlier in this
chapter. Since no SDK will be used, all the API resources,
payloads, and handling of data will have to be managed
individually.


The Python requests library will be used extensively in
this sample code. You should be familiar with this library
from Chapter 7. Example 8-10 shows a possible version
of the Python 3 script that accomplishes these tasks. The
script was developed using Python 3.7.4 and version
2.22.0 of the requests library. The json library that
comes with Python 3.7.4 was also used to deserialize and
load the data returned from the REST API into a Python
object; in this case, that object is a list. In this code, first,
the import keyword makes the two libraries requests
and json available for use within the script. Since the
connection in the script is made to an instance of
vManage that is in a sandbox environment and that uses
a self-signed SSL certificate, the third and fourth lines of
the script disable the warning messages that are
generated by the requests library when connecting to

Free download pdf