Skip to content

Commit

Permalink
T6587: Raise an error when trying to get information about network in…
Browse files Browse the repository at this point in the history
…terfaces that don't exist
  • Loading branch information
HollyGurza committed Jul 22, 2024
1 parent 9c64df5 commit 4a58492
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/op_mode/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,39 +445,48 @@ def _format_show_counters(data: list):
print (output)
return output


def _show_raw(data: list, intf_name: str):
if intf_name is not None and len(data) <= 1:
try:
return data[0]
except IndexError:
raise vyos.opmode.UnconfiguredObject(
f"Interface {intf_name} does not exist")
else:
return data


def show(raw: bool, intf_name: typing.Optional[str],
intf_type: typing.Optional[str],
vif: bool, vrrp: bool):
data = _get_raw_data(intf_name, intf_type, vif, vrrp)
if raw:
return data
return _show_raw(data, intf_name)
return _format_show_data(data)

def show_summary(raw: bool, intf_name: typing.Optional[str],
intf_type: typing.Optional[str],
vif: bool, vrrp: bool):
data = _get_summary_data(intf_name, intf_type, vif, vrrp)
if raw:
if intf_name is not None and len(data) <= 1:
return data[0] if data else {}
else:
return data
return _show_raw(data, intf_name)
return _format_show_summary(data)

def show_summary_extended(raw: bool, intf_name: typing.Optional[str],
intf_type: typing.Optional[str],
vif: bool, vrrp: bool):
data = _get_summary_data(intf_name, intf_type, vif, vrrp)
if raw:
return data
return _show_raw(data, intf_name)
return _format_show_summary_extended(data)

def show_counters(raw: bool, intf_name: typing.Optional[str],
intf_type: typing.Optional[str],
vif: bool, vrrp: bool):
data = _get_counter_data(intf_name, intf_type, vif, vrrp)
if raw:
return data
return _show_raw(data, intf_name)
return _format_show_counters(data)

def clear_counters(intf_name: typing.Optional[str],
Expand Down

0 comments on commit 4a58492

Please sign in to comment.