summaryrefslogtreecommitdiff
path: root/src/op_mode/vrf.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-08-23 20:14:14 +0200
committerChristian Breunig <christian@breunig.cc>2023-08-23 20:18:23 +0200
commitec23c669710a1f98fd1bd2095ffb861007374bda (patch)
tree92bdcf009a1720ea3934b38343e46d832ff975ae /src/op_mode/vrf.py
parentb88b11ee73601155a485956be80971a697a7f4d6 (diff)
downloadvyos-1x-ec23c669710a1f98fd1bd2095ffb861007374bda.tar.gz
vyos-1x-ec23c669710a1f98fd1bd2095ffb861007374bda.zip
vrf: T5428: move helpers to common vyos.utils.network module
Helper functions can and will be re-use din different code places.
Diffstat (limited to 'src/op_mode/vrf.py')
-rwxr-xr-xsrc/op_mode/vrf.py21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/op_mode/vrf.py b/src/op_mode/vrf.py
index 1f0bbbaeb..51032a4b5 100755
--- a/src/op_mode/vrf.py
+++ b/src/op_mode/vrf.py
@@ -20,11 +20,11 @@ import sys
import typing
from tabulate import tabulate
+from vyos.utils.network import get_vrf_members
from vyos.utils.process import cmd
import vyos.opmode
-
def _get_raw_data(name=None):
"""
If vrf name is not set - get all VRFs
@@ -45,21 +45,6 @@ def _get_raw_data(name=None):
return data
-def _get_vrf_members(vrf: str) -> list:
- """
- Get list of interface VRF members
- :param vrf: str
- :return: list
- """
- output = cmd(f'ip --json --brief link show master {vrf}')
- answer = json.loads(output)
- interfaces = []
- for data in answer:
- if 'ifname' in data:
- interfaces.append(data.get('ifname'))
- return interfaces if len(interfaces) > 0 else ['n/a']
-
-
def _get_formatted_output(raw_data):
data_entries = []
for vrf in raw_data:
@@ -67,7 +52,9 @@ def _get_formatted_output(raw_data):
state = vrf.get('operstate').lower()
hw_address = vrf.get('address')
flags = ','.join(vrf.get('flags')).lower()
- members = ','.join(_get_vrf_members(name))
+ tmp = get_vrf_members(name)
+ if tmp: members = ','.join(get_vrf_members(name))
+ else: members = 'n/a'
data_entries.append([name, state, hw_address, flags, members])
headers = ["Name", "State", "MAC address", "Flags", "Interfaces"]