summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2019-06-13 03:11:22 +0200
committerDaniil Baturin <daniil@baturin.org>2019-06-13 03:11:22 +0200
commit163905e7e8977ae82c4a93c992b8f21f91144918 (patch)
tree51a5773d696fb6fe7c39d3d862eb5faa2ea0f485
parent29df430906c830146e6cc9b7edda9be836a01837 (diff)
parentbd6f3f6534a93f8a8c64e06967c24d4c3827c517 (diff)
downloadvyos-1x-163905e7e8977ae82c4a93c992b8f21f91144918.tar.gz
vyos-1x-163905e7e8977ae82c4a93c992b8f21f91144918.zip
Merge branch 'current' of https://github.com/vyos/vyos-1x into current
-rw-r--r--python/vyos/migrator.py2
-rwxr-xr-xsrc/helpers/vyos-merge-config.py35
2 files changed, 29 insertions, 8 deletions
diff --git a/python/vyos/migrator.py b/python/vyos/migrator.py
index 2d4bc7ffc..59d68f0f7 100644
--- a/python/vyos/migrator.py
+++ b/python/vyos/migrator.py
@@ -165,6 +165,8 @@ class Migrator(object):
self.write_config_file_versions(rev_versions)
+ def config_changed(self):
+ return self._changed
class VirtualMigrator(Migrator):
def __init__(self, config_file, vintage='vyos'):
diff --git a/src/helpers/vyos-merge-config.py b/src/helpers/vyos-merge-config.py
index f0d5d1595..e9a14ae98 100755
--- a/src/helpers/vyos-merge-config.py
+++ b/src/helpers/vyos-merge-config.py
@@ -18,8 +18,10 @@
import sys
import os
import subprocess
+import tempfile
import vyos.defaults
import vyos.remote
+import vyos.migrator
from vyos.config import Config
from vyos.configtree import ConfigTree
@@ -55,15 +57,25 @@ else:
print(err)
sys.exit(1)
-path = None
-if (len(sys.argv) > 2):
- path = " ".join(sys.argv[2:])
+with tempfile.NamedTemporaryFile() as file_to_migrate:
+ with open(file_to_migrate.name, 'w') as fd:
+ fd.write(config_file)
+
+ migration = vyos.migrator.Migrator(file_to_migrate.name)
+ migration.run()
+ if migration.config_changed():
+ with open(file_to_migrate.name, 'r') as fd:
+ config_file = fd.read()
merge_config_tree = ConfigTree(config_file)
effective_config = Config()
output_effective_config = effective_config.show_config()
+# showConfig (called by config.show_config() does not escape
+# backslashes, which configtree expects; cf. T1001.
+output_effective_config = output_effective_config.replace("\\", "\\\\")
+
effective_config_tree = ConfigTree(output_effective_config)
effective_cmds = effective_config_tree.to_commands()
@@ -75,12 +87,19 @@ merge_cmd_list = merge_cmds.splitlines()
effective_cmd_set = set(effective_cmd_list)
add_cmds = [ cmd for cmd in merge_cmd_list if cmd not in effective_cmd_set ]
-if path:
- if not effective_config.exists(path):
- print("path {} does not exist in running config; will use "
- "root.".format(path))
+path = None
+if (len(sys.argv) > 2):
+ path = sys.argv[2:]
+ if (not effective_config_tree.exists(path) and not
+ merge_config_tree.exists(path)):
+ print("path {} does not exist in either effective or merge"
+ " config; will use root.".format(path))
+ path = None
else:
- add_cmds = [ cmd for cmd in add_cmds if path in cmd ]
+ path = " ".join(path)
+
+if path:
+ add_cmds = [ cmd for cmd in add_cmds if path in cmd ]
for cmd in add_cmds:
cmd = "/opt/vyatta/sbin/my_" + cmd