From df231744b98202ec5fbcd236e795df7399747a0e Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Thu, 23 May 2019 07:38:54 -0500 Subject: T1397: Rewrite the config merge script Add vyos.config.show_config to show working configuration. Add vyos.remote.get_config_remote() for obtaining remote config files. --- python/vyos/config.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'python/vyos/config.py') diff --git a/python/vyos/config.py b/python/vyos/config.py index bcf04225b..9a5125eb9 100644 --- a/python/vyos/config.py +++ b/python/vyos/config.py @@ -169,6 +169,21 @@ class Config(object): except VyOSError: return False + def show_config(self, path='', default=None): + """ + Args: + path (str): Configuration tree path, or empty + default (str): Default value to return + + Returns: + str: working configuration + """ + try: + out = self._run(self._make_command('showConfig', path)) + return out + except VyOSError: + return(default) + def is_multi(self, path): """ Args: -- cgit v1.2.3 From 29df430906c830146e6cc9b7edda9be836a01837 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Thu, 13 Jun 2019 03:10:08 +0200 Subject: T1431: make it possible to obtain session environment and run vyos.config functions under it. This is required for programs running outside a CLI session, like the future API daemon. --- python/vyos/config.py | 11 +++++++++-- python/vyos/configsession.py | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'python/vyos/config.py') diff --git a/python/vyos/config.py b/python/vyos/config.py index 9a5125eb9..96e9631e0 100644 --- a/python/vyos/config.py +++ b/python/vyos/config.py @@ -87,9 +87,13 @@ class Config(object): the only state it keeps is relative *config path* for convenient access to config subtrees. """ - def __init__(self): + def __init__(self, session_env=None): self._cli_shell_api = "/bin/cli-shell-api" self._level = "" + if session_env: + self.__session_env = session_env + else: + self.__session_env = None def _make_command(self, op, path): args = path.split() @@ -97,7 +101,10 @@ class Config(object): return cmd def _run(self, cmd): - p = subprocess.Popen(cmd, stdout=subprocess.PIPE) + if self.__session_env: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=self.__session_env) + else: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE) out = p.stdout.read() p.wait() if p.returncode != 0: diff --git a/python/vyos/configsession.py b/python/vyos/configsession.py index b989d3be5..c84d80a77 100644 --- a/python/vyos/configsession.py +++ b/python/vyos/configsession.py @@ -69,6 +69,9 @@ class ConfigSession(object): if result != 0: raise ConfigSessionError(output) + def get_session_env(self): + return self.__session_env + def set(self, path, value=None): if not value: value = [] -- cgit v1.2.3 From 3f7322d7f15ac348f1d06ba411c935956e276a76 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Wed, 3 Jul 2019 12:40:27 +0200 Subject: [vyos.config] T1505: correct return_effective_values output splitting. --- python/vyos/config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'python/vyos/config.py') diff --git a/python/vyos/config.py b/python/vyos/config.py index 96e9631e0..c9c73b971 100644 --- a/python/vyos/config.py +++ b/python/vyos/config.py @@ -405,7 +405,8 @@ class Config(object): else: try: out = self._run(self._make_command('returnEffectiveValues', full_path)) - return out + values = re.findall(r"\'(.*?)\'", out) + return values except VyOSError: return(default) -- cgit v1.2.3