cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1700
Views
5
Helpful
2
Replies

Yang conditional type

franjorge
Level 1
Level 1

Hello,

 

I have the following yang file, where I am trying to model the connection between a device and its neighbors:

 

module cr-art {
  list cr-art {
    key DEVICE;
    leaf DEVICE {
      type leafref {
        path "/ncs:devices/ncs:device/ncs:name";
      }
    }
    list NEIGHBOR_ROUTER {
      key NAME;
      leaf NAME {
        type leafref {
            must "current() != ../../DEVICE"{}
path "/ncs:devices/ncs:device/ncs:name"; } } list AGGR_INT { key NAME_AGGR_INT; leaf NAME_AGGR_INT { type leafref { path "/cr-art:cr-art[DEVICE=current()/../../NAME]/cr-art:NEIGHBOR_ROUTER[NAME=current()/../../../DEVICE]/cr-art:AGGR_INT/cr-art:REMOTE_AGGR_INT"; } } leaf REMOTE_AGGR_INT { type string; } } } } }

The leafref in "NAME_AGGR_INT" is working as expected, ie, if I am configuring a device, for "NAME_AGGR_INT" I get the list of ""REMOTE_AGGR_INT" previously defined in the neighbor device.

 

However, that becomes a problem when configuring the 'original' device, since no other router has it configured as a neighbor, so the leafref is empty.

 

Is there a way to choose "NAME_AGGR_INT" among the "REMOTE_AGGR_INT" configured in the neighbors if there is any, and just type a string if the leafref is empty?

 

Thanks.

 

2 Replies 2

vleijon
Cisco Employee
Cisco Employee
The easiest way might be to use the annotation tailf:no-leafref-check or possibly tailf:non-strict-leafref, see the man page tailf_yang_extensions for details.

An alternative, stricter, interpretation might be that this reference integrity is crucial, that pointing to a non-existing neighbor is senseless: Then you’d force the user to enter at least two devices initially rather than doing them one by one.

Hi,

 

Thanks four your answer.

 

I will try your suggestion regarding tailf:no-leafref-check / tailf:non-strict-leafref.

 

I do not think the second approach will work, since I am not able to even configure the first device without having configured its neighbor first.

 

Best regards.

 

Getting Started

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: