cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1351
Views
0
Helpful
4
Replies

Getting Devices List via Restconf

equinix
Level 1
Level 1

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 

 

 

1 Accepted Solution

Accepted Solutions

Nabsch
Spotlight
Spotlight

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-id
 as expression
 
 
Here the output  that i got
 
 
{
   "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"
               }
            ]
         }
      ]
   }
}
Here  also the show devices  device plateform
 
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"
            }
        ]
    }
}'
Here the output 
 
{
   "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"
               }
            ]
         }
      ]
   }
}
 
You can use the command show devices device platform | display xpath , If want to find another xpath that i didn't specify for example a specific xpath for a specific ned. 
 
 
I hope it's going to help you.
 
 

View solution in original post

4 Replies 4

balaji.bandi
Hall of Fame
Hall of Fame

Can you post-show devices list output, what device is this ?

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

u.avsec
Spotlight
Spotlight

Unless you find something better; perhaps look into RESTCONF Query API section of NSO Northbound guide.

Nabsch
Spotlight
Spotlight

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-id
 as expression
 
 
Here the output  that i got
 
 
{
   "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"
               }
            ]
         }
      ]
   }
}
Here  also the show devices  device plateform
 
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"
            }
        ]
    }
}'
Here the output 
 
{
   "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"
               }
            ]
         }
      ]
   }
}
 
You can use the command show devices device platform | display xpath , If want to find another xpath that i didn't specify for example a specific xpath for a specific ned. 
 
 
I hope it's going to help you.
 
 

Thank you very much, this is exactly what we were looking for. The performance is significantly better (went from hours to seconds!)