From 1d43c2ce2a677454713e9aa93fbb71f3516aa992 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 13 Mar 2021 17:53:55 +0100 Subject: vyos.util: add helper get_all_vrfs() The helper will return a dict in form: {'red': {'table': 1000}, 'blue': {'table': 2000}} --- python/vyos/util.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'python') 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 -- cgit v1.2.3