08-29-2022 12:34 AM - edited 08-29-2022 03:53 AM
The script below is working in DNAC version 2.2.3.5 (Cisco DNA Center Platform 1.6.1.162) and stopped working when DNAC was upgraded to version 2.3.3.4 (Cisco DNA Center Platform 1.8.1.120)
What should I change in the script to have it working? I could not find anything in the release notes about changes for the API.
Top of the script is omitted...
# Get count of devices
headers = {'X-Auth-Token': token, 'Content-Type': 'application/json'}
DEVICES_COUNT_URL = '/dna/intent/api/v1/network-device/count'
response = requests.get(BASE_URL + DEVICES_COUNT_URL,
headers=headers, verify=False)
# Print device count
print(response.json()['response'])
# Get device
query_params = {
'family': 'cat9k'
}
DEVICES_URL = '/dna/intent/api/v1/network-device'
response = requests.get(BASE_URL + DEVICES_URL,
params=query_params,
headers=headers, verify=False)
device_id = response.json()
print("Device ID: ", device_id)
The output is shown below. As you can see the "network-device/count" is working and the "response" for a specific device is empty.
Execute script: ./sdalab_get-devices.py
11
Device ID: {'response': [], 'version': '1.0'}
Solved! Go to Solution.
08-30-2022 05:14 AM - edited 08-30-2022 05:15 AM
Hi there,
The response is empty because your query_params seems to be invalid. Below are some example definitions for "family" (also sharing Series & Type in case it helps):
atestini@ubuntu-atestini:~$ python3 support.py | grep -i "type\|family\|series"
'family': 'Switches and Hubs',
'series': 'Cisco Catalyst 9300 Series Switches',
'type': 'Cisco Catalyst 9300 Switch',
'family': 'Switches and Hubs',
'series': 'Cisco Catalyst 3850 Series Ethernet Stackable Switch',
'type': 'Cisco Catalyst38xx stack-able ethernet switch',
'family': 'Switches and Hubs',
'series': 'Cisco Catalyst 9200 Series Switches',
'type': 'Cisco Catalyst 9200 Switch Stack',
The above is the result of modifying the provided .py to:
# Get devices with below family
query_params = {
'family': 'Switches and Hubs'
}
DEVICES_URL = '/dna/intent/api/v1/network-device'
response = requests.get(BASE_URL + DEVICES_URL,
params=query_params,
headers=headers, verify=False)
# pprint(response.json())
#Print Device ID and Hostname for every device in response
for device in response.json()['response']:
print('DeviceID: {0}, Hostname: {1}'.format(device['id'], device['hostname']))
We can now retrieve a list of Device IDs against the network-device endpoint.
atestini@ubuntu-atestini:~$ python3 support.py
8
DeviceID: db0f68f5-b807-4047-b2c7-7999533bcdd8, Hostname: LON-C9K-1
DeviceID: d593df57-7c78-4ea3-8424-f4c2a8684ea6, Hostname: LON-C9K-2
DeviceID: 874aa80f-81c0-4567-9b52-e9e93a2ab0c0, Hostname: TEST-C3850-1
DeviceID: 5a61c67f-1554-4640-bed6-ea32a5446f44, Hostname: TEST-C3850-3
DeviceID: 2938685d-1c99-4be5-a11e-94b47b0901cf, Hostname: TEST-C9K-1
DeviceID: c8980f50-4329-4af1-8c05-19ff263d80fe, Hostname: TEST-C9K-2
P.S: The only time I've seen 'family': 'cat9k' is in the context of SWIM API endpoints. Some samples below:
atestini@ubuntu-atestini:~$ curl -k --location --request GET 'https://10.100.14.133/api/v2/device-image/device?id=d593df57-7c78-4ea3-8424-f4c2a8684ea6' \
--header 'x-auth-token: <redacted>' \
--header 'Cookie: JSESSIONID=1slxn2yjltj3o1hgraycvznn2o'
{
"response": [
{
"deviceId": "d593df57-7c78-4ea3-8424-f4c2a8684ea6",
"productType": "Cisco Catalyst 9300 Switch",
"productSeries": "Cisco Catalyst 9300 Series Switches",
"productFamily": "Switches and Hubs",
"deviceImageUpgradeStatus": "OUTDATED",
"deviceInstalledInfo": [
{
"imageUuid": null,
"name": "CAT9K[17.06.01.0.250]",
"type": "SYSTEM",
"version": "17.06.01.0.250",
"displayVersion": "17.6.1",
"family": "CAT9K",
"golden": false,
"subpackageType": null
},
{
"imageUuid": "6c27c035-9848-40d1-8f74-d888e8f668bf",
"name": "C9800-SW-iosxe-wlc.17.06.01.SPA.bin",
"type": "SUBPACKAGE",
"version": "17.06.01.0.250",
"displayVersion": "17.06.01.0.250",
"family": "CAT9K",
"golden": false,
"subpackageType": null
}
],
"targetImageInfo": [
{
"imageUuid": "6d4bb9d6-5111-45b8-8b52-4fb39dbc5089",
"name": "cat9k_iosxe.17.03.05.SPA.bin",
"family": "CAT9K",
"version": "17.03.05.0.6600",
"displayVersion": "17.03.05",
"md5Checksum": "62dcae59c73eb99aa54969b4da5a7c84",
"shaCheckSum": "b57e5a44cca1874b698653e8b967baf149beae8537cd1acfce0f18c80ccbbc01e2013cfb0dcbe69b82e234d957b0c1d57f89c796812ac2017e263dc52ddad556",
"createdTime": "2022-05-27 03:27:00.544",
"imageType": "SYSTEM_SW",
<snip>
Hope that helps!
08-30-2022 05:14 AM - edited 08-30-2022 05:15 AM
Hi there,
The response is empty because your query_params seems to be invalid. Below are some example definitions for "family" (also sharing Series & Type in case it helps):
atestini@ubuntu-atestini:~$ python3 support.py | grep -i "type\|family\|series"
'family': 'Switches and Hubs',
'series': 'Cisco Catalyst 9300 Series Switches',
'type': 'Cisco Catalyst 9300 Switch',
'family': 'Switches and Hubs',
'series': 'Cisco Catalyst 3850 Series Ethernet Stackable Switch',
'type': 'Cisco Catalyst38xx stack-able ethernet switch',
'family': 'Switches and Hubs',
'series': 'Cisco Catalyst 9200 Series Switches',
'type': 'Cisco Catalyst 9200 Switch Stack',
The above is the result of modifying the provided .py to:
# Get devices with below family
query_params = {
'family': 'Switches and Hubs'
}
DEVICES_URL = '/dna/intent/api/v1/network-device'
response = requests.get(BASE_URL + DEVICES_URL,
params=query_params,
headers=headers, verify=False)
# pprint(response.json())
#Print Device ID and Hostname for every device in response
for device in response.json()['response']:
print('DeviceID: {0}, Hostname: {1}'.format(device['id'], device['hostname']))
We can now retrieve a list of Device IDs against the network-device endpoint.
atestini@ubuntu-atestini:~$ python3 support.py
8
DeviceID: db0f68f5-b807-4047-b2c7-7999533bcdd8, Hostname: LON-C9K-1
DeviceID: d593df57-7c78-4ea3-8424-f4c2a8684ea6, Hostname: LON-C9K-2
DeviceID: 874aa80f-81c0-4567-9b52-e9e93a2ab0c0, Hostname: TEST-C3850-1
DeviceID: 5a61c67f-1554-4640-bed6-ea32a5446f44, Hostname: TEST-C3850-3
DeviceID: 2938685d-1c99-4be5-a11e-94b47b0901cf, Hostname: TEST-C9K-1
DeviceID: c8980f50-4329-4af1-8c05-19ff263d80fe, Hostname: TEST-C9K-2
P.S: The only time I've seen 'family': 'cat9k' is in the context of SWIM API endpoints. Some samples below:
atestini@ubuntu-atestini:~$ curl -k --location --request GET 'https://10.100.14.133/api/v2/device-image/device?id=d593df57-7c78-4ea3-8424-f4c2a8684ea6' \
--header 'x-auth-token: <redacted>' \
--header 'Cookie: JSESSIONID=1slxn2yjltj3o1hgraycvznn2o'
{
"response": [
{
"deviceId": "d593df57-7c78-4ea3-8424-f4c2a8684ea6",
"productType": "Cisco Catalyst 9300 Switch",
"productSeries": "Cisco Catalyst 9300 Series Switches",
"productFamily": "Switches and Hubs",
"deviceImageUpgradeStatus": "OUTDATED",
"deviceInstalledInfo": [
{
"imageUuid": null,
"name": "CAT9K[17.06.01.0.250]",
"type": "SYSTEM",
"version": "17.06.01.0.250",
"displayVersion": "17.6.1",
"family": "CAT9K",
"golden": false,
"subpackageType": null
},
{
"imageUuid": "6c27c035-9848-40d1-8f74-d888e8f668bf",
"name": "C9800-SW-iosxe-wlc.17.06.01.SPA.bin",
"type": "SUBPACKAGE",
"version": "17.06.01.0.250",
"displayVersion": "17.06.01.0.250",
"family": "CAT9K",
"golden": false,
"subpackageType": null
}
],
"targetImageInfo": [
{
"imageUuid": "6d4bb9d6-5111-45b8-8b52-4fb39dbc5089",
"name": "cat9k_iosxe.17.03.05.SPA.bin",
"family": "CAT9K",
"version": "17.03.05.0.6600",
"displayVersion": "17.03.05",
"md5Checksum": "62dcae59c73eb99aa54969b4da5a7c84",
"shaCheckSum": "b57e5a44cca1874b698653e8b967baf149beae8537cd1acfce0f18c80ccbbc01e2013cfb0dcbe69b82e234d957b0c1d57f89c796812ac2017e263dc52ddad556",
"createdTime": "2022-05-27 03:27:00.544",
"imageType": "SYSTEM_SW",
<snip>
Hope that helps!
08-30-2022 06:06 AM
Thank you very much @Andrea Testino
This was indeed the issue. After adjusting the query_params the response is working. You are right that I was working on the SWIM API example and that is why this mistake happened.
08-30-2022 08:44 AM
My pleasure. Happy to help.
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: