cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
211
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

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

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