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

How to print a leaf-list using python

Hello,

 

I try to display the device-list of a service instance using python code. 

I tired this:

for instance in root.services.serviceName:

   print(instance.device_list)

and I got as a result this:

LeafList name=device-list tag=96950231

 

I want to display the same output as the cli when I type:

#show services serviceName serviceInstance device-list

output: device-list [ device1 device2 device3 ]

 

How can I do please?

 

1 Accepted Solution

Accepted Solutions

tcragg1
Cisco Employee
Cisco Employee

The simplest way to handle this is using the as_list() method within the Maagic API, which converts an NSO leaf-list into a python list.

for instance in root.services.serviceName:

   print(instance.device_list.as_list())

View solution in original post

1 Reply 1

tcragg1
Cisco Employee
Cisco Employee

The simplest way to handle this is using the as_list() method within the Maagic API, which converts an NSO leaf-list into a python list.

for instance in root.services.serviceName:

   print(instance.device_list.as_list())
Polls
AI-powered tools for network troubleshooting are likely to be part of everyone’s workflow sooner or later. What is the single biggest challenge or concern you see with adopting these tools in your organization?