diff options
author | John Estabrook <jestabro@vyos.io> | 2023-06-10 16:49:13 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2023-06-10 22:39:56 -0500 |
commit | f8d75a17e2f6b725f6119295cf9397caf18e32eb (patch) | |
tree | 643f6725732499f6ee3a575b6609642722d588a6 /python/vyos/configsession.py | |
parent | 795b259b95a4c11f92c6c8aaceb5003c869f1b1a (diff) | |
download | vyos-1x-f8d75a17e2f6b725f6119295cf9397caf18e32eb.tar.gz vyos-1x-f8d75a17e2f6b725f6119295cf9397caf18e32eb.zip |
configsession: T5248: add functions set/load_section
Diffstat (limited to 'python/vyos/configsession.py')
-rw-r--r-- | python/vyos/configsession.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/python/vyos/configsession.py b/python/vyos/configsession.py index df44fd8d6..88eedb944 100644 --- a/python/vyos/configsession.py +++ b/python/vyos/configsession.py @@ -1,5 +1,5 @@ # configsession -- the write API for the VyOS running config -# Copyright (C) 2019 VyOS maintainers and contributors +# Copyright (C) 2019-2023 VyOS maintainers and contributors # # This library is free software; you can redistribute it and/or modify it under the terms of # the GNU Lesser General Public License as published by the Free Software Foundation; @@ -18,6 +18,7 @@ import sys import subprocess from vyos.util import is_systemd_service_running +from vyos.utils.dict import dict_to_paths CLI_SHELL_API = '/bin/cli-shell-api' SET = '/opt/vyatta/sbin/my_set' @@ -148,6 +149,13 @@ class ConfigSession(object): value = [value] self.__run_command([SET] + path + value) + def set_section(self, path: list, d: dict): + try: + for p in dict_to_paths(d): + self.set(path + p) + except (ValueError, ConfigSessionError) as e: + raise ConfigSessionError(e) + def delete(self, path, value=None): if not value: value = [] @@ -155,6 +163,14 @@ class ConfigSession(object): value = [value] self.__run_command([DELETE] + path + value) + def load_section(self, path: list, d: dict): + try: + self.delete(path) + for p in dict_to_paths(d): + self.set(path + p) + except (ValueError, ConfigSessionError) as e: + raise ConfigSessionError(e) + def comment(self, path, value=None): if not value: value = [""] |