Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def execute(device, cmd):
- from netmiko import ConnectHandler
- net_connect = ConnectHandler(**device) # **kwargs, un dictionar de lungime varaibila pasat ca arg
- net_connect.enable()
- output = net_connect.send_command(cmd)
- print(output)
- if __name__ == '__main__':
- import threading
- import time
- print('MAIN ' * 30)
- cisco_device1 = {'device_type': 'cisco_ios', 'ip': '192.168.122.100', 'username': 'u1', 'password': 'cisco',
- 'port': 22,
- 'secret': 'cisco', 'verbose': True}
- cisco_device2 = {'device_type': 'cisco_ios', 'ip': '192.168.122.200', 'username': 'u1', 'password': 'cisco',
- 'port': 22,
- 'secret': 'cisco', 'verbose': True}
- devices = []
- devices.append(cisco_device1)
- devices.append(cisco_device2)
- print(devices)
- start = time.time()
- execute(cisco_device1, 'sh run')
- execute(cisco_device2, 'sh run')
- end = time.time()
- normal_time = end - start
- threads = []
- start = time.time()
- for device in devices:
- th = threading.Thread(target=execute,
- args=(
- device, 'sh run')) # virgula e pentru a-l pacacli ca e tuplu t = (s,) type(t) = touple
- threads.append(th)
- for th in threads:
- th.start()
- for th in threads:
- th.join()
- end = time.time()
- thread_time = end - start
- print(f'Normal vs thread: {normal_time} vs. {thread_time}')
- print('MAIN ' * 30)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement