summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-08-25 19:26:00 +0200
committerGitHub <noreply@github.com>2022-08-25 19:26:00 +0200
commite8dc2c731697c7c76c75fa7844edde52dc0ff76b (patch)
tree34819fbe9e13e929838a1148d5987b9da1e3abd5 /python
parent73be77ec42d06a369974bfb1255839164f73c276 (diff)
parentdcf89afba457fd4e4d4f764484f329c19d8ed554 (diff)
downloadvyos-1x-e8dc2c731697c7c76c75fa7844edde52dc0ff76b.tar.gz
vyos-1x-e8dc2c731697c7c76c75fa7844edde52dc0ff76b.zip
Merge pull request #1458 from sever-sever/T4594
ipsec: T4594: Rewrite op-mode 'show vpn ipsec sa' to the new format
Diffstat (limited to 'python')
-rw-r--r--python/vyos/util.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index c1459f02a..325b630bc 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -823,6 +823,32 @@ def dict_search_recursive(dict_object, key, path=[]):
for x in dict_search_recursive(j, key, new_path):
yield x
+def convert_data(data):
+ """Convert multiple types of data to types usable in CLI
+
+ Args:
+ data (str | bytes | list | OrderedDict): input data
+
+ Returns:
+ str | list | dict: converted data
+ """
+ from collections import OrderedDict
+
+ if isinstance(data, str):
+ return data
+ if isinstance(data, bytes):
+ return data.decode()
+ if isinstance(data, list):
+ list_tmp = []
+ for item in data:
+ list_tmp.append(convert_data(item))
+ return list_tmp
+ if isinstance(data, OrderedDict):
+ dict_tmp = {}
+ for key, value in data.items():
+ dict_tmp[key] = convert_data(value)
+ return dict_tmp
+
def get_bridge_fdb(interface):
""" Returns the forwarding database entries for a given interface """
if not os.path.exists(f'/sys/class/net/{interface}'):