summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-07-29 18:39:40 +0200
committerGitHub <noreply@github.com>2022-07-29 18:39:40 +0200
commitb5d9ebf16f63b86013ce4e72a8023ac65fc2df8d (patch)
tree935b49a012aa6eb6b996b553e03bb2c9e464a1e5 /src
parent9310ed82e1e3800e68255b0166ff741c5e84e587 (diff)
parent97e0e0eb3ddc1645be3ee255cd7a17fa4b9c1e80 (diff)
downloadvyos-1x-b5d9ebf16f63b86013ce4e72a8023ac65fc2df8d.tar.gz
vyos-1x-b5d9ebf16f63b86013ce4e72a8023ac65fc2df8d.zip
Merge pull request #1438 from sever-sever/T4569
bridge: T4569: Extend bridge.py for op-mode
Diffstat (limited to 'src')
-rwxr-xr-xsrc/op_mode/bridge.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/op_mode/bridge.py b/src/op_mode/bridge.py
index 4ab127156..411aa06d1 100755
--- a/src/op_mode/bridge.py
+++ b/src/op_mode/bridge.py
@@ -17,6 +17,7 @@
import jmespath
import json
import sys
+import typing
from sys import exit
from tabulate import tabulate
@@ -43,6 +44,33 @@ def _get_raw_data_summary():
return data_dict
+def _get_raw_data_vlan():
+ """
+ :returns dict
+ """
+ json_data = cmd('sudo bridge --json --compressvlans vlan show')
+ data_dict = json.loads(json_data)
+ return data_dict
+
+
+def _get_raw_data_fdb(bridge):
+ """Get MAC-address for the bridge brX
+ :returns list
+ """
+ json_data = cmd(f'sudo bridge --json fdb show br {bridge}')
+ data_dict = json.loads(json_data)
+ return data_dict
+
+
+def _get_raw_data_mdb(bridge):
+ """Get MAC-address multicast gorup for the bridge brX
+ :return list
+ """
+ json_data = cmd(f'bridge --json mdb show br {bridge}')
+ data_dict = json.loads(json_data)
+ return data_dict
+
+
def _get_bridge_members(bridge: str) -> list:
"""
Get list of interface bridge members
@@ -86,6 +114,52 @@ def _get_formatted_output_summary(data):
return output
+def _get_formatted_output_vlan(data):
+ data_entries = []
+ for entry in data:
+ interface = entry.get('ifname')
+ vlans = entry.get('vlans')
+ for vlan_entry in vlans:
+ vlan = vlan_entry.get('vlan')
+ if vlan_entry.get('vlanEnd'):
+ vlan_end = vlan_entry.get('vlanEnd')
+ vlan = f'{vlan}-{vlan_end}'
+ flags = ', '.join(vlan_entry.get('flags')).lower()
+ data_entries.append([interface, vlan, flags])
+
+ headers = ["Interface", "Vlan", "Flags"]
+ output = tabulate(data_entries, headers)
+ return output
+
+
+def _get_formatted_output_fdb(data):
+ data_entries = []
+ for entry in data:
+ interface = entry.get('ifname')
+ mac = entry.get('mac')
+ state = entry.get('state')
+ flags = ','.join(entry['flags'])
+ data_entries.append([interface, mac, state, flags])
+
+ headers = ["Interface", "Mac address", "State", "Flags"]
+ output = tabulate(data_entries, headers, numalign="left")
+ return output
+
+
+def _get_formatted_output_mdb(data):
+ data_entries = []
+ for entry in data:
+ for mdb_entry in entry['mdb']:
+ interface = mdb_entry.get('port')
+ group = mdb_entry.get('grp')
+ state = mdb_entry.get('state')
+ flags = ','.join(mdb_entry.get('flags'))
+ data_entries.append([interface, group, state, flags])
+ headers = ["Interface", "Group", "State", "Flags"]
+ output = tabulate(data_entries, headers)
+ return output
+
+
def show(raw: bool):
bridge_data = _get_raw_data_summary()
if raw:
@@ -94,6 +168,30 @@ def show(raw: bool):
return _get_formatted_output_summary(bridge_data)
+def show_vlan(raw: bool):
+ bridge_vlan = _get_raw_data_vlan()
+ if raw:
+ return bridge_vlan
+ else:
+ return _get_formatted_output_vlan(bridge_vlan)
+
+
+def show_fdb(raw: bool, interface: str):
+ fdb_data = _get_raw_data_fdb(interface)
+ if raw:
+ return fdb_data
+ else:
+ return _get_formatted_output_fdb(fdb_data)
+
+
+def show_mdb(raw: bool, interface: str):
+ mdb_data = _get_raw_data_mdb(interface)
+ if raw:
+ return mdb_data
+ else:
+ return _get_formatted_output_mdb(mdb_data)
+
+
if __name__ == '__main__':
try:
res = vyos.opmode.run(sys.modules[__name__])