diff options
author | Kim Hagen <kim.sidney@gmail.com> | 2018-07-03 11:54:21 +0200 |
---|---|---|
committer | Kim Hagen <kim.sidney@gmail.com> | 2018-07-03 11:54:21 +0200 |
commit | 615dd2052ce194618cd6fbc0aabb3ad68687e7c3 (patch) | |
tree | b90d4cbf83dc70112495a73762048492a1af9978 | |
parent | 00d501404064ee548e96d67da70f17f08876a850 (diff) | |
parent | 01dbed6d792750550cbd961ba8b2794e4b98e294 (diff) | |
download | vyos-salt-minion-615dd2052ce194618cd6fbc0aabb3ad68687e7c3.tar.gz vyos-salt-minion-615dd2052ce194618cd6fbc0aabb3ad68687e7c3.zip |
Merge branch 'master' of github.com:UnicronNL/vyos-salt-minion
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | README.md | 57 | ||||
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | debian/vyos-salt-minion.postinst | 10 | ||||
-rwxr-xr-x | src/conf_mode/salt-minion.py | 32 |
5 files changed, 39 insertions, 65 deletions
@@ -7,6 +7,9 @@ interface_definitions: mkdir -p $(TMPL_DIR) find $(CURDIR)/interface-definitions/ -type f | xargs -I {} $(CURDIR)/scripts/build-command-templates {} $(CURDIR)/schema/interface_definition.rng $(TMPL_DIR) || exit 1 + + # XXX: delete top level node.def's that now live in other packages + rm -f $(TMPL_DIR)/service/node.def .PHONY: op_mode_definitions .ONESHELL: @@ -1,56 +1 @@ -# vyos-1x: VyOS 1.2.0+ configuration scripts and data - -[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=vyos%3Avyos-1x&metric=coverage)](https://sonarcloud.io/component_measures?id=vyos%3Avyos-1x&metric=coverage) - -VyOS 1.1.x had its codebase split into way too many submodules for no good reason, which made it hard -to navigate or write meaningful changelogs. As the code undergoes rewrite in the new style in VyOS 1.2.0+, -we consolidate the rewritten code in this package. - -If you just want to build a VyOS image, the repository you want is [vyos-build](https://github.com/vyos/vyos-build). -If you also want to contribute to VyOS, read on. - -## Package layout - -``` -interface-definitions # Configuration interface (i.e. conf mode command) definitions -op-mode-definitions # Operational command definitions -src - conf_mode/ # Configuration mode scripts - op_mode/ # Operational mode scripts - completion/ # Completion helpers - validators/ # Value validators - helpers/ # Misc helpers - migration-scripts # Migration scripts - tests/ # Unit tests - -python/ # Python modules - -scripts/ # Build-time scripts -schema/ # XML schemas -``` - -## Interface/command definitions - -Raw node.def files for the old backend are no longer written by hand or generated by custom sciprts. -They are all now produced from a unified XML format that supports a strict subset of the old backend -features. In particular, it intentionally does not support embedded shell scripts, default values, -and value "types", instead delegating those tasks to external scripts. - -Configuration interface definitions must conform to the schema found in schema/interface_definition.rng -and operational command definitions must conform to schema/op-mode-definition.rng -Schema checks are performed at build time, so a package with malformed interface definitions will not build. - -## Configuration scripts - -The guidelines in a nutshell: - -* Use separate functions for retrieving configuration data, validating it, and generating taret config -* Use a template processor when the format is more complex than just one line (jinja2 and pystache are acceptable options) - -## Tests - -Tests are executed at build time, you can also execute them by hand with: - -``` -make test -``` +# vyos-salt-minion diff --git a/debian/control b/debian/control index 54203cb..be45596 100644 --- a/debian/control +++ b/debian/control @@ -19,6 +19,8 @@ Depends: python3, python3-netifaces, python3-jinja2, python3-pystache, + salt-minion, + vyos-1x, ipaddrcheck, tcpdump, bmon, diff --git a/debian/vyos-salt-minion.postinst b/debian/vyos-salt-minion.postinst new file mode 100644 index 0000000..a427c3c --- /dev/null +++ b/debian/vyos-salt-minion.postinst @@ -0,0 +1,10 @@ +#!/bin/sh -e +if ! deb-systemd-helper --quiet was-enabled salt-minion.service; then + # Enables the unit on first installation, creates new + # symlinks on upgrades if the unit file has changed. + deb-systemd-helper disable salt-minion.service >/dev/null || true +fi + +if [ -x "/etc/init.d/salt-minion" ]; then + update-rc.d -f salt-minion remove >/dev/null +fi diff --git a/src/conf_mode/salt-minion.py b/src/conf_mode/salt-minion.py index 4edb7a0..621159b 100755 --- a/src/conf_mode/salt-minion.py +++ b/src/conf_mode/salt-minion.py @@ -18,6 +18,7 @@ import sys import os +import pwd import socket import jinja2 @@ -37,7 +38,9 @@ config_tmpl = """ # Set the location of the salt master server, if the master server cannot be # resolved, then the minion will fail to start. -master: {{ master }} +{% for host in master -%} +master: {{ host }} +{% endfor %} # The user to run salt user: {{ user }} @@ -50,13 +53,17 @@ pki_dir: /config/salt/pki/minion # Since salt uses detached ids it is possible to run multiple minions on the # same machine but with different ids, this can be useful for salt compute # clusters. -id: {{ id }} +id: {{ salt_id }} + +mine_enabled: True +mine_return_job: False +mine_interval: 60 """ default_config_data = { 'master' : 'salt', 'user': 'vyos', - 'id': socket.gethostname() + 'salt_id': socket.gethostname() } def get_config(): @@ -72,17 +79,18 @@ def get_config(): salt['master'] = master if conf.exists('ID'): - id = conf.return_values('ID') - salt['id'] = id + salt['salt_id'] = conf.return_value('ID') if conf.exists('user'): - user = conf.return_values('user') - salt['user'] = user + salt['user'] = conf.return_value('user') return salt def generate(salt): - directory = '/config/salt/pki/minion' + paths = ['/etc/salt/','/var/run/salt','/opt/vyatta/etc/config/salt/'] + directory = '/opt/vyatta/etc/config/salt/pki/minion' + uid = pwd.getpwnam(salt['user']).pw_uid + if salt is None: return None @@ -93,6 +101,13 @@ def generate(salt): config_text = tmpl.render(salt) with open(config_file, 'w') as f: f.write(config_text) + path = "/etc/salt/" + for path in paths: + for root, dirs, files in os.walk(path): + for usgr in dirs: + os.chown(os.path.join(root, usgr), uid, 100) + for usgr in files: + os.chown(os.path.join(root, usgr), uid, 100) return None def apply(salt): @@ -108,7 +123,6 @@ def apply(salt): if __name__ == '__main__': try: c = get_config() - verify(c) generate(c) apply(c) except ConfigError as e: |