1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- From 9617d339273ceecd3b47cbcd8c331080faac48f8 Mon Sep 17 00:00:00 2001
- From: Massimiliano Torromeo <massimilianotorromeo@artera.it>
- Date: Mon, 14 Apr 2014 18:01:18 +0200
- Subject: [PATCH] Allow systemd parametrized services to be enabled by the
- service state.
- This makes the systemd.get_all function return the combined output of
- list-units and list-unit-files and the systemd.available function will
- also check for the base unit name stripped of the user parameter
- (e.g. dhcpcd@eth0 will be considered available if dhcpcd@.service exists)
- ---
- salt/modules/systemd.py | 18 +++++++++++++-----
- 1 file changed, 13 insertions(+), 5 deletions(-)
- diff --git a/salt/modules/systemd.py b/salt/modules/systemd.py
- index e2cfb1d..72079d7 100644
- --- a/salt/modules/systemd.py
- +++ b/salt/modules/systemd.py
- @@ -82,7 +82,7 @@ def _get_all_units():
- r')\s+loaded\s+(?P<active>[^\s]+)')
-
- out = __salt__['cmd.run_stdout'](
- - 'systemctl --full list-units | col -b'
- + 'systemctl --full --no-legend --no-pager list-units | col -b'
- )
-
- ret = {}
- @@ -104,7 +104,7 @@ def _get_all_unit_files():
- r')\s+(?P<state>.+)$')
-
- out = __salt__['cmd.run_stdout'](
- - 'systemctl --full list-unit-files | col -b'
- + 'systemctl --full --no-legend --no-pager list-unit-files | col -b'
- )
-
- ret = {}
- @@ -195,7 +195,7 @@ def get_all():
-
- salt '*' service.get_all
- '''
- - return sorted(_get_all_units().keys())
- + return sorted(set(_get_all_units().keys() + _get_all_unit_files().keys()))
-
-
- def available(name):
- @@ -209,7 +209,15 @@ def available(name):
-
- salt '*' service.available sshd
- '''
- - return _canonical_template_unit_name(name) in get_all()
- + name = _canonical_template_unit_name(name)
- + units = get_all()
- + if name in units:
- + return True
- + elif '@' in name:
- + templatename = name[:name.find('@') + 1]
- + return templatename in units
- + else:
- + return False
-
-
- def missing(name):
- @@ -224,7 +232,7 @@ def missing(name):
-
- salt '*' service.missing sshd
- '''
- - return not _canonical_template_unit_name(name) in get_all()
- + return not available(name)
-
-
- def start(name):
- --
- 1.9.3
|