diff options
author | Christian Breunig <christian@breunig.cc> | 2024-07-22 22:00:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-22 22:00:46 +0200 |
commit | 150d7c8c4d400479eac1f30da9c6f3eaa3503f28 (patch) | |
tree | da1b9c3eedda0419ed76e29330102a2ed6ab29e6 /src/op_mode | |
parent | 1f5cb9d01536f2005f80e94845972e90dfcdd0fd (diff) | |
parent | 4a58492fccfdc2043af5091150b8823ec7169507 (diff) | |
download | vyos-1x-150d7c8c4d400479eac1f30da9c6f3eaa3503f28.tar.gz vyos-1x-150d7c8c4d400479eac1f30da9c6f3eaa3503f28.zip |
Merge pull request #3840 from HollyGurza/T6589
T6589: Return a dict when querying information about a single interface
Diffstat (limited to 'src/op_mode')
-rwxr-xr-x | src/op_mode/interfaces.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/op_mode/interfaces.py b/src/op_mode/interfaces.py index 14ffdca9f..e7afc4caa 100755 --- a/src/op_mode/interfaces.py +++ b/src/op_mode/interfaces.py @@ -445,12 +445,24 @@ 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], @@ -458,7 +470,7 @@ def show_summary(raw: bool, intf_name: 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], @@ -466,7 +478,7 @@ def show_summary_extended(raw: bool, intf_name: 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], @@ -474,7 +486,7 @@ def show_counters(raw: bool, intf_name: 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], |