blob: 01a6a88dc57198e103a1e3b9fc3049afdafe89ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/usr/bin/env python3
#
# Copyright VyOS maintainers and contributors <maintainers@vyos.io>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
# published by the Free Software Foundation.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
import os
import sys
import argparse
import tempfile
from vyos.remote import get_config_file
from vyos.config import Config
from vyos.migrate import ConfigMigrate
from vyos.migrate import ConfigMigrateError
from vyos.load_config import load as load_config
parser = argparse.ArgumentParser()
parser.add_argument('config_file', help='config file to load')
parser.add_argument(
'--migrate', action='store_true', help='migrate config file before merge'
)
args = parser.parse_args()
file_name = args.config_file
# pylint: disable=consider-using-with
file_path = tempfile.NamedTemporaryFile(delete=False).name
err = get_config_file(file_name, file_path)
if err:
os.remove(file_path)
sys.exit(err)
if args.migrate:
migrate = ConfigMigrate(file_path)
try:
migrate.run()
except ConfigMigrateError as e:
os.remove(file_path)
sys.exit(e)
config = Config()
if config.vyconf_session is not None:
out, err = config.vyconf_session.load_config(file_path)
if err:
os.remove(file_path)
sys.exit(out)
print(out)
else:
load_config(file_path)
os.remove(file_path)
if config.session_changed():
print("Load complete. Use 'commit' to make changes effective.")
else:
print('No configuration changes to commit.')
|