Cisco SD-WAN vManage API Client Code Examples¶
This guide shows how to use the
CiscoVmanage client to interact with Cisco SD-WAN vManage APIs.
The Wingpy vManage client is designed for seamless interaction with Cisco SD-WAN vManage REST APIs, including authentication, token refresh, logging, concurrency, and error management.
- The client raises
UnsupportedMethodErrorfor unsupported HTTP methods (e.g., PATCH). - You can call the
.authenticate()method to force (re-)authentication.
Environment Variables
You can set the environment variables in your shell to avoid hardcoding sensitive information in your code. See the FAQ on Environment Variables for more details.
The Basics - Connect and Get Data¶
Connect to Cisco SD-WAN vManage
from wingpy import CiscoVmanage
vmanage = CiscoVmanage(
base_url="https://vmanage.example.com/dataservice", # (1)!
username="...", # (2)!
password="...", # (3)!
verify=False,
)
-
Environment variable:
-
Environment variable:
-
Environment variable:
Get all devices
# Returns a list of device records
devices = vmanage.get_all("/device")
for device in devices:
print(f"{device['deviceId']}: {device['host-name']} ({device['device-type']})")
Get device details
device_id = "10.10.22.33"
device = vmanage.get(f"/device/{device_id}").json()
print(f"Device {device['host-name']} is a {device['device-type']} with system IP {device['system-ip']}")
Push a device template to a router
# Example: Attach a device template to a router (push configuration)
template_id = "b1c2d3e4-5678-90ab-cdef-1234567890ab"
device_id = "10.10.22.33"
payload = {
"deviceTemplateList": [
{
"templateId": template_id,
"device": [
{
"csv-status": "complete",
"csv-deviceId": device_id,
"csv-deviceIP": "192.168.1.10",
"csv-host-name": "Branch-Router-1",
"csv-templateId": template_id
}
],
"isEdited": True,
"isMasterEdited": False
}
]
}
rsp = vmanage.post("/template/device/config/attach", data=payload)
print(f"Template push status: {rsp.status_code}")
Reboot a device
# Example: Reboot a device using the action API
device_id = "10.10.22.33"
payload = {
"deviceType": "vedge",
"deviceIP": device_id,
"action": "reboot"
}
rsp = vmanage.post("/device/action/reboot", data=payload)
print(f"Reboot action status: {rsp.status_code}")
Bulk Operations¶
Bulk create items
items = [
{"name": "item1", "value": 1},
{"name": "item2", "value": 2},
]
bulk_payload = {
"deviceTemplateList": [
{
"templateId": "b1c2d3e4-5678-90ab-cdef-1234567890ab",
"device": [
{"csv-deviceId": "10.10.22.33", "csv-host-name": "Branch-Router-1"},
{"csv-deviceId": "10.10.22.34", "csv-host-name": "Branch-Router-2"}
],
"isEdited": True,
"isMasterEdited": False
}
]
}
rsp = vmanage.post("/template/device/config/attach", data=bulk_payload)
print(f"Bulk template attach status: {rsp.status_code}")
Summary¶
- The
CiscoVmanageclient simplifies interaction with Cisco SD-WAN vManage APIs. - Handles authentication, token refresh, and error management automatically.
- Supports all HTTP verbs (except PATCH), bulk operations, path parameterization, and concurrency.
- For advanced usage, refer to the API Reference, the FAQ, and the general User Guide.