cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
217
Views
1
Helpful
1
Replies

How to log yang data with python

Fantolino
Level 1
Level 1

I develop a tool base on NSO Action. I'd like to log the input received by the Action. I can do that with a lengthy code that access to all the data (including containers and lists) to retrive and log each data.

I wonder if a smarter way to do so exists. Maybe something that produces a printable text of a completa data tree.

 

1 Accepted Solution

Accepted Solutions

rogaglia
Cisco Employee
Cisco Employee

An Action input is a maagic.Node object.

You should be able to use the ncs.maagic.as_pyval(node) method and then print the python object as it fits you.

Relative example follows.

In [7]: node = root.ncs__devices.global_settings

In [8]: ncs.maagic.as_pyval(node)
Out[8]:
{'connect_timeout': 20,
'read_timeout': 20,
'write_timeout': 20,
'no_wait_for_lock': False,
'wait_for_lock': None,
'ssh_keep_alive': {'interval': 20, 'count': 3},
'ssh_algorithms': {'public_key': [Enum string="ssh-ed25519" value="2",
Enum string="ecdsa-sha2-nistp256" value="3",
Enum string="ecdsa-sha2-nistp384" value="4",
Enum string="ecdsa-sha2-nistp521" value="5",
Enum string="rsa-sha2-512" value="8",
Enum string="rsa-sha2-256" value="7"],
'kex': [Enum string="curve25519-sha256" value="18",
Enum string="curve25519-sha256@libssh.org" value="19",
Enum string="ecdh-sha2-nistp256" value="21",

View solution in original post

1 Reply 1

rogaglia
Cisco Employee
Cisco Employee

An Action input is a maagic.Node object.

You should be able to use the ncs.maagic.as_pyval(node) method and then print the python object as it fits you.

Relative example follows.

In [7]: node = root.ncs__devices.global_settings

In [8]: ncs.maagic.as_pyval(node)
Out[8]:
{'connect_timeout': 20,
'read_timeout': 20,
'write_timeout': 20,
'no_wait_for_lock': False,
'wait_for_lock': None,
'ssh_keep_alive': {'interval': 20, 'count': 3},
'ssh_algorithms': {'public_key': [Enum string="ssh-ed25519" value="2",
Enum string="ecdsa-sha2-nistp256" value="3",
Enum string="ecdsa-sha2-nistp384" value="4",
Enum string="ecdsa-sha2-nistp521" value="5",
Enum string="rsa-sha2-512" value="8",
Enum string="rsa-sha2-256" value="7"],
'kex': [Enum string="curve25519-sha256" value="18",
Enum string="curve25519-sha256@libssh.org" value="19",
Enum string="ecdh-sha2-nistp256" value="21",