cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
733
Views
0
Helpful
3
Replies

Template XPath gives "result: no nodes" but "xpath eval" works

mikeg22
Level 1
Level 1

I have a service template that attempts to set max-reauth-req using an XPath:

<max-reauth-req>{/etc/service/wired-nac/interface/dot1x/max-reauth-req}</max-reauth-req>

which is not getting the value:

3-Mar-2023::20:35:30.972 template ios-interface-template: evaluating: /etc/service/wired-nac/interface/dot1x/max-reauth-req
3-Mar-2023::20:35:30.972 template ios-interface-template: result: no nodes

despite the nodes existing:

admin@7ccbd23a9e56# devtools true

admin@7ccbd23a9e56# config
Entering configuration mode terminal

admin@7ccbd23a9e56(config)# xpath eval /etc/service/wired-nac/*
/etc/service/wired-nac/interface
/etc/service/wired-nac/acls

admin@7ccbd23a9e56(config)# xpath eval /etc/service/wired-nac/interface/*
/etc/service/wired-nac/interface/dot1x

admin@7ccbd23a9e56(config)# xpath eval /etc/service/wired-nac/interface/dot1x/*
/etc/service/wired-nac/interface/dot1x/timeout
/etc/service/wired-nac/interface/dot1x/max-reauth-req :: 3

I have confirmed that the value is actual (not a YANG default):

(admin@7ccbd23a9e56(config)# commit dry-run
cli {
  local-node {
    data etc {
      service {
        wired-nac {
          interface {
            dot1x {
    -         max-reauth-req 3;
    +         max-reauth-req 6;
            }
          }
        }
      }
    }
  }
}

What am I doing wrong?

1 Accepted Solution

Accepted Solutions

mikeg22
Level 1
Level 1

Thank you gentlemen! Your assistance regarding context helped me understand what was causing my problem: the XPath '/' represented the service root. I thought starting my XPath with '/' always represented the NSO CDB root.

Adding:

<?set-root-node {/}?>

to the template before the XPaths allowed them to behave as I expected (the '/' in the XPath represented the NSO CDB root).

View solution in original post

3 Replies 3

hniska
Cisco Employee
Cisco Employee

Which context are you in? A good tip is to use the "| debug template" command to see whats going on. 

Lets say you have a template and on line 33 you have your xpath. You can do this

commit dry-run | debug template | match -a 10 line\ 33

And it will show you line 33 and then the ten following lines. There you can see which context that xpath query has.

admin@ncs% commit dry-run | debug template | match -a 10 line\ 33
227:Operation 'merge' on non-existing node: /devices/device[name='ce1']/config/ios:interface/GigabitEthernet[name='0/11']/description (from file "l3vpn-ce.xml", line 33)
228:Evaluating "/name" (from file "l3vpn-ce.xml", line 33)
229-Context node: /vpn/l3vpn[name='volvo']
230-Result:
231-For /vpn/l3vpn[name='volvo'], it evaluates to "volvo"
232:Fetching literal " local network" (from file "l3vpn-ce.xml", line 33)
233-Setting /devices/device[name='ce1']/config/ios:interface/GigabitEthernet[name='0/11']/description to "volvo local network"
234-Operation 'merge' on existing node: /devices/device[name='ce1']/config/ios:interface/GigabitEthernet[name='0/11']/ip/address/primary/address (from file "l3vpn-ce.xml", line 37)
235-Evaluating "$LOCAL_CE_ADR" (from file "l3vpn-ce.xml", line 37)
236-Context node: /vpn/l3vpn[name='volvo']
237-Result: "10.7.7.1"
238-Setting /devices/device[name='ce1']/config/ios:interface/GigabitEthernet[name='0/11']/ip/address/primary/address to "10.7.7.1"
239-Operation 'merge' on existing node: /devices/device[name='ce1']/config/ios:interface/GigabitEthernet[name='0/11']/ip/address/primary/mask (from file "l3vpn-ce.xml", line 38)
240-Evaluating "$CE_MASK" (from file "l3vpn-ce.xml", line 38)
241-Context node: /vpn/l3vpn[name='volvo']
242-Result: "255.255.255.0"

l3vpn-ce_xml.jpg

Just to add to the previous reply, you can set the context when using the xpath tool to do the eval:

admin@ncs% xpath ctx devices eval device/name
/devices/device[name='ASR9K1']/name :: ASR9K1
/devices/device[name='ASR9K2']/name :: ASR9K2
/devices/device[name='IOS-XRv']/name :: IOS-XRv
/devices/device[name='MX960']/name :: MX960
/devices/device[name='MX961']/name :: MX961
/devices/device[name='MX962']/name :: MX962
/devices/device[name='MX963']/name :: MX963
/devices/device[name='PTX1']/name :: PTX1
/devices/device[name='vMX1']/name :: vMX1
/devices/device[name='vMX2']/name :: vMX2
/devices/device[name='vMX6']/name :: vMX6
[ok][2023-03-06 09:35:02]

[edit]
admin@ncs%

 

mikeg22
Level 1
Level 1

Thank you gentlemen! Your assistance regarding context helped me understand what was causing my problem: the XPath '/' represented the service root. I thought starting my XPath with '/' always represented the NSO CDB root.

Adding:

<?set-root-node {/}?>

to the template before the XPaths allowed them to behave as I expected (the '/' in the XPath represented the NSO CDB root).