cancel
Showing results for 
Search instead for 
Did you mean: 
cancel

Who Me Too'd this topic

Unable to use XPath as a value when deploying a device template with variables

We are using NSO 5.3.1.1

admin@8a4d49ee4c2a# show ncs-state version
ncs-state version 5.3.1.1

We attempted to apply a device template with a variable. This works fine. When doing it, we noticed that <node set> was an available option, which is an XPath expression.

admin@8a4d49ee4c2a(config)# devices device csr1 apply-template template-name test-variables variable { name NAME value ?
Possible completions:
<node set> an XPath expression resulting in a node set
<number> some integer or float number. This is an XPath number.
<quoted> some text enclosed in single quotes. This is an XPath string.

While attempting to use the results from an XPath expression in the device template (similar to how we would for a service template), we were unable to actually get it to work.

admin@8a4d49ee4c2a(config)# devices device csr1 apply-template template-name test-variables variable { name NAME value /devices/device[name='csr1']/address }
Error: Variable: NAME could not be set to: /devices/device[name='csr1']/address due to: XPATH syntax error. Did you forget enclosing single quotes for string?

admin@8a4d49ee4c2a(config)# devices device csr1 apply-template template-name test-variables variable { name NAME value /devices/device/address }
Error: Variable: NAME could not be set to: /devices/device/address due to: XPATH syntax error. Did you forget enclosing single quotes for string?

 

We attempted to use a XPath function of string(), thinking that may be required. But it failed, doing a regular xpath eval with string() does provide a value though.

admin@8a4d49ee4c2a(config)# devices device csr1 apply-template template-name test-variables variable { name NAME value string(/devices/device/address) }
Error: Variable: NAME could not be set to: string(/devices/device/address) due to: XPATH syntax error. Did you forget enclosing single quotes for string?

admin@8a4d49ee4c2a(config)# xpath eval string(/devices/device/address)
10.11.12.113

admin@8a4d49ee4c2a(config)# xpath eval /devices/device/address
/devices/device[name='csr-lab']/address :: 10.11.12.113
/devices/device[name='csr1']/address :: 10.11.12.113
/devices/device[name='gns3-csr1']/address :: 172.16.233.168
/devices/device[name='gns3-iosv-1']/address :: 172.16.233.167
/devices/device[name='gns3-ospf-iosv1']/address :: 172.16.233.216
/devices/device[name='gns3-ospf-iosv2']/address :: 172.16.233.217
/devices/device[name='new']/address :: 172.16.233.168

 

We used a XPath function, and found that it is being evaluated.

allen.chen@nso-hq-1(config)# devices device-group mygroup apply-template template-name vartest variable { name NAME value count() }
Error: Variable: NAME could not be set to: count() due to: Function count() can not be called with 0 arguments. Did you forget enclosing single quotes for string?

Below is the YANG, it looks like the type is yang:xpath1.0

list variable {
key name;
leaf name {
tailf:cli-completion-actionpoint "template-variable";
type string {
tailf:info
"The name of the XPath variable as used in the template";
}
mandatory "true";
}
leaf value {
type union {
type string {
tailf:info
"quoted;;some text enclosed in single quotes. This
is an XPath string.";
}
type string {
tailf:info
"number;;some integer or float number. This is an XPath
number.";
}
type yang:xpath1.0 {
tailf:info
"node set;;an XPath expression resulting in a node set";
}
}
mandatory "true";
}
}

Does anyone have any idea what we are missing? Or is this bug?

Who Me Too'd this topic