-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_defs.py
144 lines (129 loc) · 5.35 KB
/
func_defs.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import paramiko
import pandas as pd
import re
def get_client(ip, username, password):
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ip, username = username, password = password)
return client
def get_switch_info(stdout):
switch_info = stdout.readline()
return switch_info
def get_swtich_name(stdout):
switch_name = stdout.readline()
return switch_name
def get_fc_interface_brief(stdout, switch_info):
interface_info = []
for line in stdout:
if 'vfc' not in line:
line = line.split()
interface_info.append(line)
if 'MDS' in switch_info:
df = pd.DataFrame(interface_info, columns =['Interface', 'VSAN', 'Admin Mode', 'Admin Trunk Mode',
'Status', 'SFP', 'Oper Mode', 'Oper Speed (Gbps)',
'Port Channel', 'Logical Type'])
else:
df = pd.DataFrame(interface_info, columns =['Interface', 'VSAN', 'Admin Mode', 'Admin Trunk Mode',
'Status', 'SFP', 'Oper Mode', 'Oper Speed (Gbps)',
'Port Channel'])
return df
def get_san_po_interface_brief(stdout, switch_info):
interface_info = []
for line in stdout:
line = line.split()
if len(line) == 6:
line.append('--')
interface_info.append(line)
if 'MDS' in switch_info:
df = pd.DataFrame(interface_info, columns =['Interface', 'VSAN', 'Admin Trunk Mode',
'Status', 'Oper Mode', 'Oper Speed (Gbps)',
'IP Address', 'Logical Type'])
else:
df = pd.DataFrame(interface_info, columns =['Interface', 'VSAN', 'Admin Trunk Mode',
'Status', 'Oper Mode', 'Oper Speed (Gbps)',
'IP Address'])
return df
def get_interface_info(stdout):
line = stdout.readline()
return line
#match = re.findall(r"\[\D*\]", line)
def print_port_internal_errors(client, intf):
print('\nPrinting port internal errors for interface ' + intf)
cmd = 'show port internal info interface {0} | grep Vsan'.format(intf)
__, stdout, __ = client.exec_command(cmd)
flag = 0
for line in stdout:
if '(up)' not in line:
flag = 1
print(line, end = '')
return flag
def activate_port_license(client, intf):
print('\nActivating port license for interface ' + intf)
client.exec_command('interface ' + intf)
client.exec_command('shutdown')
pass
def flap_port(client, intf):
print('Flapping interface ' + intf)
client.exec_command('interface ' + intf)
client.exec_command('shutdown')
client.exec_command('no shutdown')
def get_topology(stdout):
connections = []
extensionsToCheck = ['fc', 'vfc', 'vfc-po', 'san-port-channel', 'port-channel']
for line in stdout:
if any(ext in line for ext in extensionsToCheck):
line = line.split()
#TODO : Improve parsing
peer_ip, switchname = line[3].split('(')
line[3] = peer_ip
line.append( switchname.rstrip(')') )
connections.append(line)
df = pd.DataFrame(connections, columns = ['Interface', 'Peer Domain', 'Peer Interface', 'Peer IP Address', 'Switch Name'])
return df
def get_flogi_database(stdout):
database = []
extensionsToCheck = ['fc', 'vfc', 'vfc-po', 'san-port-channel', 'port-channel']
for line in stdout:
if any(ext in line for ext in extensionsToCheck):
database.append( line.split() )
df = pd.DataFrame(database, columns = ['Interface', 'VSAN', 'FCID', 'PORT NAME', 'NODE NAME'])
return df
def get_fcns_database(stdout):
database = []
regex1 = re.compile(r'0x[0-9a-f]{6}') #Checking for a valid FCID in the line
regex2 = re.compile(r'\(.*\)') #Checking if Vendor field is present
for line in stdout:
mo = re.findall(regex1, line)
if mo == None or len(line) == 1:
#Skipping insignificant lines
#Ignoring the line since it has only device-alias name
continue
else:
#TODO : Parsing the FCNS database properly
line = line.split()
if len(line) > 3:
mo = re.fullmatch(regex2, line[3]) #Checking if Vendor ID is present
if mo == None:
line.insert(3, '--')
if len(line) < 5:
line = line + ['--'] * 2
else:
if ':' in line[4]:
fc4_type, first_feature = line[4].split(':')
else:
fc4_type = line[4]
first_feature = '--'
line[4] = fc4_type
line.insert(5, first_feature)
if len(line) > 6:
line[5] = line[5] + ','.join(x for x in line[6:])
database.append(line[:6])
df = pd.DataFrame(database, columns = ['FCID', 'TYPE', 'PWWN', '(VENDOR)', 'FC4-TYPE', 'FEATURE'])
return df
"""
Extra cases to be covered
1. what if the output of the cmd is empty?
2. cover the case when switchname is of single word.
3. init/target info along with fcid for flogi(s).
"""