summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@sentrium.io>2019-05-30 13:46:08 -0500
committerJohn Estabrook <jestabro@sentrium.io>2019-06-05 15:13:58 -0500
commit6763170830010c8cea2f17daee5f46b9203dab56 (patch)
treed64f009676f44f8d49a09b91655d81ec1f22ca08 /src/helpers
parent1483288278060c62904ba1c9984aae841600e2f5 (diff)
downloadvyos-1x-6763170830010c8cea2f17daee5f46b9203dab56.tar.gz
vyos-1x-6763170830010c8cea2f17daee5f46b9203dab56.zip
T1334: Migration script runner rewrite
Python script and support code to replace the vyatta_config_migrate.pl script.
Diffstat (limited to 'src/helpers')
-rwxr-xr-xsrc/helpers/run-config-migration.py83
-rwxr-xr-xsrc/helpers/system-versions-foot.py39
2 files changed, 122 insertions, 0 deletions
diff --git a/src/helpers/run-config-migration.py b/src/helpers/run-config-migration.py
new file mode 100755
index 000000000..a57a19cdf
--- /dev/null
+++ b/src/helpers/run-config-migration.py
@@ -0,0 +1,83 @@
+#!/usr/bin/python3
+
+# Copyright 2019 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
+import sys
+import argparse
+import datetime
+import subprocess
+from vyos.migrator import Migrator, VirtualMigrator
+
+def main():
+ argparser = argparse.ArgumentParser(
+ formatter_class=argparse.RawTextHelpFormatter)
+ argparser.add_argument('config_file', type=str,
+ help="configuration file to migrate")
+ argparser.add_argument('--force', action='store_true',
+ help="Force calling of all migration scripts.")
+ argparser.add_argument('--set-vintage', type=str,
+ choices=['vyatta', 'vyos'],
+ help="Set the format for the config version footer in config"
+ " file:\n"
+ "set to 'vyatta':\n"
+ "(for '/* === vyatta-config-version ... */' format)\n"
+ "or 'vyos':\n"
+ "(for '// vyos-config-version ...' format).")
+ argparser.add_argument('--virtual', action='store_true',
+ help="Update the format of the trailing comments in"
+ " config file,\nfrom 'vyatta' to 'vyos'; no migration"
+ " scripts are run.")
+ args = argparser.parse_args()
+
+ config_file_name = args.config_file
+ force_on = args.force
+ vintage = args.set_vintage
+ virtual = args.virtual
+
+ if not os.access(config_file_name, os.R_OK):
+ print("Read error: {}.".format(config_file_name))
+ sys.exit(1)
+
+ if not os.access(config_file_name, os.W_OK):
+ print("Write error: {}.".format(config_file_name))
+ sys.exit(1)
+
+ separator = "."
+ backup_file_name = separator.join([config_file_name,
+ '{0:%Y-%m-%d-%H%M%S}'.format(datetime.datetime.now()),
+ 'pre-migration'])
+
+ try:
+ subprocess.check_call(['cp', '-p', config_file_name,
+ backup_file_name])
+ except subprocess.CalledProcessError as err:
+ print("Called process error: {}.".format(err))
+ sys.exit(1)
+
+ if not virtual:
+ migration = Migrator(config_file_name, force=force_on,
+ set_vintage=vintage)
+ else:
+ migration = VirtualMigrator(config_file_name)
+
+ migration.run()
+
+ if not migration._changed:
+ os.remove(backup_file_name)
+
+if __name__ == '__main__':
+ main()
diff --git a/src/helpers/system-versions-foot.py b/src/helpers/system-versions-foot.py
new file mode 100755
index 000000000..c33e41d79
--- /dev/null
+++ b/src/helpers/system-versions-foot.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python3
+
+# Copyright 2019 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 sys
+import vyos.formatversions as formatversions
+import vyos.systemversions as systemversions
+import vyos.defaults
+import vyos.version
+
+sys_versions = systemversions.get_system_versions()
+
+component_string = formatversions.format_versions_string(sys_versions)
+
+os_version_string = vyos.version.get_version()
+
+sys.stdout.write("\n\n")
+if vyos.defaults.cfg_vintage == 'vyos':
+ formatversions.write_vyos_versions_foot(None, component_string,
+ os_version_string)
+elif vyos.defaults.cfg_vintage == 'vyatta':
+ formatversions.write_vyatta_versions_foot(None, component_string,
+ os_version_string)
+else:
+ formatversions.write_vyatta_versions_foot(None, component_string,
+ os_version_string)