06-04-2021 12:20 PM
When I try to get junos configuration using nso cli, it works:
admin@ncs# devices device vmx1 rpc rpc-get-configuration get-configuration config-text | display xml
<configuration-text xmlns='_juniper-junos-nc-4.6:juniper-junos-nc-4.6#urn:juniper-rpc'>## Last changed: 2021-06-02 22:48:40 UTC
version 18.2R1.9;
system {
root-authentication {
encrypted-password "xyz";
}
host-name VMX1;
services {
ssh {
root-login allow;
}
...
However, when i try to do the same from python, i found that i need to add empty leaf "config-text", otherwise the configuration is not returned.
I tried setting the leaf to "", but i get error that this element cannot be set.
How can i retrieve junos config from python ?
In [142]: action = device.rpc.jrpc__rpc_get_configuration.get_configuration
In [143]: input = action.get_input()
In [144]: input.config_text
Out[144]: Empty leaf name=config-text tag=249964986 cached=False
In [145]: print(action(input).configuration_text)
None
In [146]: input.config_text=''
---------------------------------------------------------------------------
MaagicError Traceback (most recent call last)
<ipython-input-146-9f18c6955582> in <module>
----> 1 input.config_text=''
/root/nso5.3/src/ncs/pyapi/ncs/maagic.py in __setattr__(self, name, value)
486 child.set_value(value)
487 else:
--> 488 raise MaagicError("Node type does not support assignment")
489 else:
490 raise MaagicError("Node has no attribute '%s'" % (name,))
MaagicError: Node type does not support assignment
In [147]:
Solved! Go to Solution.
06-04-2021 12:56 PM
06-04-2021 12:56 PM
06-04-2021 01:04 PM - edited 06-04-2021 01:06 PM
Thanks!
Is there any way to filter the output for something like "show configuration protocols isis" only, instead of the full config ?
Or a way to retrieve the config in XML format, instead of free text ?
06-04-2021 01:47 PM
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: