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

get all list element with restconf immediate query

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.

1 Accepted Solution

Accepted Solutions

tsiemers1
Spotlight
Spotlight

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"
                            ]
                        }
                    }
                ]
            }
        ]
    }
}

View solution in original post

1 Reply 1

tsiemers1
Spotlight
Spotlight

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"
                            ]
                        }
                    }
                ]
            }
        ]
    }
}
Polls
AI-powered tools for network troubleshooting are likely to be part of everyone’s workflow sooner or later. What is the single biggest challenge or concern you see with adopting these tools in your organization?