cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1334
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())
Getting Started

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: