summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-03-13 17:53:55 +0100
committerChristian Poessinger <christian@poessinger.com>2021-03-14 11:09:57 +0100
commit1d43c2ce2a677454713e9aa93fbb71f3516aa992 (patch)
treeed8576c8d63d57a3ae863839bd71c7d6eaab46d5
parentee2dfee43f8319726c2225a5ad2367d936ec3176 (diff)
downloadvyos-1x-1d43c2ce2a677454713e9aa93fbb71f3516aa992.tar.gz
vyos-1x-1d43c2ce2a677454713e9aa93fbb71f3516aa992.zip
vyos.util: add helper get_all_vrfs()
The helper will return a dict in form: {'red': {'table': 1000}, 'blue': {'table': 2000}}
-rw-r--r--python/vyos/util.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 17a7dda91..837faa632 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -655,3 +655,16 @@ def get_json_iface_options(interface):
from json import loads
tmp = loads(cmd(f'ip -d -j link show {interface}'))[0]
return tmp
+
+def get_all_vrfs():
+ """ Return a dictionary of all system wide known VRF instances """
+ from json import loads
+ tmp = loads(cmd('ip -j vrf list'))
+ # Result is of type [{"name":"red","table":1000},{"name":"blue","table":2000}]
+ # so we will re-arrange it to a more nicer representation:
+ # {'red': {'table': 1000}, 'blue': {'table': 2000}}
+ data = {}
+ for entry in tmp:
+ name = entry.pop('name')
+ data[name] = entry
+ return data