Guest User

Untitled

a guest
Mar 17th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. from netmiko import ConnectHandler
  2.  
  3. def run_commands(host, user, pw, command, device_type="cisco_nxos"):
  4. """
  5. Executes a commands on a device
  6. :param host: IP/hostname
  7. :param user: username to login to the switch
  8. :param pw: password to login to the switch
  9. :param command: list of commands to execute on each device
  10. :param device_type: netmiko device type
  11. :return:
  12. """
  13. device = {"device_type": device_type,
  14. "ip": host.rstrip(),
  15. "username": user,
  16. "password": pw,
  17. }
  18.  
  19. session = ConnectHandler(**device)
  20. output = session.send_command(command)
  21. return output
  22.  
  23. hosts = ['1.1.1.1', '2.2.2.2']
  24.  
  25. for h in hosts:
  26. unsaved_changes = run_commands(h, 'cisco', 'cisco', 'show running-config diff')
  27. if len(unsaved_changes) > 1:
  28. print("unsaved changes on {}".format(h))
  29. # potentially save automatically, or record delta's, etc?
Add Comment
Please, Sign In to add comment