Quick Start
Make sure that you have viptela installed and upgraded to the latest version.
Set credentials as environment variables
IP/DNS and credentials for the vManage server can be set for the SDK via environment variable. You need to supply valid values for the following variables:
VMANAGE_HOSTVMANAGE_USERNAMEVMANAGE_PASSWORD
There are many places and diverse ways that you can set an environment variable, which can include:
- A setting within your development IDE
- A setting in your container / PaaS service
- A statement in a shell script that configures and launches your app
It can be as simple as setting it in your CLI before running your script:
export VMANAGE_HOST=your_host_here
export VMANAGE_USERNAME=your_username_here
export VMANAGE_PASSWORD= your_password_here
python myscript.py
Or putting your credentials in a shell script that you source when your shell starts up or before your run a script:
$ cat mycredentials.sh
export VMANAGE_HOST=your_host_here
export VMANAGE_USERNAME=your_username_here
export VMANAGE_PASSWORD= your_password_here
$ source mycredentials.sh
$ python myscript.py
Create an "Authentication" object
First, create an Authentication object and call the login function.
>>> from vmanage.api.authentication import Authentication
>>> import os
>>> vmanage_host = os.environ.get('VMANAGE_HOST')
>>> vmanage_username = os.environ.get('VMANAGE_USERNAME')
>>> vmanage_password = os.environ.get('VMANAGE_PASSWORD')
>>> auth = Authentication(host=vmanage_host, user=vmanage_username, password=vmanage_password).login()
Making API calls
Once you are authenticated to Cisco vManage, make API calls by creating an instance of the API object you are interested in (e.g. Device, Settings, LocalPolicy, etc.) and calling the functions from that object. The example below, retrieves a list of all devices.
>>> from vmanage.api.device import Device
>>> vmanage_device = Device(auth, vmanage_host)
>>> device_config_list = vmanage_device.get_device_config_list('all')
For documentation on all of the supported API objects and functions, refer to the readthedocs page.
Working with returned data
Data returned by the SDK is usually a python dictionary. The example below extracts the hostnames from device_config_list by referencing the dictionary host-name key.
for device in device_config_list:
try:
print(device['host-name'])
except KeyError:
pass