Repository navigation
Expand file tree
/
Copy pathmlag_data_compare.py
More file actions
108 lines (91 loc) · 4.21 KB
/
Copy pathmlag_data_compare.py
File metadata and controls
108 lines (91 loc) · 4.21 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
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
#!/usr/bin/env python3
import json
from exsh import clicmd
def get_mlag_peers():
mlagpeerRslt = json.loads(clicmd('debug cfgmgr show next vsm.mLagPeer', True))
mlag_peer = []
dup = False
for peerRow in mlagpeerRslt['data']:
for peer in mlag_peer:
if peer['peerName'] == peerRow['peerName'] or peerRow['peerName'] == None:
dup = True
if dup is True:
pass
else:
mlag_peer.append({'peerName': str(peerRow['peerName']) or '',
'peerIpAddr': str(peerRow['peerIpAddr']) or '',
'localIpAddr': str(peerRow['localIpAddr']) or '',
'vlan': str(peerRow['vlan']) or '' })
return mlag_peer
def get_mlag_ports():
mlagportRslt = json.loads(clicmd('debug cfgmgr show next vsm.mLagPort', True))
mlag_ports = []
dup = False
for mportRow in mlagportRslt['data']:
for peer in mlag_ports:
if mportRow['peerName'] == None:
dup = True
if peer['peerName'] == mportRow['peerName'] and peer['idx'] == mportRow['idx']:
dup = True
if dup is True:
pass
else:
mlag_ports.append({'peerName': str(mportRow['peerName']) or '',
'idx': str(mportRow['idx']) or '',
'port': str(mportRow['port']) or '',
'localportstate': str(mportRow['lclLinkState']) or '',
'remoteportstate': str(mportRow['rmtLinkState']) or ''})
return mlag_ports
def get_port_vlans(port):
vlanRslt = json.loads(clicmd('debug cfgmgr show next vlan.show_ports_info_detail_vlans port={0} vlanIfInstance=None'.format(port), True))
port_data = []
for vlanRow in vlanRslt['data']:
port_data.append({'VlanName': str(vlanRow['vlanName']).lower() or '',
'VlanId': str(vlanRow['vlanId']) or '',
'tag' : str(vlanRow['tagStatus']) or ''})
return port_data
def get_port_vlan_list(port):
vlanRslt = json.loads(clicmd('debug cfgmgr show next vlan.show_ports_info_detail_vlans port={0} vlanIfInstance=None'.format(port), True))
port_data = []
for vlanRow in vlanRslt['data']:
port_data.append(str(vlanRow['vlanName']) or '')
return port_data
def get_vlan_ports(vlan):
vlanportsRslt = json.loads(clicmd('debug cfgmgr show one vlan.vlanPort vlanName={0}'.format(vlan), True))
return ({'untagged' : str(vlanportsRslt['data'][0]['untaggedPorts']) or '', 'tagged' : str(vlanportsRslt['data'][0]['taggedPorts']) or ''})
peer_info = get_mlag_peers()
def main():
peer_info = get_mlag_peers()
mports = get_mlag_ports()
isc_port = ''
if len(peer_info) == 1:
peer_info = peer_info[0]
port_check = get_vlan_ports(peer_info['vlan'])
if port_check['untagged'] == 'None':
isc_port = port_check['tagged']
if port_check['tagged'] == 'None':
isc_port = port_check['untagged']
print("###############################")
print("MLAG peer is {0}".format(peer_info[0]['peerName'] if isinstance(peer_info, list) else peer_info['peerName']))
print("###############################")
print("")
print("KEY:")
print("VLAN Name : VLAN ID : Tag 0/1")
print("")
print("------------------------------------")
print("ISC port {0}".format(isc_port))
print("------------------------------------")
for isc_vlans in get_port_vlans(isc_port):
print("{0} : {1} : {2}".format(isc_vlans['VlanName'], isc_vlans['VlanId'], isc_vlans['tag']))
print("")
for port in mports:
print("------------------------------------")
print("MLAG Port {0}, ID: {1}, Rpeer : {2}".format(port['port'], port['idx'], port['remoteportstate']))
print("------------------------------------")
for mvlan in get_port_vlans(port['port']):
print("{0} : {1} : {2}".format(mvlan['VlanName'], mvlan['VlanId'], mvlan['tag']))
print("")
if len(peer_info) > 1:
print("This script does not support two MLAG peers.")
else:
main()