08-17-2022 02:04 AM
Hello dears :
I have this yang model:
...
list customers{
key name;
leaf name{
type string;
}
list sites{
key site-id;
leaf site-id{type int;}
list devices{
key name;
leaf name{type string;}
}
}
}
...
I'd like to get all the devices name for each customer so I'm using restconf immediate querry wich body is :
{
"immediate-query": {
"foreach": "/customers",
"select": [
{
"label": "customer name",
"expression": "name",
"result-type": ["leaf-value"]
},
{
"label": "devices",
"expression": "sites/devices/name",
"result-type": ["inline"]
}
],
"sort-by": ["customer name"],
"limit": "100000",
"offset": "1"
}
}
But my query just return the first device of the first site on a customer.
Does somone has any idea? your help will be verry appreciate.
regards.
Solved! Go to Solution.
08-18-2022 01:52 PM
Not sure about doing it with the devices per site as a list of devices but here is an example of using a list of customers with a list of sites per customer and a leaf-list of devices at each site.
Yang:
module NestedYangList {
namespace "http://example.com/NestedYangList";
prefix NestedYangList;
import ietf-inet-types {
prefix inet;
}
import tailf-common {
prefix tailf;
}
import tailf-ncs {
prefix ncs;
}
description
"Bla bla...";
revision 2016-01-01 {
description
"Initial revision.";
}
list NestedYangList {
description "This is an RFS skeleton service";
key test;
leaf test {
tailf:info "Unique service id";
tailf:cli-allow-range;
type string;
}
uses ncs:service-data;
ncs:servicepoint NestedYangList-servicepoint;
list customers{
key name;
leaf name{
type string;
}
list sites{
key site-id;
leaf site-id{type uint8;}
leaf-list devices{
type string;
}
}
}
}
}
Query:
{
"immediate-query": {
"foreach": "/NestedYangList[test='YangListQuery']/customers[name]/sites[site-id]",
"select": [
{
"label": "customer name",
"expression": "../name",
"result-type": ["leaf-value"]
},
{
"label": "sites",
"expression": "site-id",
"result-type": ["leaf-value"]
},
{
"label": "deviceList",
"expression": "devices",
"result-type": ["inline"]
}
],
"sort-by": ["customer name"],
"limit": "100000",
"offset": "1"
}
}
So your query is telling it to loop over the list of sites per customer and pull back the devices. Not sure if you have a specific use case that the devices need to be a list instead of leaf-list.
So in this case it returns the following
{
"tailf-rest-query:query-result": {
"result": [
{
"select": [
{
"label": "customer name",
"value": "customer-1"
},
{
"label": "sites",
"value": "1"
},
{
"label": "deviceList",
"data": {
"NestedYangList:devices": [
"cust1_site1_device1,",
"cust1_site1_device2"
]
}
}
]
},
{
"select": [
{
"label": "customer name",
"value": "customer-1"
},
{
"label": "sites",
"value": "2"
},
{
"label": "deviceList",
"data": {
"NestedYangList:devices": [
"cust1_site2_device1,",
"cust1_site2_device2"
]
}
}
]
},
{
"select": [
{
"label": "customer name",
"value": "customer-2"
},
{
"label": "sites",
"value": "1"
},
{
"label": "deviceList",
"data": {
"NestedYangList:devices": [
"cust2_site1_device1,",
"cust2_site1_device2"
]
}
}
]
}
]
}
}
08-18-2022 01:52 PM
Not sure about doing it with the devices per site as a list of devices but here is an example of using a list of customers with a list of sites per customer and a leaf-list of devices at each site.
Yang:
module NestedYangList {
namespace "http://example.com/NestedYangList";
prefix NestedYangList;
import ietf-inet-types {
prefix inet;
}
import tailf-common {
prefix tailf;
}
import tailf-ncs {
prefix ncs;
}
description
"Bla bla...";
revision 2016-01-01 {
description
"Initial revision.";
}
list NestedYangList {
description "This is an RFS skeleton service";
key test;
leaf test {
tailf:info "Unique service id";
tailf:cli-allow-range;
type string;
}
uses ncs:service-data;
ncs:servicepoint NestedYangList-servicepoint;
list customers{
key name;
leaf name{
type string;
}
list sites{
key site-id;
leaf site-id{type uint8;}
leaf-list devices{
type string;
}
}
}
}
}
Query:
{
"immediate-query": {
"foreach": "/NestedYangList[test='YangListQuery']/customers[name]/sites[site-id]",
"select": [
{
"label": "customer name",
"expression": "../name",
"result-type": ["leaf-value"]
},
{
"label": "sites",
"expression": "site-id",
"result-type": ["leaf-value"]
},
{
"label": "deviceList",
"expression": "devices",
"result-type": ["inline"]
}
],
"sort-by": ["customer name"],
"limit": "100000",
"offset": "1"
}
}
So your query is telling it to loop over the list of sites per customer and pull back the devices. Not sure if you have a specific use case that the devices need to be a list instead of leaf-list.
So in this case it returns the following
{
"tailf-rest-query:query-result": {
"result": [
{
"select": [
{
"label": "customer name",
"value": "customer-1"
},
{
"label": "sites",
"value": "1"
},
{
"label": "deviceList",
"data": {
"NestedYangList:devices": [
"cust1_site1_device1,",
"cust1_site1_device2"
]
}
}
]
},
{
"select": [
{
"label": "customer name",
"value": "customer-1"
},
{
"label": "sites",
"value": "2"
},
{
"label": "deviceList",
"data": {
"NestedYangList:devices": [
"cust1_site2_device1,",
"cust1_site2_device2"
]
}
}
]
},
{
"select": [
{
"label": "customer name",
"value": "customer-2"
},
{
"label": "sites",
"value": "1"
},
{
"label": "deviceList",
"data": {
"NestedYangList:devices": [
"cust2_site1_device1,",
"cust2_site1_device2"
]
}
}
]
}
]
}
}
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