Created
March 7, 2018 23:40
-
-
Save kecorbin/6525d4862f73f45a04400853e07137e3 to your computer and use it in GitHub Desktop.
netmiko script to detect unsaved changes on NX-OS devices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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