cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1265
Views
0
Helpful
5
Replies

xpath nested deref iterates through every cdb device

ryan-hitch
Level 4
Level 4

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"
          }

        }

1 Accepted Solution

Accepted Solutions

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

View solution in original post

5 Replies 5

frjansso
Cisco Employee
Cisco Employee

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.

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"

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

Thanks Fredrik! The following did it:

/ncs:devices/ncs:device[ncs:name=current()/../../../switch-name]/ncs:config/ios:interface/ios:GigabitEthernet/ios:name

Awesome!!