cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1852
Views
5
Helpful
2
Replies

xpath check for Config-Templates

Abdel el Anazi
Level 1
Level 1

Hi,

 

I am having some challenges when implementing config templates based on device version using config-template only.

My solution is aiming to use the platform version from the devices provided by the NED based on the version nr a config template is pushed.

 

The Version can be anything between saos-06-11-01-0000 and saos-06-17-01-0149. The logic I am aiming to implement is when the version is above saos-06-15-00-000 then push the new config style else push the old format.

 

Here is an example of the version output:

nsoadmin@ncs# show devices device 3916-* platform version
NAME VERSION
----------------------------
3916-A saos-06-17-01-0149
3916-B saos-06-14-00-0434

 

nsoadmin@ncs# show devices device 3916-* platform version | display xpath
/devices/device[name='3916-A']/platform/version saos-06-17-01-0149
/devices/device[name='3916-B']/platform/version saos-06-14-00-0434
nsoadmin@ncs#

 

First I tried to use the following logic:

<?set-root-node {/devices/device[name=$EDU-DEVICE]/platform}?>
<?if {/version <= 'saos-06-15-00-0000'}?>

 

I realized it was not working due to the datatype which is a string so comparison operators will not work.

Also converting the check to number did not result in a valid result.

<?if {number(/version) <= 'saos-06-15-00-0000'}?>

 

I end up using the following logic:

 

<?set-root-node {/devices/device[name=$EDU-DEVICE]/platform}?>
<?for i=0; {$i < 15}; i={$i +1}?>
<?if {/version = concat('saos-06-',$i,'-00-0434')}?>
<!--OLD style config section-->
<?else?>
<!--New style config section-->
<?end?>
<?end?>
 
But the issue I have with this approach is that the for loop iterate over all nr's from 0 to 15 each time the result is false it pushes the else section and when the result is true it also pushes the if section, which ends up in both code being pushed to the device having any version between (saos-06-0-00-0434 - saos-06-15-00-0434).
 
The solutions can be implemented in python very easy however a requirement I have is to use XML only.
Looking forward to read your feedback.
 
Thank you.
 
 
1 Accepted Solution

Accepted Solutions

mvolf
Cisco Employee
Cisco Employee

You may want to try string-compare(string,string) returning -1, 0, or 1. It is NSO XPath extension usable in other contexts, maybe it works in templates too - see tailf_yang_extension man page.

View solution in original post

2 Replies 2

mvolf
Cisco Employee
Cisco Employee

You may want to try string-compare(string,string) returning -1, 0, or 1. It is NSO XPath extension usable in other contexts, maybe it works in templates too - see tailf_yang_extension man page.

Thank you very much for pointing that out, after reading the man page I have to change the logic to the following:

<?if {string-compare(/version, 'saos-06-14-00-0434') <=0}?>
The result worked exactly as I wanted...