diff options
Diffstat (limited to 'src/helpers/vyos-load-config.py')
-rwxr-xr-x | src/helpers/vyos-load-config.py | 38 |
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.") |