diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-04-26 11:31:16 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-04-26 11:31:24 +0200 |
commit | 6a3938cbf595ea24d2d2e3802cf78a0519483339 (patch) | |
tree | a38cfbd330f7f0d1c46ceccf33215180a15ef948 | |
parent | bdda118c4573ba6e42376f9391d4ab16e73eb4bd (diff) | |
download | vyos-1x-6a3938cbf595ea24d2d2e3802cf78a0519483339.tar.gz vyos-1x-6a3938cbf595ea24d2d2e3802cf78a0519483339.zip |
salt: T2384: migrate config options
- delete log_file, log_level and user nodes
- rename hash_type to hash
- rename mine_interval to interval
-rw-r--r-- | data/templates/salt-minion/minion.tmpl | 4 | ||||
-rw-r--r-- | interface-definitions/salt-minion.xml.in | 9 | ||||
-rwxr-xr-x | src/conf_mode/salt-minion.py | 10 | ||||
-rwxr-xr-x | src/migration-scripts/salt/0-to-1 | 58 |
4 files changed, 67 insertions, 14 deletions
diff --git a/data/templates/salt-minion/minion.tmpl b/data/templates/salt-minion/minion.tmpl index 0b97c0524..9369573a4 100644 --- a/data/templates/salt-minion/minion.tmpl +++ b/data/templates/salt-minion/minion.tmpl @@ -12,7 +12,7 @@ # # Prior to changing this value, the master should be stopped and all Salt # caches should be cleared. -hash_type: {{ hash_type }} +hash_type: {{ hash }} ##### Logging settings ##### ########################################## @@ -54,6 +54,6 @@ id: {{ salt_id }} # The number of minutes between mine updates. -mine_interval: {{ mine_interval }} +mine_interval: {{ interval }} verify_master_pubkey_sign: {{ verify_master_pubkey_sign }} diff --git a/interface-definitions/salt-minion.xml.in b/interface-definitions/salt-minion.xml.in index 1c1dee2fb..d0e8e3e2b 100644 --- a/interface-definitions/salt-minion.xml.in +++ b/interface-definitions/salt-minion.xml.in @@ -8,7 +8,7 @@ <priority>500</priority> </properties> <children> - <leafNode name="hash_type"> + <leafNode name="hash"> <properties> <help>Hash used when discovering file on master server (default: sha256)</help> <completionHelp> @@ -43,12 +43,7 @@ <help>Explicitly declare the id for this minion to use.</help> </properties> </leafNode> - <leafNode name="user"> - <properties> - <help>The user to run the Salt processes.</help> - </properties> - </leafNode> - <leafNode name="mine_interval"> + <leafNode name="interval"> <properties> <help>The number of minutes between mine updates.</help> </properties> diff --git a/src/conf_mode/salt-minion.py b/src/conf_mode/salt-minion.py index d3412b7ef..515019014 100755 --- a/src/conf_mode/salt-minion.py +++ b/src/conf_mode/salt-minion.py @@ -30,7 +30,7 @@ config_file = r'/etc/salt/minion' master_keyfile = r'/opt/vyatta/etc/config/salt/pki/minion/master_sign.pub' default_config_data = { - 'hash_type': 'sha256', + 'hash': 'sha256', 'log_level': 'warning', 'master' : 'salt', 'user': 'nobody', @@ -51,8 +51,8 @@ def get_config(): else: conf.set_level(base) - if conf.exists(['hash_type']): - salt['hash_type'] = conf.return_value(['hash_type']) + if conf.exists(['hash']): + salt['hash'] = conf.return_value(['hash']) if conf.exists(['master']): salt['master'] = conf.return_values(['master']) @@ -63,8 +63,8 @@ def get_config(): if conf.exists(['user']): salt['user'] = conf.return_value(['user']) - if conf.exists(['mine_interval']): - salt['mine_interval'] = conf.return_value(['mine_interval']) + if conf.exists(['interval']): + salt['interval'] = conf.return_value(['interval']) if conf.exists(['master-key']): salt['master_key'] = conf.return_value(['master-key']) diff --git a/src/migration-scripts/salt/0-to-1 b/src/migration-scripts/salt/0-to-1 new file mode 100755 index 000000000..79053c056 --- /dev/null +++ b/src/migration-scripts/salt/0-to-1 @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 VyOS maintainers and contributors +# +# 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/>. + +# Delete log_file, log_level and user nodes +# rename hash_type to hash +# rename mine_interval to interval + +from sys import argv,exit + +from vyos.configtree import ConfigTree + +if (len(argv) < 1): + print("Must specify file name!") + exit(1) + +file_name = argv[1] + +with open(file_name, 'r') as f: + config_file = f.read() + +config = ConfigTree(config_file) + +base = ['service', 'salt-minion'] +if not config.exists(base): + # Nothing to do + exit(0) +else: + + # delete nodes which are now populated with sane defaults + for node in ['log_file', 'log_level', 'user']: + if config.exists(base + [node]): + config.delete(base + [node]) + + if config.exists(base + ['hash_type']): + config.rename(base + ['hash_type'], 'hash') + + if config.exists(base + ['mine_interval']): + config.rename(base + ['mine_interval'], 'interval') + + try: + with open(file_name, 'w') as f: + f.write(config.to_string()) + except OSError as e: + print("Failed to save the modified config: {}".format(e)) + exit(1) |