Skip to content

Instantly share code, notes, and snippets.

@kecorbin
Created March 7, 2018 23:40
Show Gist options
  • Save kecorbin/6525d4862f73f45a04400853e07137e3 to your computer and use it in GitHub Desktop.
Save kecorbin/6525d4862f73f45a04400853e07137e3 to your computer and use it in GitHub Desktop.
netmiko script to detect unsaved changes on NX-OS devices
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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment