cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1555
Views
0
Helpful
4
Replies

Junos deactive using Python

rogaglia
Cisco Employee
Cisco Employee

Hi,

In a junos device, you can use "deactivate" to disable a given configuration leaf.

NSO handles "deactivate" by adding the XML attribute "inactive".   I can do this in CLI but how can I do it in python?

 

Thanks,

Roque

 

CLI output:

 

admin@ncs(config)# deactivate devices device pe-j1 config junos:configuration system host-name
admin@ncs(config)# commit dry-run outformat xml
result-xml {
    local-node {
        data <devices xmlns="http://tail-f.com/ns/ncs">
               <device>
                 <name>pe-j1</name>
                 <config>
                   <configuration xmlns="http://xml.juniper.net/xnm/1.1/xnm">
                     <system>
                       <host-name novalue="true"
                                  inactive="inactive"/>
                     </system>NSO Developer Hub Discussions, Developer
                   </configuration>
                 </config>
               </device>
             </devices>
    }
}
admin@ncs(config)#
1 Accepted Solution

Accepted Solutions

rogaglia
Cisco Employee
Cisco Employee

Here is the answer to my own question:

 

In [22]: trans.set_attr(attr=0x00000000,v=_ncs.Value(True),keypath="/devices/device{pe-j0}/config/junos:configuration/system/ntp/server{10.30.10.120}")

In [24]: trans.compare()
Diff set:
kp=/ncs:devices/device{pe-j0}, op=MOP_MODIFIED, oldv=None, newv=None
kp=/ncs:devices/device{pe-j0}/config/junos:configuration/system/ntp/server{10.30.10.120}, op=MOP_MODIFIED, oldv=None, newv=None
kp=/ncs:devices/device{pe-j0}/config/junos:configuration/system/ntp/server{10.30.10.120}, op=MOP_ATTR_SET, oldv=None, newv=(<_ncs.Value type=C_UINT32(12) value='0'>, <_ncs.Value type=C_BOOL(17) value='true'>)

In [25]: trans.apply()

In [26]:

Confirmation:

admin@ncs(config)# show full-configuration devices device pe-j0 config junos:configuration system ntp | display xml
<config xmlns="http://tail-f.com/ns/config/1.0">
  <devices xmlns="http://tail-f.com/ns/ncs">
  <device>
    <name>pe-j0</name>
      <config>
      <configuration xmlns="http://xml.juniper.net/xnm/1.1/xnm">
      <system>
      <ntp>
        <server>
          <name>10.20.10.110</name>
        </server>
        <server inactive="inactive">
          <name>10.30.10.120</name>
        </server>
      </ntp>
      </system>
      </configuration>
      </config>
  </device>
  </devices>
</config>

View solution in original post

4 Replies 4

rogaglia
Cisco Employee
Cisco Employee

Here is the answer to my own question:

 

In [22]: trans.set_attr(attr=0x00000000,v=_ncs.Value(True),keypath="/devices/device{pe-j0}/config/junos:configuration/system/ntp/server{10.30.10.120}")

In [24]: trans.compare()
Diff set:
kp=/ncs:devices/device{pe-j0}, op=MOP_MODIFIED, oldv=None, newv=None
kp=/ncs:devices/device{pe-j0}/config/junos:configuration/system/ntp/server{10.30.10.120}, op=MOP_MODIFIED, oldv=None, newv=None
kp=/ncs:devices/device{pe-j0}/config/junos:configuration/system/ntp/server{10.30.10.120}, op=MOP_ATTR_SET, oldv=None, newv=(<_ncs.Value type=C_UINT32(12) value='0'>, <_ncs.Value type=C_BOOL(17) value='true'>)

In [25]: trans.apply()

In [26]:

Confirmation:

admin@ncs(config)# show full-configuration devices device pe-j0 config junos:configuration system ntp | display xml
<config xmlns="http://tail-f.com/ns/config/1.0">
  <devices xmlns="http://tail-f.com/ns/ncs">
  <device>
    <name>pe-j0</name>
      <config>
      <configuration xmlns="http://xml.juniper.net/xnm/1.1/xnm">
      <system>
      <ntp>
        <server>
          <name>10.20.10.110</name>
        </server>
        <server inactive="inactive">
          <name>10.30.10.120</name>
        </server>
      </ntp>
      </system>
      </configuration>
      </config>
  </device>
  </devices>
</config>

Hi Roque,

Could you pls also suggest how we can mark them active in a similar way .

Thanks in Advance

Hello @sayeali,

Have you tried the following?

trans.set_attr(attr=0x00000000,v=_ncs.Value(False),keypath="/devices/device{pe-j0}/config/junos:configuration/system/ntp/server{10.30.10.120}")

My assumption is that if you change the "_ncs.Value()" to "False", the attribute will be removed.

Hello @rogaglia,

I see your command above:

 

trans.set_attr(attr=0x00000000,v=_ncs.Value(True),keypath="/devices/device{pe-j0}/config/junos:configuration/system/ntp/server{10.30.10.120}")

 

However, I'm not familiar with this command and I don't see an import command.
Is there a specific package or module that you used?

Thanks!