-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnapalm_replace.loopbacks.py
More file actions
60 lines (43 loc) · 1.41 KB
/
napalm_replace.loopbacks.py
File metadata and controls
60 lines (43 loc) · 1.41 KB
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
#!/usr/bin/env python
##############################################################
# Author: Stuart Clark <stuaclar@cisco.com>
#
#
# Allows you to replace configurations to an IOS-XR device
# python napalm.replace.loopbacks.py -ip [ip address]
##############################################################
from napalm import get_network_driver
import argparse
import sys
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_replace_candidate(filename='replace_loopbacks.conf')
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()
device.close()