summaryrefslogtreecommitdiff
path: root/src/helpers/vyos-load-config.py
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2022-03-10 09:34:00 -0600
committerJohn Estabrook <jestabro@vyos.io>2022-03-10 12:10:35 -0600
commitfde48b4d303b471f8c56b81bc7fcef0a028bb60a (patch)
tree9e29d3d5497ff116f8be559517e3078774227629 /src/helpers/vyos-load-config.py
parent2a4b45ba7fa4dabf7e592f499cfb06a7ae38cdea (diff)
downloadvyos-1x-fde48b4d303b471f8c56b81bc7fcef0a028bb60a.tar.gz
vyos-1x-fde48b4d303b471f8c56b81bc7fcef0a028bb60a.zip
Revert "load-config: T4295: use config_tree instead of legacy loadFile"
This reverts commit 2a4b45ba7fa4dabf7e592f499cfb06a7ae38cdea. Revert while investigating failure in vyos-configtest.
Diffstat (limited to 'src/helpers/vyos-load-config.py')
-rwxr-xr-xsrc/helpers/vyos-load-config.py38
1 files changed, 8 insertions, 30 deletions
diff --git a/src/helpers/vyos-load-config.py b/src/helpers/vyos-load-config.py
index 08f28b24e..e579e81b2 100755
--- a/src/helpers/vyos-load-config.py
+++ b/src/helpers/vyos-load-config.py
@@ -29,40 +29,15 @@ import gzip
import tempfile
import vyos.defaults
import vyos.remote
-from vyos.configsource import ConfigSourceSession
-from vyos.configtree import ConfigTree, DiffTree
+from vyos.configsource import ConfigSourceSession, VyOSError
from vyos.migrator import Migrator, VirtualMigrator, MigratorError
-from vyos.util import cmd, DEVNULL
class LoadConfig(ConfigSourceSession):
- """A subclass for loading a config file.
+ """A subclass for calling 'loadFile'.
This does not belong in configsource.py, and only has a single caller.
"""
- def load_config(self, file_path):
- try:
- with open(file_path) as f:
- config_file = f.read()
- load_ct = ConfigTree(config_file)
- except (OSError, ValueError) as e:
- print(e)
- return
-
- eff_ct, _ = self.get_configtree_tuple()
- diff = DiffTree(eff_ct, load_ct)
- commands = diff.to_commands()
- # on an empty set of 'add' or 'delete' commands, to_commands
- # returns '\n'; prune below
- command_list = commands.splitlines()
- command_list = [c for c in command_list if c]
-
- if not command_list:
- return
- for op in command_list:
- try:
- cmd(f'/opt/vyatta/sbin/my_{op}', shell=True, stderr=DEVNULL)
- except OSError as e:
- print(e)
- return
+ def load_config(self, path):
+ return self._run(['/bin/cli-shell-api','loadFile',path])
file_name = sys.argv[1] if len(sys.argv) > 1 else 'config.boot'
configdir = vyos.defaults.directories['config']
@@ -118,7 +93,10 @@ with tempfile.NamedTemporaryFile() as fp:
except MigratorError as err:
sys.exit('{}'.format(err))
- config.load_config(fp.name)
+ try:
+ config.load_config(fp.name)
+ except VyOSError as err:
+ sys.exit('{}'.format(err))
if config.session_changed():
print("Load complete. Use 'commit' to make changes effective.")