Open bwks opened 6 years ago
edited from: https://stackoverflow.com/a/15144765/2520425
from netconnect.cisco import CiscoDriver
from multiprocessing.pool import ThreadPool as Pool
ios01 = '192.168.121.153'
ios02 = '192.168.121.218'
items = [ios01, ios02]
pool_size = 5
def worker(item):
commands = ['show run | i hostname']
with CiscoDriver(item, 'vagrant', 'vagrant', disable_host_key_checking=True) as dev:
result = dev.send_commands(commands)
for i in result:
print(i)
pool = Pool(pool_size)
for item in items:
pool.apply_async(worker, (item,))
pool.close()
pool.join()
Having some async helpers for dealing with large number of hosts would be a nice addition.