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

RESTCONF: getting list size

rogaglia
Cisco Employee
Cisco Employee

Hi,

 

Is there any pre-cooked way to get the size of a list via RESTCONF? For example, I need to get the number of devices in NSO.

 

I am now using the query API. but I wonder if we could use xpath in any clever way.

 

Roque

 

curl -X POST \

  https://nso-alexa:8443/restconf/tailf/query \

  -H 'Accept: application/yang-data+json' \

  -H 'Authorization: Basic YWRtaW46QzFzY28xMjM0NQ==' \

  -H 'Content-Type: application/yang-data+json' \

  -d '{

"immediate-query": {

"foreach": "/devices/device",

"select": [

{

"label": "Host name",

"expression": "name",

"result-type": ["string"]

}

],

"sort-by": ["name"],

"limit": 100,

"offset": 1

}

}'

1 Accepted Solution

Accepted Solutions

perander
Cisco Employee
Cisco Employee

There is the possibility to use the XPath count() function to achieve counting list items through the REST Query API.

 

Following the submitted query, the actual call would look something like:

curl -X POST \
-H 'Authorization: Basic YWRtaW46QzFzY28xMjM0NQ==' \
-H "Content-type: application/yang-data+json" \
https://nso-alexa:8443/restconf/tailf/query \
-d '
{"tailf-rest-query:immediate-query": {
"foreach": "/devices",
"select": [
{"expression": "count(device)",
"result-type": ["string"]
}
]
}
}'

 

View solution in original post

1 Reply 1

perander
Cisco Employee
Cisco Employee

There is the possibility to use the XPath count() function to achieve counting list items through the REST Query API.

 

Following the submitted query, the actual call would look something like:

curl -X POST \
-H 'Authorization: Basic YWRtaW46QzFzY28xMjM0NQ==' \
-H "Content-type: application/yang-data+json" \
https://nso-alexa:8443/restconf/tailf/query \
-d '
{"tailf-rest-query:immediate-query": {
"foreach": "/devices",
"select": [
{"expression": "count(device)",
"result-type": ["string"]
}
]
}
}'