summaryrefslogtreecommitdiff
path: root/python/vyos/config.py
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2020-06-18 21:36:39 +0300
committerDaniil Baturin <daniil@vyos.io>2020-06-18 21:36:39 +0300
commit4b5793bced424034daa944400eb8c2f198d0d0d2 (patch)
treed6f1d495a7520a43d5f14fcd20c6a0901df4eebc /python/vyos/config.py
parent025d76fb4b1641c821cd071144f12d4904634278 (diff)
downloadvyos-1x-4b5793bced424034daa944400eb8c2f198d0d0d2.tar.gz
vyos-1x-4b5793bced424034daa944400eb8c2f198d0d0d2.zip
T2614: add a key mangling option to vyos.config.get_config_dict()
Diffstat (limited to 'python/vyos/config.py')
-rw-r--r--python/vyos/config.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/python/vyos/config.py b/python/vyos/config.py
index f94293e2d..56353c322 100644
--- a/python/vyos/config.py
+++ b/python/vyos/config.py
@@ -68,6 +68,7 @@ import re
import json
import subprocess
+import vyos.util
import vyos.configtree
@@ -287,7 +288,7 @@ class Config(object):
self.__session_env = save_env
return(default)
- def get_config_dict(self, path=[], effective=False):
+ def get_config_dict(self, path=[], effective=False, key_mangling=None):
"""
Args: path (str list): Configuration tree path, can be empty
Returns: a dict representation of the config
@@ -299,6 +300,15 @@ class Config(object):
else:
config_dict = {}
+ if key_mangling:
+ if not (isinstance(key_mangling, tuple) and \
+ (len(key_mangling) == 2) and \
+ isinstance(key_mangling[0], str) and \
+ isinstance(key_mangling[1], str)):
+ raise ValueError("key_mangling must be a tuple of two strings")
+ else:
+ config_dict = vyos.util.mangle_dict_keys(config_dict, key_mangling[0], key_mangling[1])
+
return config_dict
def is_multi(self, path):