diff options
author | Christian Breunig <christian@breunig.cc> | 2023-09-19 20:38:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-19 20:38:52 +0200 |
commit | 483482f16133d5aa61b07a88cca5bce7bb7776f8 (patch) | |
tree | 0e54ea3bb667a425214f04aeb9d0b3b79faa71c7 /python/vyos | |
parent | db53c8e77cd93d5d7f16036b4d7b783083caf32e (diff) | |
parent | ac21a4e69fac27504b62927a20d0a6a273abb034 (diff) | |
download | vyos-1x-483482f16133d5aa61b07a88cca5bce7bb7776f8.tar.gz vyos-1x-483482f16133d5aa61b07a88cca5bce7bb7776f8.zip |
Merge pull request #2289 from c-po/t5239-frr
init: T5239: configure system hostname prior to FRR startup
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/utils/config.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/python/vyos/utils/config.py b/python/vyos/utils/config.py new file mode 100644 index 000000000..bd363ce46 --- /dev/null +++ b/python/vyos/utils/config.py @@ -0,0 +1,34 @@ +# Copyright 2023 VyOS maintainers and contributors <maintainers@vyos.io> +# +# 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; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see <http://www.gnu.org/licenses/>. + +import os +from vyos.defaults import directories + +config_file = os.path.join(directories['config'], 'config.boot') + +def read_saved_value(path: list): + if not isinstance(path, list) or not path: + return '' + from vyos.configtree import ConfigTree + try: + with open(config_file) as f: + config_string = f.read() + ct = ConfigTree(config_string) + except Exception: + return '' + if not ct.exists(path): + return '' + res = ct.return_values(path) + return res[0] if len(res) == 1 else res |