cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
808
Views
1
Helpful
5
Replies

Retrieve a device by hostname

Nathan Sowatskey
Cisco Employee
Cisco Employee

Hi

The GET /network-device API is documented as getting a list of devices with a filter including hostname. The Swagger API page does not show how to use filters, so it is not clear whether, or how, this should or would work.

The alternative seems to be to get all network devices, and then to iterate though the results looking for the device with the desired hostname. Then one can take the ID of that device and use the APIs that take {id} as an argument.

Whilst the above approach is mechanically possible, it is not very efficient. All of the devices have to returned, and iterated over, to find the ID of a single device.

Since this is obviously less than desirable, there must be a better way. Does anyone know what that is please?

Many thanks

Nathan

5 Replies 5

aradford
Cisco Employee
Cisco Employee

Hi Nathan,

the pattern is very simple and consistent.  All the filters should work the same way (if supported)

/resource?attribute=value

https://{{apic}}:{{port}}/api/v1/network-device?hostname=AHEC-2960C1

Thanks Adam. This could be usefully added to the Swagger API pages also.

Regards

Nathan

All the filters should work the same way (if supported)

I think it doesn't work in this way. I tried

Request to filter gives single response, below.  But only for attributes that are supported... like hostname

https://{{apic}}:{{port}}/api/v1/network-device?hostname=AHEC-2960C1

{

  "response": [

    {

      "family": "Switches and Hubs",

      "location": null,

      "type": "Cisco Catalyst 2960C-8PC-L Switch",

      "serialNumber": "FOC1637Y3FJ",

      "role": "CORE",

      "lastUpdated": "2016-07-06 20:40:23",

      "lastUpdateTime": 1467837623914,

      "series": "Cisco Catalyst 2960-C Series Switches",

      "upTime": "1 day, 2:20:31.50",

      "softwareVersion": "15.2(2.5.72)E4",

      "inventoryStatusDetail": "<status><general code=\"SUCCESS\"/></status>",

      "locationName": null,

      "tagCount": "2",

      "macAddress": "54:78:1a:8e:28:c0",

      "hostname": "AHEC-2960C1",

      "bootDateTime": "2016-07-05 18:20:11",

      "collectionStatus": "Managed",

      "interfaceCount": "11",

      "lineCardCount": "5",

      "lineCardId": "54daa439-db87-426a-83ae-503d5063e521, b636196b-2bd7-4e95-b17d-9ce266c3e421, 61aeed51-06a0-409e-a575-1aab41f30783, 96582c50-15cf-4621-bcdd-6fab62583c59, b70437b5-8470-4086-bcbc-3f1b946a75f6",

      "managementIpAddress": "165.10.1.31",

      "memorySize": "59556224",

      "platformId": "WS-C2960C-8PC-L",

      "reachabilityFailureReason": "",

      "reachabilityStatus": "Reachable",

      "roleSource": "MANUAL",

      "snmpContact": "",

      "snmpLocation": "",

      "tunnelUdpPort": null,

      "apManagerInterfaceIp": "",

      "instanceUuid": "2dc30cac-072e-4d67-9720-cc302d02695a",

      "id": "2dc30cac-072e-4d67-9720-cc302d02695a"

    }

  ],

  "version": "1.0"

It would be helpful, I suppose, to be able to consult some API documentation that would reveal which APIs have filters that work, and on which attributes. Trial and error is non optimal way to find out

Regards

Nathan

Getting Started

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:


This community is intended for developer topics around Data Center technology and products. If you are looking for a non-developer topic about Data Center, you might find additional information in the Data Center and Cloud community