cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2637
Views
10
Helpful
2
Replies

Leafref explanation

Jerems
Spotlight
Spotlight

Hi Everybody !

 

I understand that leafref can easily help to import a leaf which belongs to another module/package

May i have some explanations about the "path" and "deref" attributes please ? what means the "../../../" please ?

 

type leafref {​
path "deref(../../../name)/../ncs:config/ios:interface/ios:GigabitEthernet/ios:name";​

 

Thanks in advance,

 

Jerems

1 Accepted Solution

Accepted Solutions

tcragg1
Cisco Employee
Cisco Employee

"path" refers to the path in the YANG model to which the leafref is pointing. As a simple example, you may see something similar to the below in many service models:

 

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

What this means is that the value for the hostname leaf must match the name of a device configured within NSO.

 

"deref" is the dereference function. It is used to simplify the path statement when the path will depend on the current position in the model. In the hostname leaf example above it is not necessary, because this path is always the same no matter where you are in the model.

 

In the example you have given, the starting part of the path will depend on where you are in the model. In this specific case, I believe the "name" in the deref will be a leafref pointing to "/ncs:devices/ncs:device/ncs:name", and the path "deref(../../../name)/../ncs:config/ios:interface/ios:GigabitEthernet/ios:name" will then point to a GigabitEthernet interface that exists within the device that (../../../name) points to. See page 7 of this link for some more examples of deref - https://info.tail-f.com/hubfs/Whitepapers/Whitepaper:%20XPath%20in%20NETCONF%20and%20YANG.pdf

 

"../" in the path means "go up one level" (so go to the list or container that holds the current leaf). This can be chained together, so "../../../name" means go up 3 levels in the model from your current location, and then into the "name" leaf.

View solution in original post

2 Replies 2

tcragg1
Cisco Employee
Cisco Employee

"path" refers to the path in the YANG model to which the leafref is pointing. As a simple example, you may see something similar to the below in many service models:

 

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

What this means is that the value for the hostname leaf must match the name of a device configured within NSO.

 

"deref" is the dereference function. It is used to simplify the path statement when the path will depend on the current position in the model. In the hostname leaf example above it is not necessary, because this path is always the same no matter where you are in the model.

 

In the example you have given, the starting part of the path will depend on where you are in the model. In this specific case, I believe the "name" in the deref will be a leafref pointing to "/ncs:devices/ncs:device/ncs:name", and the path "deref(../../../name)/../ncs:config/ios:interface/ios:GigabitEthernet/ios:name" will then point to a GigabitEthernet interface that exists within the device that (../../../name) points to. See page 7 of this link for some more examples of deref - https://info.tail-f.com/hubfs/Whitepapers/Whitepaper:%20XPath%20in%20NETCONF%20and%20YANG.pdf

 

"../" in the path means "go up one level" (so go to the list or container that holds the current leaf). This can be chained together, so "../../../name" means go up 3 levels in the model from your current location, and then into the "name" leaf.

Jerems
Spotlight
Spotlight

Thanks a lot for your help, that was a very clear explanation !