From aac75107bc9988ecb599265da029827ff09bf713 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Mon, 28 Oct 2019 15:01:52 +0100 Subject: Add a function for retrieving config dicts. --- python/vyos/config.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/python/vyos/config.py b/python/vyos/config.py index 5c2fc7285..13b2c107e 100644 --- a/python/vyos/config.py +++ b/python/vyos/config.py @@ -65,6 +65,7 @@ In operational mode, all functions return values from the running config. import os import re +import json import subprocess import vyos.configtree @@ -225,7 +226,7 @@ class Config(object): def show_config(self, path=[], default=None): """ Args: - path (str): Configuration tree path, or empty + path (str list): Configuration tree path, or empty default (str): Default value to return Returns: @@ -239,6 +240,16 @@ class Config(object): except VyOSError: return(default) + def get_config_dict(self, path=[], effective=False): + """ + Args: path (str list): Configuration tree path, can be empty + Returns: a dict representation of the config + """ + res = self.show_config(self._make_path(path)) + config_tree = vyos.configtree.ConfigTree(res) + config_dict = json.loads(config_tree.to_json()) + return config_dict + def is_multi(self, path): """ Args: -- cgit v1.2.3