Cisco Nexus Dashboard API Client Code Examples¶
This guide shows how to use the
CiscoNexusDashboard client to interact with Cisco Nexus Dashboard APIs.
It handles authentication, token refresh, and error management for you.
Connect to Cisco Nexus Dashboard
from wingpy import CiscoNexusDashboard
nexusdashboard = CiscoNexusDashboard(
base_url="https://nexusdashboard.example.com", # (1)!
username="admin", # (2)!
password="password", # (3)!
verify=False,
)
-
Environment variable:
-
Environment variable:
-
Environment variable:
Get all fabrics
fabrics = nexusdashboard.get_all("/api/v1/manage/fabrics")
for fabric in fabrics:
print(fabric["name"])
Get specific fabric
rsp = nexusdashboard.get(
"/api/v1/manage/fabrics/{fabricName}",
path_params={"fabricName": "MyFabrics"}
)
print(rsp.json())
Add switch credentials
new_switch = {
"switchIds": [{"switchId": "9PRQ123LKAB"}],
"switchUsername": "devnet",
"switchPassword": "Cisco123!",
}
rsp = nexusdashboard.post(
"/api/v1/manage/credentials/switches",
data=new_switch,
)
print(rsp.status_code())
Replace deployment freeze status
freeze_status = {"deploymentFreeze": False}
rsp = nexusdashboard.put(
"/api/v1/manage/fabrics/{fabricName}/deploymentFreeze",
path_params={"fabricName": "MyFabric"},
data=freeze_status
)
print(rsp.status_code())
Update tenant (MSO API)
# Note: This endpoint is part of the MSO (Multi-Site Orchestrator) APIs, often available via Nexus Dashboard.
tenant = {
"bsonIdent": "5b90695f1e00005d3b46efa2",
"name": "Tenant01",
"displayName": "My Tenant"
}
rsp = nexusdashboard.patch(
"/mso/api/v1/tenants/{tenantId}",
path_params={"tenantId": "5b90695f1e00005d3b46efa2"},
data=tenant
)
print(rsp.status_code())