Skip to content

Commit 5726d84

Browse files
committed
migration: T6007: update run-config-migration script
1 parent 613c8de commit 5726d84

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/helpers/run-config-migrate.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (C) 2024 VyOS maintainers and contributors
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License version 2 or later as
7+
# published by the Free Software Foundation.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import os
18+
import sys
19+
import time
20+
from argparse import ArgumentParser
21+
from shutil import copyfile
22+
23+
from vyos.migrate import ConfigMigrate
24+
25+
parser = ArgumentParser()
26+
parser.add_argument('config_file', type=str,
27+
help="configuration file to migrate")
28+
parser.add_argument('--test-script', type=str,
29+
help="test named script")
30+
parser.add_argument('--output-file', type=str,
31+
help="write to named output file instead of config file")
32+
parser.add_argument('--force', action='store_true',
33+
help="force run of all migration scripts")
34+
35+
36+
args = parser.parse_args()
37+
38+
config_file = args.config_file
39+
out_file = args.output_file
40+
test_script = args.test_script
41+
force = args.force
42+
43+
if not os.access(config_file, os.R_OK):
44+
print(f"Config file '{config_file}' not readable")
45+
sys.exit(1)
46+
47+
file = out_file if out_file is not None else config_file
48+
if not os.access(file, os.W_OK):
49+
print("File '{file}' not writeable")
50+
sys.exit(1)
51+
52+
if out_file is None:
53+
timestr = time.strftime("%Y%m%d-%H%M%S")
54+
backup = f'{config_file}.{timestr}.pre-migration'
55+
copyfile(config_file, backup)
56+
57+
config_migrate = ConfigMigrate(config_file, force=force, output_file=out_file)
58+
59+
if test_script:
60+
# run_script and exit
61+
config_migrate.run_script(test_script)
62+
sys.exit(0)
63+
64+
config_migrate.run()

0 commit comments

Comments
 (0)