Catalyst Center

This guide shows how to use the CiscoCatalystCenter client to interact with Cisco Catalyst Center APIs.

The Catalyst Center client is designed for seamless interaction with Cisco DNA Center's intent APIs, supporting advanced device management, credential operations, and task polling. It handles authentication, token refresh, and error management for you.

Connect to Catalyst Center
from wingpy import CiscoCatalystCenter

catalyst = CiscoCatalystCenter(
    base_url="https://catalyst-center.example.com", # (1)!
    username="admin", # (2)!
    password="password", # (3)!
    verify=False,
)
  1. Environment variable:
    WINGPY_CATALYST_CENTER_BASE_URL
    
  2. Environment variable:
    WINGPY_CATALYST_CENTER_USERNAME
    
  3. Environment variable:
    WINGPY_CATALYST_CENTER_PASSWORD
    

Get all network devices
rsp = catalyst.get("/dna/intent/api/v1/network-device/")
for device in rsp.json().get("response", []):
    print(device["hostname"])

Get device by ID
device_id = "<your-device-id>"
rsp = catalyst.get(f"/dna/intent/api/v1/network-device/{device_id}")
print(rsp.json())

Create SNMP credentials
snmp = {
    "description": "Example SNMP",
    "readCommunity": "public",
}
rsp = catalyst.post(
    "/dna/intent/api/v2/global-credential",
    data={"snmpV2cRead": [snmp]},
)
task_id = rsp.json()["response"]["taskId"]

As Catalyst Center uses asynchronous tasks for operations, you need to poll for task completion. Use the snippet below to check the status of the task:

Poll for task completion
import time

while True:
    status = catalyst.get(f"/dna/intent/api/v1/tasks/{task_id}")
    if status.json()["response"]["isError"] or status.json()["response"]["endTime"]:
        break
    time.sleep(2)
print(status.json()["response"]["status"])

Update SNMP credentials
# First, get the credential ID
api = "/dna/intent/api/v2/global-credential"
rsp = catalyst.get(api)
snmp_id = [cred["id"] for cred in rsp.json()["response"]["snmpV2cRead"] if cred["description"] == "Example SNMP"][0]

update = {
    "instanceUuid": snmp_id,
    "description": "Example SNMP",
    "readCommunity": "public",
}
rsp = catalyst.put(
    "/dna/intent/api/v1/global-credential/snmpv2-read-community",
    data=update,
)
task_id = rsp.json()["response"]["taskId"]
# Poll for task completion as above

Delete SNMP credentials
api = "/dna/intent/api/v2/global-credential"
rsp = catalyst.get(api)
snmp_id = [cred["id"] for cred in rsp.json()["response"]["snmpV2cRead"] if cred["description"] == "Example SNMP"][0]
rsp = catalyst.delete(f"{api}/{snmp_id}")
print(rsp.status_code)

  • The client raises UnsupportedMethodError for unsupported HTTP methods (e.g., PATCH).
  • Authentication and token refresh are handled automatically, but you can call catalyst.authenticate() to force re-authentication.