-
Notifications
You must be signed in to change notification settings - Fork 29
/
ipaddress.py
41 lines (32 loc) · 1.07 KB
/
ipaddress.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
import napalm
import sys
import os
def main():
# Use the appropriate network driver to connect to the device:
driver = napalm.get_network_driver('nxos')
# Connect:
device = driver(hostname='192.168.2.3', username='admin',
password='Bullf00d')
print 'Opening ...'
device.open()
config_string = """ interface Ethernet1/20
no switchport
ip address 172.16.1.1/24 """
device.load_merge_candidate(config=config_string)
# Note that the changes have not been applied yet. Before applying
# the configuration you can check the changes:
print '\nDiff:'
print device.compare_config()
# You can commit or discard the candidate changes.
choice = raw_input("\nWould you like to commit these changes? [yN]: ")
if choice == 'y':
print 'Committing ...'
device.commit_config()
else:
print 'Discarding ...'
device.discard_config()
# close the session with the device.
device.close()
print 'Done.'
if __name__ == '__main__':
main()