07-06-2022 09:59 AM
Hi everyone,
We're trying to retrieve the devices list and basic information via RESTCONF. We are looking to get the same information we get when we do "show devices list" and/or "show devices device platform" on the CLI.
We attempted to use the following URL via RESTCONF: /restconf/data/tailf-ncs:devices/device?fields=name;address;authgroup;port;description;state/admin-state;device-type(*)
However, this request doesn't scale well, because while it takes a couple of seconds in an environment with <10 devices, it can take a minute or more in an environment with <100 devices and hours when hundreds of devices are onboarded
Can you help? I imagine that this RESTCONF request is actually fetching configuration data which is not required, perhaps there's a RESTCONF request to do the equivalent of "show devices list"?
Thank you,
Gabriel
Solved! Go to Solution.
07-06-2022 07:20 PM - edited 07-06-2022 07:37 PM
You can try what @u.avsec had suggested. Using The RESTCONF Query API .
Here the example for the
show devices list
curl -X POST 'http://localhost:8080/restconf/tailf/query' \ --header 'Content-Type: application/yang-data+json' \ -u admin:admin \ -d '{ "tailf-rest-query:immediate-query": { "foreach": "/devices/device", "select": [ { "label": "name", "expression": "name", "result-type": "string" }, { "label": "address", "expression": "address", "result-type": "string" }, { "label": "description", "expression": "description", "result-type": "string" }, { "label": "ned id ", "expression": "substring-before(device-type/*/ned-id,'\'':'\'')", "result-type": "string" }, { "label": "admin state", "expression": "state/admin-state", "result-type": "string" } ] } }'
I am using substring-before so it can impact the performane otherwise you can remove it and use just
device-type/*/ned-idas expression
{ "tailf-rest-query:query-result":{ "result":[ { "select":[ { "label":"name", "value":"TEST-IOS-XR-3.00" }, { "label":"address", "value":"127.0.0.1" }, { "label":"description", "value":"" }, { "label":"ned id", "value":"cisco-iosxr-cli-3.5" }, { "label":"admin state", "value":"unlocked" } ] }, { "select":[ { "label":"name", "value":"TEST-IOS-XR-3.01" }, { "label":"address", "value":"127.0.0.1" }, { "label":"description", "value":"" }, { "label":"ned id", "value":"cisco-iosxr-cli-3.5" }, { "label":"admin state", "value":"unlocked" } ] }, { "select":[ { "label":"name", "value":"TEST-IOS-XR-3.50" }, { "label":"address", "value":"127.0.0.1" }, { "label":"description", "value":"" }, { "label":"ned id", "value":"cisco-iosxr-cli-3.5" }, { "label":"admin state", "value":"unlocked" } ] }, { "select":[ { "label":"name", "value":"TEST-IOS-XR-3.51" }, { "label":"address", "value":"127.0.0.1" }, { "label":"description", "value":"" }, { "label":"ned id", "value":"cisco-iosxr-cli-3.5" }, { "label":"admin state", "value":"unlocked" } ] }, { "select":[ { "label":"name", "value":"TEST-IOS-XR-3.52" }, { "label":"address", "value":"127.0.0.1" }, { "label":"description", "value":"" }, { "label":"ned id", "value":"cisco-iosxr-cli-3.5" }, { "label":"admin state", "value":"unlocked" } ] } ] } }
curl -X POST 'http://localhost:8080/restconf/tailf/query' \ --header 'Content-Type: application/yang-data+json' \ -u admin:admin \ -d '{ "tailf-rest-query:immediate-query": { "foreach": "/devices/device", "select": [ { "label": "name", "expression": "name", "result-type": "string" }, { "label": "platform name", "expression": "platform/name", "result-type": "string" }, { "label": "version", "expression": "platform/version", "result-type": "string" }, { "label": "model", "expression": "platform/model", "result-type": "string" }, { "label": "serial number", "expression": "platform/serial-number", "result-type": "string" } ] } }'
{ "tailf-rest-query:query-result":{ "result":[ { "select":[ { "label":"name", "value":"NETSIM-HUAWEI" }, { "label":"platform name", "value":"huawei-vrp" }, { "label":"version", "value":"8.160 (NE40E V800R010C00SPC200)" }, { "label":"model", "value":"NE40E-M2H(NETSIM)" }, { "label":"serial number", "value":"NETSIMSERIALNO" } ] } ] } }
07-06-2022 12:39 PM
Can you post-show devices list output, what device is this ?
07-06-2022 01:11 PM
Unless you find something better; perhaps look into RESTCONF Query API section of NSO Northbound guide.
07-06-2022 07:20 PM - edited 07-06-2022 07:37 PM
You can try what @u.avsec had suggested. Using The RESTCONF Query API .
Here the example for the
show devices list
curl -X POST 'http://localhost:8080/restconf/tailf/query' \ --header 'Content-Type: application/yang-data+json' \ -u admin:admin \ -d '{ "tailf-rest-query:immediate-query": { "foreach": "/devices/device", "select": [ { "label": "name", "expression": "name", "result-type": "string" }, { "label": "address", "expression": "address", "result-type": "string" }, { "label": "description", "expression": "description", "result-type": "string" }, { "label": "ned id ", "expression": "substring-before(device-type/*/ned-id,'\'':'\'')", "result-type": "string" }, { "label": "admin state", "expression": "state/admin-state", "result-type": "string" } ] } }'
I am using substring-before so it can impact the performane otherwise you can remove it and use just
device-type/*/ned-idas expression
{ "tailf-rest-query:query-result":{ "result":[ { "select":[ { "label":"name", "value":"TEST-IOS-XR-3.00" }, { "label":"address", "value":"127.0.0.1" }, { "label":"description", "value":"" }, { "label":"ned id", "value":"cisco-iosxr-cli-3.5" }, { "label":"admin state", "value":"unlocked" } ] }, { "select":[ { "label":"name", "value":"TEST-IOS-XR-3.01" }, { "label":"address", "value":"127.0.0.1" }, { "label":"description", "value":"" }, { "label":"ned id", "value":"cisco-iosxr-cli-3.5" }, { "label":"admin state", "value":"unlocked" } ] }, { "select":[ { "label":"name", "value":"TEST-IOS-XR-3.50" }, { "label":"address", "value":"127.0.0.1" }, { "label":"description", "value":"" }, { "label":"ned id", "value":"cisco-iosxr-cli-3.5" }, { "label":"admin state", "value":"unlocked" } ] }, { "select":[ { "label":"name", "value":"TEST-IOS-XR-3.51" }, { "label":"address", "value":"127.0.0.1" }, { "label":"description", "value":"" }, { "label":"ned id", "value":"cisco-iosxr-cli-3.5" }, { "label":"admin state", "value":"unlocked" } ] }, { "select":[ { "label":"name", "value":"TEST-IOS-XR-3.52" }, { "label":"address", "value":"127.0.0.1" }, { "label":"description", "value":"" }, { "label":"ned id", "value":"cisco-iosxr-cli-3.5" }, { "label":"admin state", "value":"unlocked" } ] } ] } }
curl -X POST 'http://localhost:8080/restconf/tailf/query' \ --header 'Content-Type: application/yang-data+json' \ -u admin:admin \ -d '{ "tailf-rest-query:immediate-query": { "foreach": "/devices/device", "select": [ { "label": "name", "expression": "name", "result-type": "string" }, { "label": "platform name", "expression": "platform/name", "result-type": "string" }, { "label": "version", "expression": "platform/version", "result-type": "string" }, { "label": "model", "expression": "platform/model", "result-type": "string" }, { "label": "serial number", "expression": "platform/serial-number", "result-type": "string" } ] } }'
{ "tailf-rest-query:query-result":{ "result":[ { "select":[ { "label":"name", "value":"NETSIM-HUAWEI" }, { "label":"platform name", "value":"huawei-vrp" }, { "label":"version", "value":"8.160 (NE40E V800R010C00SPC200)" }, { "label":"model", "value":"NE40E-M2H(NETSIM)" }, { "label":"serial number", "value":"NETSIMSERIALNO" } ] } ] } }
07-07-2022 05:17 AM
Thank you very much, this is exactly what we were looking for. The performance is significantly better (went from hours to seconds!)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide