from my_functions import napalm_conn, create_backup if __name__ == "__main__": cisco3 = my_devices.cisco3 arista1 = my_devices.arista1 devices = list() devices.append(cisco3) devices.append(arista1) for device in devices: # Creating the napalm connection device_conn = napalm_conn(device) print("#" * 50) print(f"Printing {device['hostname']} napalm connection: ") print("#" * 50) print(device_conn) # Load config change (merge) - no commit filename = f"{device['hostname']}-loopbacks" device_conn.load_merge_candidate(filename=filename) print("#" * 50) print(f"Printing {device['hostname']} DIFFS Candidate vs Running: ") print("#" * 50) print(device_conn.compare_config())
from my_devices import all_devices from my_functions import napalm_conn, create_backup from pprint import pprint napalm_objects = [] for device in all_devices: napalm_objects.append(napalm_conn(device)) # Exercise 2b for device in napalm_objects: hostname = device.hostname print("\n") print(f"{hostname}'s ARP Table:") print("-" * 40) pprint(device.get_arp_table()) print("=" * 40) # Exercise 2b for device in napalm_objects: hostname = device.hostname print() print(f"NTP Peers of {hostname}: ") try: output = device.get_ntp_peers() print(output) except: print("Unable to gather NTP peers!") print("=" * 40)
from my_devices import nxos1 from my_functions import napalm_conn, create_checkpoint nxos1_conn = napalm_conn(nxos1) # Exercise 4a print() print("Creating checkpoint for nxos1...") create_checkpoint(nxos1_conn) # Exercise 4d print() print("Loading candidate config...") nxos1_conn.load_replace_candidate(filename="nxos1.lasthop.io-checkpoint-NEW.txt") print() print("Compare diff with new config loaded:\n", "-" * 32) print(nxos1_conn.compare_config()) print("-" * 32, "\n") print("Discarding changes...") nxos1_conn.discard_config() print()
from napalm import get_network_driver from my_functions import napalm_conn, create_backup, create_checkpoint # Disable Self-signed Certificate Warnings import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning) if __name__ == "__main__": # Creating the nxos napalm connection nxos1 = my_devices.nxos1 nxos1_hostname = nxos1['hostname'] device_conn = napalm_conn(nxos1) print("#" * 50) print(f"Printing {nxos1_hostname} napalm connection: ") print("#" * 50) print(device_conn) # Creating the nxos checkpoint file filename = f"{nxos1_hostname}_checkpoint" checkpoint = create_checkpoint(device_conn, filename) # Napalm Config Replace staging
from my_devices import cisco3, arista1 from my_functions import napalm_conn, create_backup from pprint import pprint #napalm_objects = [] #for device in all_devices: # napalm_objects.append(napalm_conn(device)) cisco3_conn = napalm_conn(cisco3) arista1_conn = napalm_conn(arista1) # Exercise 3b cisco3_filename = "cisco3.lasthop.io-loopbacks.txt" arista1_filename = "arista1.lasthop.io-loopbacks.txt" print("Loading configs...") cisco3_conn.load_merge_candidate(filename=cisco3_filename) arista1_conn.load_merge_candidate(filename=arista1_filename) # Exercise 3c print() print("cisco3.lasthop.io config diff:") print("-" * 40) print(cisco3_conn.compare_config()) print() print("arista1.lasthop.io config diff:") print("-" * 40) print(arista1_conn.compare_config()) print()