cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1156
Views
5
Helpful
3
Replies

Yang leafref question

rjbotham
Level 1
Level 1

Hi All,

I wanted to as a basic question re yang leaf refs as i'm just starting with NSO

 

I have a very simple model, however ,the part i'm struggling to understand is this section below defining  the device leaf

The module imports tailf-ncs and so naturally I went looking in that module for /devices/device/name

However when I open tailf-ncs.yang it also imports many other models and I ended up 'down a rabbit hole'

I'm trying to learn so that I understand all parts of the model so would appreciate some assistance and a 'steer' if i'm mis- understanding this and where is should look to follow and understand the leaf ref

 

Thanks

Rich

 

leaf device {
      type leafref {
        path "/ncs:devices/ncs:device/ncs:name";
      }
    }

Model

module access {
  namespace "http://com/example/access";
  prefix access;

  import ietf-inet-types {
    prefix inet;
  }
  import tailf-ncs {
    prefix ncs;
  }

  list access {
    key customer-name;

    uses ncs:service-data;
    ncs:servicepoint "access";

    leaf customer-name {
      type string;
    }


    /*
    1 - We import tailf-ncs.yang and give that a prefix of ncs
    Home@Richs-MacBook-Pro:~/Documents/Programming/nso5.7/src/ncs/yang$ grep -Ril 'list devices' ./
  .//tailf-ncs-plan.yang
  .//tailf-ncs-webui.yang
  .//tailf-ncs-services.yang
  .//tailf-ncs-devices.yang
    
    */
    leaf device {
      type leafref {
        path "/ncs:devices/ncs:device/ncs:name";
      }
    }
    
    leaf vlan {
     mandatory true;
     type uint16;
    }
   
    leaf access-interface {
     mandatory true;
     type string; 
    }

    leaf trunk-interface {
     mandatory true;
     type string; 
    }
  }
}
1 Accepted Solution

Accepted Solutions

tcragg1
Cisco Employee
Cisco Employee

A leafref is a pointer to another part of the model. The leafref selects the set of leaf instances at the path listed at the "path" substatement. In this case, a leafref pointing to "/ncs:devices/ncs:device/ncs:name" will return the set of all devices configured within NSO. If you configure an instance of your service in NCS CLI and attempt an auto-complete after "device", you will see that the available options for the device leaf are the set of devices configured within NSO.

View solution in original post

3 Replies 3

tcragg1
Cisco Employee
Cisco Employee

A leafref is a pointer to another part of the model. The leafref selects the set of leaf instances at the path listed at the "path" substatement. In this case, a leafref pointing to "/ncs:devices/ncs:device/ncs:name" will return the set of all devices configured within NSO. If you configure an instance of your service in NCS CLI and attempt an auto-complete after "device", you will see that the available options for the device leaf are the set of devices configured within NSO.

Hello tcragg1,

Many thanks for the explanation

So does this actually refer to the entries in the CDB files, and I presume, that for any given service, a complete list devices would be available and not just the devices associated with that service ? 

 

import tailf-ncs {
    prefix ncs;
  }


@rjbotham wrote:

Hello tcragg1,

Many thanks for the explanation

So does this actually refer to the entries in the CDB files, and I presume, that for any given service, a complete list devices would be available and not just the devices associated with that service ? 


That's correct. If you use the same leafref in multiple services, they will each have access to the full list of devices configured in NSO.