-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdelete_loopback.py
71 lines (55 loc) · 1.84 KB
/
delete_loopback.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
#!/usr/bin/env python
"""
Code sample for use with the DevNet Sandbox Always On Open NX-OS Programmability
"""
from ncclient import manager
import sys
from lxml import etree
# Set the device variables
DEVICE = "sbx-nxos-mgmt.cisco.com"
USER = 'admin'
PASS = 'Admin_1234!'
PORT = 10000
# Ask user for loopback to configure
loopback_number = input("What Loopback interface should be removed? (Provide Id Number Only)\n")
# Verify input
try:
int(loopback_number)
except ValueError:
print("Error: Provide just the interface number. Example 101")
sys.exit()
LOOPBACK = {'loopback': 'lo{}'.format(loopback_number),
'name': 'Loopback{}'.format(loopback_number)
}
# create a main() method
def main():
"""
Main method that adds loopback interfaces and configures an IP address to
both the spine switches.
"""
remove_ip_interface = """<config>
<System xmlns="http://cisco.com/ns/yang/cisco-nx-os-device">
<intf-items>
<lb-items>
<LbRtdIf-list operation="delete">
<id>{0}</id>
</LbRtdIf-list>
</lb-items>
</intf-items>
</System>
</config>"""
with manager.connect(host=DEVICE, port=PORT, username=USER,
password=PASS, hostkey_verify=False,
device_params={'name': 'nexus'},
look_for_keys=False, allow_agent=False) as m:
# Add the loopback interface
print("\nNow removing intf {} from device {}...\n".format(
LOOPBACK['name'],
DEVICE)
)
data = remove_ip_interface.format(LOOPBACK['loopback'])
netconf_response = m.edit_config(target='running', config=data)
# Parse the XML response
print(netconf_response)
if __name__ == '__main__':
sys.exit(main())