Showing results for 
Search instead for 
Did you mean: 

Using NSO XML templates to shut/no shut Nexus Ethernet interfaces

Hi team, this is my first post so apologies if this is not posted in the correct forum. Please help me move it to the correct one if it shouldnt be here.


We are using NSO service package with Python and template...

We take in 3 variables from yang, device name, interface number and true or false for shutdown.


in xml output, for no shut interface it looks like this...

root@ncs> request devices device mario_nexus sync-from dry-run { outformat xml }
result-xml <interface xmlns="">
                <shutdown xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"

[ok][2020-02-06 09:12:16]

for shutting down the interface the XML generated looks like this...

root@ncs> request devices device mario_nexus sync-from dry-run { outformat xml }
result-xml <interface xmlns="">

[ok][2020-02-06 09:11:03]

i'm trying to use if statements in the python logic and a variable in the XML template so that if shutdown is true, then just send a blank string leaving the xml untouched. However if shutdown is false (i.e. no shutdown) then append the <shutdown/> element with a variable so the template looks like the below...


       <interface xmlns="">
           <shutdown {$ACTION}/>

so for a shutdown action the ACTION variable would be blank string resulting in <shutdown /> whereas for no shutdown it would append like this... <shutdown xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete"/>


However when reloading the packages in NSO i get errors about the XML syntax... does anyone know how this can be corrected or a different way to achieve shut/no shut of Nexus Ethernet interfaces?

reload-result {
    package shutdown-switchport-nexus
    result false
    info [shutdown-switchport-nexus-template.xml:10: Invalid attribute syntax in tag 'shutdown'.]

thanks and much appreciated for the help!


Cisco Employee

This is what is called an “empty leaf” and it can either exist or not exist.

To delete shutdown you can use the delete tag, look in the NSO Developer guide in the Templates chapter (Chapter 11 in my manual) at the “Template tag operations”, you end up with something like

For conditionals, you may want to use the syntax that is also explaind in the template chapter.



where can i find this Developer guide and also your manual?


i dont see any links and i have google searched but i cant seem to find what you are referring to.





When you install nso you get a doc subdirectory in $NCS_DIR, it contains all the manuals. There is also a $NCS_DIR/examples.ncs directory with lots of examples to help you get started.

It’s in the doc directory in your NSO installation

Hi, so if we use the delete tag to delete shutdown i.e. doing a no shutdown... how would we be able to initiate a shutdown....? do we do this via a variable?

You do it by not having the delete tag. The simplest way might be to use the tag, with delete in one branch and create in the other.

Hi thanks for your help on this so far... ok im getting close... i can now shutdown the interface using the delete tag as per the developer guide. Now i have 2 problems..


1) if i change the state of the interface back to shutdown and then try and re-run the "no shutdown" service, NSO keeps advising that there are no changes to commit so never pushes any config to no shut the interface again. If i create a brand new interface the no shutdown service always works the first time but never again... what would cause that?

2) i need to adapt the service to be able to do a shutdown, when you say create two branches with the tag delete in one and create in the other... does that mean that the service would just do the opposite of what the current state is? so if shutdown tag is already deleted it would run the create tag... and if create tag is already created, it would run the delete tag? Or do i have to build some logic of my own using Python and template variables?


thanks so much for this!