Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from netmiko import ConnectHandler
- def run_commands(host, user, pw, command, device_type="cisco_nxos"):
- """
- Executes a commands on a device
- :param host: IP/hostname
- :param user: username to login to the switch
- :param pw: password to login to the switch
- :param command: list of commands to execute on each device
- :param device_type: netmiko device type
- :return:
- """
- device = {"device_type": device_type,
- "ip": host.rstrip(),
- "username": user,
- "password": pw,
- }
- session = ConnectHandler(**device)
- output = session.send_command(command)
- return output
- hosts = ['1.1.1.1', '2.2.2.2']
- for h in hosts:
- unsaved_changes = run_commands(h, 'cisco', 'cisco', 'show running-config diff')
- if len(unsaved_changes) > 1:
- print("unsaved changes on {}".format(h))
- # potentially save automatically, or record delta's, etc?
Add Comment
Please, Sign In to add comment