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

473
Views
0
Helpful
2
Replies
RichardD2
Beginner

Interface shutdown test for existence in xml template

I need to execute a block within my xml template if and only if, the interface is shutdown(in the config not live-status).

This test shows the existence of the condition

admin@ncs# show running-config devices device iosxr-r3 config interface Bundle-Ether 18 | display xpath
/devices/device[name='iosxr-r3']/config/cisco-ios-xr:interface/Bundle-Ether[id='18']/description "<< Blah>>"
/devices/device[name='iosxr-r3']/config/cisco-ios-xr:interface/Bundle-Ether[id='18']/mtu 1522
/devices/device[name='iosxr-r3']/config/cisco-ios-xr:interface/Bundle-Ether[id='18']/ipv4/mtu 1500
/devices/device[name='iosxr-r3']/config/cisco-ios-xr:interface/Bundle-Ether[id='18']/ipv6/mtu 1500
/devices/device[name='iosxr-r3']/config/cisco-ios-xr:interface/Bundle-Ether[id='18']/shutdown
/devices/device[name='iosxr-r3']/config/cisco-ios-xr:interface/Bundle-Ether[id='18']/load-interval 30

My XML template (snipped to show relevant piece):

snip>
<?set be_shutdown = {count(../../ncs:devices/ncs:device[name='device_name']/config/cisco-ios-xr:interface/Bundle-Ether[id='be_id']/shutdown)}?>
<snip>
<?if {/be_shutdown > 0}?>
      <interface xmlns="http://tail-f.com/ned/cisco-ios-xr"> ….

Also tried:
 <?set be_shutdown = {string-length(../../ncs:devices/ncs:device[name='device_name']/config/cisco-ios-xr:interface/Bundle-Ether[id='be_id']/shutdown)}?>
<snip>
<?if {/be_shutdown != ''}?>
      <interface xmlns="http://tail-f.com/ned/cisco-ios-xr">
        <Bundle-Ether tags="delete">

Neither of these work and I suspect it's due to the fact that the template either always returns an empty node or 0 

Processing instruction 'set': evaluating expression for variable be_id (from file "migration_cleanup-template.xml", line 8)
Evaluating "/be_id" (from file "migration_cleanup-template.xml", line 8)
Context node: /services/migration_cleanup:migration_cleanup[device_name='iosxr-r3'][be_id='18']
Result:
For /services/migration_cleanup:migration_cleanup[device_name='iosxr-r3'][be_id='18'], it evaluates to "18"
Processing instruction 'set': evaluating expression for variable be_shutdown (from file "migration_cleanup-template.xml", line 9)
Evaluating "string-length(../../ncs:devices/ncs:device[name='device_name']/config/cisco-ios-xr:interface/Bundle-Ether[id='be_id']/shutdown)" (from file "migration_cleanup-template.xml", line 9)
Context node: /services/migration_cleanup:migration_cleanup[device_name='iosxr-r3'][be_id='18']
Result: "0"

How can I test for the shutdown condition to be present in the xml (not using python or code here)

thank you,

R

 

1 ACCEPTED SOLUTION

Accepted Solutions
gmuloche
Cisco Employee

Hello,

 

the way you are using your variable looks incorrect:

 

<?if {/be_shutdown != ''}?>
      <interface xmlns="http://tail-f.com/ned/cisco-ios-xr">
        <Bundle-Ether tags="delete">

 

Have a look here:

https://github.com/NSO-developer/tme-demo/blob/0ea92876c50d825a6bf96cf21b6a19d980794394/packages/tme-demo/templates/data-centre.xml#L32

 

Probably should be:

<?if {$be_shutdown != ''}?> <interface xmlns="http://tail-f.com/ned/cisco-ios-xr"> <Bundle-Ether tags="delete">

I have tried out the count technique (on some Nexus but should be the same) and it should work I guess

 

admin@scratch(config)# xpath eval count(/devices/device[name='swn1-bgw-bi0514']/config/interface/Ethernet[name='1/1']/shutdown)
1
admin@scratch(config)# xpath eval count(/devices/device[name='swn1-bgw-bi0514']/config/interface/Ethernet[name='101/1/1']/shutdown)
0

 

However note that in your template the root-node is the service (you can read more about this in the nso development guide on templates)

 

so you would need to do something like:

 

<?set-root-node {/}?>
<?set shutdown1 = {count(/devices/device[name='swn1-bgw-bi0514']/config/interface/Ethernet[name='1/1']/shutdown)}?>
<?set shutdown101 = {count(/devices/device[name='swn1-bgw-bi0514']/config/interface/Ethernet[name='101/1/1']/shutdown)} ?>

to get the values - you can also leverage the save-context and switch-context processing instructions if you need to come back to your service context.

View solution in original post

2 REPLIES 2
gmuloche
Cisco Employee

Hello,

 

the way you are using your variable looks incorrect:

 

<?if {/be_shutdown != ''}?>
      <interface xmlns="http://tail-f.com/ned/cisco-ios-xr">
        <Bundle-Ether tags="delete">

 

Have a look here:

https://github.com/NSO-developer/tme-demo/blob/0ea92876c50d825a6bf96cf21b6a19d980794394/packages/tme-demo/templates/data-centre.xml#L32

 

Probably should be:

<?if {$be_shutdown != ''}?> <interface xmlns="http://tail-f.com/ned/cisco-ios-xr"> <Bundle-Ether tags="delete">

I have tried out the count technique (on some Nexus but should be the same) and it should work I guess

 

admin@scratch(config)# xpath eval count(/devices/device[name='swn1-bgw-bi0514']/config/interface/Ethernet[name='1/1']/shutdown)
1
admin@scratch(config)# xpath eval count(/devices/device[name='swn1-bgw-bi0514']/config/interface/Ethernet[name='101/1/1']/shutdown)
0

 

However note that in your template the root-node is the service (you can read more about this in the nso development guide on templates)

 

so you would need to do something like:

 

<?set-root-node {/}?>
<?set shutdown1 = {count(/devices/device[name='swn1-bgw-bi0514']/config/interface/Ethernet[name='1/1']/shutdown)}?>
<?set shutdown101 = {count(/devices/device[name='swn1-bgw-bi0514']/config/interface/Ethernet[name='101/1/1']/shutdown)} ?>

to get the values - you can also leverage the save-context and switch-context processing instructions if you need to come back to your service context.

RichardD2
Beginner

Hi gmuloche,

Thanks very much for the reply and great explanation - that fixed it!

R