summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkhramshinr <khramshinr@gmail.com>2024-07-22 21:47:37 +0600
committerkhramshinr <khramshinr@gmail.com>2024-07-22 22:00:40 +0600
commit4a58492fccfdc2043af5091150b8823ec7169507 (patch)
tree304faa50436791dc331e8cf49fea8819e4bf66a7 /src
parent9c64df545f2ba21a6e2cda29d132389c71fac144 (diff)
downloadvyos-1x-4a58492fccfdc2043af5091150b8823ec7169507.tar.gz
vyos-1x-4a58492fccfdc2043af5091150b8823ec7169507.zip
T6587: Raise an error when trying to get information about network interfaces that don't exist
Diffstat (limited to 'src')
-rwxr-xr-xsrc/op_mode/interfaces.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/op_mode/interfaces.py b/src/op_mode/interfaces.py
index 50199eed5..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,10 +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:
- 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],
@@ -469,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],
@@ -477,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],