Skip to content

Instantly share code, notes, and snippets.

@YUChoe
Last active June 30, 2020 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YUChoe/ba29594ca181a33d3fb1447274bd083a to your computer and use it in GitHub Desktop.
Save YUChoe/ba29594ca181a33d3fb1447274bd083a to your computer and use it in GitHub Desktop.
#!/usr/bin/python
exclide_keys = ['Ethernet Channel Bonding Driver', 'Primary Slave', 'Up Delay (ms)',
'Down Delay (ms)', 'Slave queue ID', 'Duplex', 'Speed', 'Link Failure Count',
'Bonding Mode', 'MII Polling Interval (ms)']
def print_bond_status(dev):
md = {}
d = {}
with open("/proc/net/bonding/{}".format(dev)) as fp:
for row in fp.readlines():
row = row.strip()
if row:
_key, _value = row.split(': ')
if _key in exclide_keys: continue
if _key == 'Currently Active Slave':
md['current_slave_dev'] = _value
if _key == 'Currently Active Slave':
md['active'] = _value
continue
if _key == 'Slave Interface':
sdev = _value
d[sdev] = {}
continue
if _key == 'MII Status':
if 'sdev' in vars():
d[sdev][_key] = _value
else:
md[_key] = _value
print("Master Status Active Interface Link")
print("---------------------------------------")
isFirstRow = True
for sdev in d:
act = '*' if md['current_slave_dev'] == sdev else ' '
if isFirstRow:
print("{:6} {:6} {:6} {:9} {:4}".format(dev, md['MII Status'], act, sdev, d[sdev]['MII Status']))
isFirstRow = False
else:
print("{:6} {:6} {:6} {:9} {:4}".format('', '', act, sdev, d[sdev]['MII Status']))
print('')
for dev in ['eth0', 'eth1', 'ha']:
print_bond_status(dev)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment