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

Use PyATS to connect to multiple devices

rasmus.elmholt
Level 7
Level 7

Hi

I am using the following python code to connect to a bunch of devices. Right now I am doing it one by one but it takes a lot of time, is there anyway to connec to multible devices at once and have it run the commands on them in parallel?

 

testbed = load("empty-testbed.yaml")
for device in allDevices:
  # Helper function to add devices to the testbed
  dev = add_device(device.name, "ios", testbed, ip_addr=device.ip)
  dev.connect(log_stdout=False, connection_timeout=10)
  stp = dev.parse('show spanning-tree detail')
  instances = stp['mstp']['mst_instances']

 

Instead of looping through the list and run the commands one by one, I just want to add all devices to the testbed and have it run the commands on all devices at once.

1 Accepted Solution

Accepted Solutions

balaji.bandi
Hall of Fame
Hall of Fame

you need to use multiprocess example :

https://pubhub.devnetcloud.com/media/pyats/docs/async/multiprocessing.html

make sure you enough process when you run same time multi processs, it may freeze CPU if you overload test with limited multi process.

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

View solution in original post

1 Reply 1

balaji.bandi
Hall of Fame
Hall of Fame

you need to use multiprocess example :

https://pubhub.devnetcloud.com/media/pyats/docs/async/multiprocessing.html

make sure you enough process when you run same time multi processs, it may freeze CPU if you overload test with limited multi process.

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help