summaryrefslogtreecommitdiff
path: root/src/op_mode/vrf.py
diff options
context:
space:
mode:
authorViacheslav Hletenko <v.gletenko@vyos.io>2022-07-29 13:57:33 +0000
committerViacheslav Hletenko <v.gletenko@vyos.io>2022-07-29 14:02:32 +0000
commit5e7120a00278671a73e9762a5da5e6f6961a387d (patch)
tree6f5ab0bb150c8f9cf6020857edf1ba4e772ad52f /src/op_mode/vrf.py
parentb33de0bac8172f3571ffc6d46b87de0c906e1b48 (diff)
downloadvyos-1x-5e7120a00278671a73e9762a5da5e6f6961a387d.tar.gz
vyos-1x-5e7120a00278671a73e9762a5da5e6f6961a387d.zip
vrf: T4562: Rewrite show vrf name xxx delete old script
Add option "--name" for function "show" to get required VRF name Delete old script "show_vrf.py"
Diffstat (limited to 'src/op_mode/vrf.py')
-rwxr-xr-xsrc/op_mode/vrf.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/op_mode/vrf.py b/src/op_mode/vrf.py
index 63d9b5ee5..f86516786 100755
--- a/src/op_mode/vrf.py
+++ b/src/op_mode/vrf.py
@@ -16,6 +16,7 @@
import json
import sys
+import typing
from tabulate import tabulate
from vyos.util import cmd
@@ -23,12 +24,23 @@ from vyos.util import cmd
import vyos.opmode
-def _get_raw_data():
+def _get_raw_data(name=None):
"""
- :return: list
+ If vrf name is not set - get all VRFs
+ If vrf name is set - get only this name data
+ If vrf name set and not found - return []
"""
output = cmd('sudo ip --json --brief link show type vrf')
data = json.loads(output)
+ if not data:
+ return []
+ if name:
+ is_vrf_exists = True if [vrf for vrf in data if vrf.get('ifname') == name] else False
+ if is_vrf_exists:
+ output = cmd(f'sudo ip --json --brief link show dev {name}')
+ data = json.loads(output)
+ return data
+ return []
return data
@@ -62,8 +74,8 @@ def _get_formatted_output(raw_data):
return output
-def show(raw: bool):
- vrf_data = _get_raw_data()
+def show(raw: bool, name: typing.Optional[str]):
+ vrf_data = _get_raw_data(name=name)
if raw:
return vrf_data
else: