-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnapalm.loopbacks.rollback.py
84 lines (58 loc) · 1.83 KB
/
napalm.loopbacks.rollback.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
##############################################################
# Author: Stuart Clark <[email protected]>
#
#
# Allows you to merge configurations to an IOS-XR device
# python napalm_loopbacks.rollback.py -ip [ip address]
##############################################################
from napalm import get_network_driver
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-ip", "--router_ip", help="Enter device ip address")
args = parser.parse_args()
device_ip = args.router_ip
driver = get_network_driver('iosxr')
device = driver(username='vagrant',
password='vagrant',
optional_args={'port':2221},
hostname=device_ip)
device.open()
print('Napalm Is Running........')
device.load_merge_candidate(filename='new_loopbacks.cfg')
diffs = device.compare_config()
if len(diffs) > 0:
print(diffs)
commit = input("Type COMMIT to commit the configuration or hit ENTER to abort: ")
if commit == 'COMMIT':
try:
device.commit_config()
except Exception as inst:
print('\nAn error occurred with the commit: ')
print(type(inst))
sys.exit(inst)
print()
else:
print('Config committed')
else:
sys.exit('Script aborted by user')
else:
print('No changes needed')
device.discard_config()
sys.exit()
device.close()
rollback = input("Type ROLLBACK to revert changes or hit ENTER to abort: ")
if rollback == 'ROLLBACK':
try:
device.rollback()
except Exception as inst:
print('\nAn error occurred with the rollback: ')
print(type(inst))
sys.exit(inst)
print()
else:
print('Configuration Reverted')
else:
sys.exit()
device.close()