02-07-2018 06:54 AM - edited 03-01-2019 04:05 AM
I noticed in xpath.trace that the following leafref iterates through every GigabitEthernet interface on every device in the CDB to constrain the "must" down to just GigabitEthernet interfaces on the current device. This seems very inefficient and introduces quite a bit of delay (several seconds) while leafref values are being constrained to the current device. Is there a better way to do this so that the device is selected prior to the interface search?
list switch-interfaces-GigabitEthernet {
key switch-interface-id;
when "../switch-interface-type = 'GigabitEthernet'";
leaf switch-interface-id {
tailf:info "The switch interface identifier";
type leafref {
path "/ncs:devices/ncs:device/ncs:config/ios:interface/ios:GigabitEthernet/ios:name";
}
must "current()=deref(deref(current()/../../../switch-name))/../ncs:config/ios:interface/ios:GigabitEthernet/ios:name;
// ../../../switch-name is a leafref to "/net-topo:net-topo/net-topo:switch/net-topo:switch-name"
// net-topo:switch-name is a leafref to "/ncs:devices/ncs:device/ncs:name"
}
}
Solved! Go to Solution.
02-07-2018 12:16 PM
Aha, can you try this path, please note it's pseudo and probably needs some massage
/ncs:devices/ncs:device[ncs:name=../../../switch-name]/ncs:config/ios:interface/ios:GigabitEthernet/ios:name
02-07-2018 09:06 AM
If I understand you correct, you want the leafref to an interface on the device referenced by switch-name, if that's the case I'd change the leafref to something like this
path "deref(../../../switch-name)/../ncs:config/ios:interface/ios:GigabitEthernet/ios:name"
and get rid of the must statement.
02-07-2018 12:09 PM
I have been unable to figure out the proper leafref path syntax to get this working as switch-name in this example requires a nested deref which the compiler complains is invalid syntax for a path statement (one deref in a path statement works fine, but not two).
../../../switch-name is a reference to "/net-topo:net-topo/net-topo:switch/net-topo:switch-name
net-topo:switch-name is a reference to "/ncs:devices/ncs:device/ncs:name"
path "deref(deref(current()/../../../switch-name))/../ncs:config/ios:interface/ios:GigabitEthernet/ios:name" // errors out on compile with a "should be of type path-arg error"
02-07-2018 12:16 PM
Aha, can you try this path, please note it's pseudo and probably needs some massage
/ncs:devices/ncs:device[ncs:name=../../../switch-name]/ncs:config/ios:interface/ios:GigabitEthernet/ios:name
02-08-2018 11:27 AM
Thanks Fredrik! The following did it:
/ncs:devices/ncs:device[ncs:name=current()/../../../switch-name]/ncs:config/ios:interface/ios:GigabitEthernet/ios:name
02-08-2018 11:53 AM
Awesome!!
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