-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcisco_nx7k_config_capture.py
executable file
·73 lines (56 loc) · 1.71 KB
/
cisco_nx7k_config_capture.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
#!/usr/bin/python3
"""
Capture Cisco Nexus 7k device configurations. Used by CA Spectrum NCM
"""
import re
import sys
from netmiko import (ConnectHandler, NetMikoAuthenticationException, NetMikoTimeoutException)
HOSTNAME = sys.argv[1]
USER = sys.argv[2]
PASS = sys.argv[3]
ENABLE = sys.argv[4]
TIMEOUT = int(sys.argv[5])
CONFIG_TYPE = sys.argv[6] if len(sys.argv) > 6 else 'running'
GLOBAL_DELAY_FACTOR = 2
SHOW_DELAY_FACTOR = 5
def main():
"""Connect to the device"""
cisco_device = {
'device_type': 'cisco_nxos',
'ip': HOSTNAME,
'username': USER,
'password': PASS,
'secret': ENABLE,
'timeout': TIMEOUT,
'global_delay_factor': GLOBAL_DELAY_FACTOR
}
try:
net_connect = ConnectHandler(**cisco_device)
except NetMikoTimeoutException:
print('Connection Timeout', file=sys.stderr)
exit(3)
except NetMikoAuthenticationException:
print('Authentication Error', file=sys.stderr)
exit(252)
except Exception:
print('Unexpected error:', sys.exc_info()[0], file=sys.stderr)
exit(1)
# Enter enable mode
try:
net_connect.enable()
except Exception:
print('Unable to enter enable mode', file=sys.stderr)
exit(252)
if CONFIG_TYPE == 'startup':
command = 'show startup-config vdc-all'
elif CONFIG_TYPE == 'running':
command = 'show running-config vdc-all'
else:
net_connect.disconnect()
print('Invalid configuration type.\nPlease specify either running or startup', file=sys.stderr)
exit(5)
output = net_connect.send_command(command)
net_connect.disconnect()
print(output)
if __name__ == '__main__':
main()