Skip to content

Commit

Permalink
Merge pull request vyos#1511 from jack9603301/T4659
Browse files Browse the repository at this point in the history
T4659: op-mode: Display bridge interface details
  • Loading branch information
c-po authored Jul 22, 2023
2 parents e4f3bcc + a684ab2 commit 20b7155
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
12 changes: 12 additions & 0 deletions op-mode-definitions/show-bridge.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@
</properties>
<command>${vyos_op_scripts_dir}/bridge.py show_fdb --interface=$3</command>
</leafNode>
<leafNode name="detail">
<properties>
<help>Display bridge interface details</help>
</properties>
<command>${vyos_op_scripts_dir}/bridge.py show_detail --interface=$3</command>
</leafNode>
<leafNode name="nexthop-group">
<properties>
<help>Display bridge interface nexthop-group</help>
</properties>
<command>${vyos_op_scripts_dir}/bridge.py show_detail --nexthop_group --interface=$3</command>
</leafNode>
</children>
</tagNode>
</children>
Expand Down
32 changes: 31 additions & 1 deletion src/op_mode/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from vyos.utils.process import cmd
from vyos.utils.process import rc_cmd
from vyos.utils.process import call
from vyos.utils.dict import dict_search

import vyos.opmode
Expand Down Expand Up @@ -129,7 +130,8 @@ def _get_formatted_output_vlan(data):
if vlan_entry.get('vlanEnd'):
vlan_end = vlan_entry.get('vlanEnd')
vlan = f'{vlan}-{vlan_end}'
flags = ', '.join(vlan_entry.get('flags')).lower()
flags_raw = vlan_entry.get('flags')
flags = ', '.join(flags_raw if isinstance(flags_raw,list) else "").lower()
data_entries.append([interface, vlan, flags])

headers = ["Interface", "Vlan", "Flags"]
Expand Down Expand Up @@ -164,6 +166,23 @@ def _get_formatted_output_mdb(data):
output = tabulate(data_entries, headers)
return output

def _get_bridge_detail(iface):
"""Get interface detail statistics"""
return call(f'vtysh -c "show interface {iface}"')

def _get_bridge_detail_nexthop_group(iface):
"""Get interface detail nexthop_group statistics"""
return call(f'vtysh -c "show interface {iface} nexthop-group"')

def _get_bridge_detail_nexthop_group_raw(iface):
out = cmd(f'vtysh -c "show interface {iface} nexthop-group"')
return out

def _get_bridge_detail_raw(iface):
"""Get interface detail json statistics"""
data = cmd(f'vtysh -c "show interface {iface} json"')
data_dict = json.loads(data)
return data_dict

def show(raw: bool):
bridge_data = _get_raw_data_summary()
Expand Down Expand Up @@ -196,6 +215,17 @@ def show_mdb(raw: bool, interface: str):
else:
return _get_formatted_output_mdb(mdb_data)

def show_detail(raw: bool, nexthop_group: typing.Optional[bool], interface: str):
if raw:
if nexthop_group:
return _get_bridge_detail_nexthop_group_raw(interface)
else:
return _get_bridge_detail_raw(interface)
else:
if nexthop_group:
return _get_bridge_detail_nexthop_group(interface)
else:
return _get_bridge_detail(interface)

if __name__ == '__main__':
try:
Expand Down

0 comments on commit 20b7155

Please sign in to comment.