Advertisement
Guest User

Untitled

a guest
Jan 9th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. import paramiko
  2. import time
  3. auth_username = 'x'
  4. auth_password = 'x'
  5. devices = {$
  6.     'Anlin-AH-16' : {
  7.          'hostname'  : '192.168.254.185',
  8.          'port'      : 22,
  9.          'username'  : auth_username,
  10.          'password'  : auth_password
  11.     },
  12.     'Anlin-AH-14' : {$
  13.         'hostname'  : '192.168.254.183',
  14.          'port'      : 22,
  15.           'username'  : auth_username,
  16.           'password'  : auth_password
  17.         }
  18. }
  19. def connect_to(device_name, device_data):
  20.       ssh = paramiko.SSHClient()
  21.       ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  22.       ssh.connect(**device_data)
  23.       remote_conn = ssh.invoke_shell()
  24.       print('system is rebooting')
  25.       remote_conn.send('reboot')
  26.       time.sleep(2)
  27.       remote_conn.send('y')
  28.  
  29. for device_name, device_data in devices.items():
  30.   connect_to(device_name, device_data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement