11-24-2021 03:46 AM
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
Solved! Go to Solution.
11-25-2021 03:01 AM
"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.
11-25-2021 03:01 AM
"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.
11-25-2021 05:48 AM
Thanks a lot for your help, that was a very clear explanation !
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