10-24-2018
01:18 PM
- last edited on
03-09-2022
11:08 PM
by
smallbusiness
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)#
Solved! Go to Solution.
10-24-2018 01:19 PM
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>
10-24-2018 01:19 PM
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>
09-04-2023 12:52 PM
Hi Roque,
Could you pls also suggest how we can mark them active in a similar way .
Thanks in Advance
09-21-2023 08:01 PM
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.
09-21-2023 07:55 PM - edited 09-22-2023 10:04 AM
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!
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