Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T6589: Return a dict when querying information about a single interface #3840

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/op_mode/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,36 +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:
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
Loading