diff options
Diffstat (limited to 'python/vyos/config.py')
-rw-r--r-- | python/vyos/config.py | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/python/vyos/config.py b/python/vyos/config.py index 56353c322..780b48a7b 100644 --- a/python/vyos/config.py +++ b/python/vyos/config.py @@ -71,7 +71,6 @@ import subprocess import vyos.util import vyos.configtree - class VyOSError(Exception): """ Raised on config access errors, most commonly if the type of a config tree node @@ -288,17 +287,26 @@ class Config(object): self.__session_env = save_env return(default) - def get_config_dict(self, path=[], effective=False, key_mangling=None): + def get_config_dict(self, path=[], effective=False, key_mangling=None, get_first_key=False): """ - Args: path (str list): Configuration tree path, can be empty - Returns: a dict representation of the config + Args: + path (str list): Configuration tree path, can be empty + effective=False: effective or session config + key_mangling=None: mangle dict keys according to regex and replacement + get_first_key=False: if k = path[:-1], return sub-dict d[k] instead of {k: d[k]} + + Returns: a dict representation of the config under path """ - res = self.show_config(self._make_path(path), effective=effective) - if res: - config_tree = vyos.configtree.ConfigTree(res) - config_dict = json.loads(config_tree.to_json()) + config_dict = {} + + if effective: + if self._running_config: + config_dict = json.loads((self._running_config).to_json()) else: - config_dict = {} + if self._session_config: + config_dict = json.loads((self._session_config).to_json()) + + config_dict = vyos.util.get_sub_dict(config_dict, self._make_path(path), get_first_key) if key_mangling: if not (isinstance(key_mangling, tuple) and \ |