diff options
author | Daniil Baturin <daniil@baturin.org> | 2019-09-04 15:39:38 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2019-09-04 15:39:38 +0200 |
commit | 4d50edfc9543f3d27eb83300dd27d598ffe63fe2 (patch) | |
tree | 6d403977484aa5231659d17efdd031ea01c1a768 /python/vyos/config.py | |
parent | 6167fab1737ef59f223ee6c7fff0a493c76d9793 (diff) | |
download | vyos-1x-4d50edfc9543f3d27eb83300dd27d598ffe63fe2.tar.gz vyos-1x-4d50edfc9543f3d27eb83300dd27d598ffe63fe2.zip |
T1443: backport the HTTP API to crux.
Implementation by Daniil Baturin and John Estabrook.
Diffstat (limited to 'python/vyos/config.py')
-rw-r--r-- | python/vyos/config.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/python/vyos/config.py b/python/vyos/config.py index 7483e3552..c9c73b971 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: @@ -169,6 +176,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: |