10-20-2020 10:32 AM
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
Solved! Go to Solution.
10-21-2020 02:09 AM
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:
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.
10-21-2020 02:09 AM
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:
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.
10-21-2020 07:06 AM
Hi gmuloche,
Thanks very much for the reply and great explanation - that fixed it!
R
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide