09-27-2017 09:59 AM - edited 03-01-2019 04:00 AM
Hey NSO Experts,
I came across the NSO REST Query API in the North bound API documentation and found it to be quite interesting and possibly powerful feature. However, the doc is a bit simple in its example and crafting more complex queries has been a bit tricky.
Does anyone have experience with the Query API that could offer some guidance? A sample query would be "Return all GigabitEthernet interface descriptions for devices in a given Device Group"
For those not familiar with the API here is a nifty simple query to get all devices where cdp is enabled:
URL: localhost:8080/api/query
Headers:
'content-type': "application/vnd.yang.data+xml"
Body:
<start-query xmlns="http://tail-f.com/ns/tailf-rest-query">
<foreach>
/ncs:devices/device
</foreach>
<select>
<label>Host name</label>
<expression>name</expression>
<result-type>string</result-type>
</select>
<select>
<label>cdp enabled</label>
<expression>config/cdp/run</expression>
<result-type>string</result-type>
</select>
<sort-by>name</sort-by>
<limit>100</limit>
<offset>1</offset>
</start-query>
Solved! Go to Solution.
09-28-2017 01:15 AM
This is mostly a question of being able to express your query in XPATH 1.0.
To select all devices that are members of device-group 'group11' and have authgroup 'vagrant' and get all the GigE interface descriptions, you could use (assuming an IOS CLI NED):
/devices/device[name=/devices/device-group[name='group11']/member][authgroup='vagrant']/config/ios:interface/GigabitEthernet/description
09-28-2017 01:15 AM
This is mostly a question of being able to express your query in XPATH 1.0.
To select all devices that are members of device-group 'group11' and have authgroup 'vagrant' and get all the GigE interface descriptions, you could use (assuming an IOS CLI NED):
/devices/device[name=/devices/device-group[name='group11']/member][authgroup='vagrant']/config/ios:interface/GigabitEthernet/description
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 NSO Developer community: