mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #15509 from ajacoutot/service-enabled-kwargs
Service enabled kwargs
This commit is contained in:
commit
f6e3951ddb
@ -274,7 +274,7 @@ def disable(name, **kwargs):
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
|
||||
|
||||
def enabled(name):
|
||||
def enabled(name, **kwargs):
|
||||
'''
|
||||
Return True if the named service is enabled, false otherwise
|
||||
|
||||
|
@ -209,7 +209,7 @@ def disable(name, **kwargs):
|
||||
return _switch(name, False, **kwargs)
|
||||
|
||||
|
||||
def enabled(name):
|
||||
def enabled(name, **kwargs):
|
||||
'''
|
||||
Return True if the named service is enabled, false otherwise
|
||||
|
||||
|
@ -188,7 +188,7 @@ def disable(name, **kwargs):
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
|
||||
|
||||
def enabled(name):
|
||||
def enabled(name, **kwargs):
|
||||
'''
|
||||
Return True if the named service is enabled, false otherwise
|
||||
|
||||
|
@ -258,7 +258,7 @@ def disable(name, **kwargs):
|
||||
return _rcconf_status(name, 'NO')
|
||||
|
||||
|
||||
def enabled(name):
|
||||
def enabled(name, **kwargs):
|
||||
'''
|
||||
Return True if the named service is enabled, false otherwise
|
||||
|
||||
|
@ -40,6 +40,16 @@ def _cmd():
|
||||
return rcctl
|
||||
|
||||
|
||||
def _get_flags(**kwargs):
|
||||
'''
|
||||
Return the configured service flags.
|
||||
'''
|
||||
flags = kwargs.get('flags', \
|
||||
__salt__['config.option']('service.flags', \
|
||||
default=''))
|
||||
return flags
|
||||
|
||||
|
||||
def available(name):
|
||||
'''
|
||||
Return True if the named service is available.
|
||||
@ -216,15 +226,8 @@ def enable(name, **kwargs):
|
||||
salt '*' service.enable <service name>
|
||||
salt '*' service.enable <service name> flags=<flags>
|
||||
'''
|
||||
flags = kwargs.get('flags',
|
||||
__salt__['config.option']('service.flags',
|
||||
default=''))
|
||||
|
||||
if not flags:
|
||||
cmd = '{0} enable {1}'.format(_cmd(), name)
|
||||
else:
|
||||
cmd = '{0} enable {1} flags {2}'.format(_cmd(), name, flags)
|
||||
|
||||
flags = _get_flags(**kwargs)
|
||||
cmd = '{0} enable {1} flags {2}'.format(_cmd(), name, flags)
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
|
||||
|
||||
@ -256,9 +259,10 @@ def disabled(name):
|
||||
return not __salt__['cmd.retcode'](cmd) == 0
|
||||
|
||||
|
||||
def enabled(name):
|
||||
def enabled(name, **kwargs):
|
||||
'''
|
||||
Return True if the named service is enabled at boot, False otherwise.
|
||||
Return True if the named service is enabled at boot and the provided
|
||||
flags match the configured ones (if any). Return False otherwise.
|
||||
|
||||
name
|
||||
Service name
|
||||
@ -268,6 +272,15 @@ def enabled(name):
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' service.enabled <service name>
|
||||
salt '*' service.enabled <service name> flags=<flags>
|
||||
'''
|
||||
cmd = '{0} status {1}'.format(_cmd(), name)
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
if not __salt__['cmd.retcode'](cmd):
|
||||
# also consider a service disabled if the current flags are different
|
||||
# than the configured ones so we have a chance to update them
|
||||
flags = _get_flags(**kwargs)
|
||||
cur_flags = __salt__['cmd.run_stdout']('{0} status {1}'.format(_cmd(), name))
|
||||
if format(flags) == format(cur_flags):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
@ -243,7 +243,7 @@ def get_enabled():
|
||||
return sorted(set(get_all()) & set(services))
|
||||
|
||||
|
||||
def enabled(name):
|
||||
def enabled(name, **kwargs):
|
||||
'''
|
||||
.. versionadded:: 2014.7.0
|
||||
|
||||
|
@ -465,7 +465,7 @@ def disable(name, **kwargs):
|
||||
return _sysv_disable(name)
|
||||
|
||||
|
||||
def enabled(name):
|
||||
def enabled(name, **kwargs):
|
||||
'''
|
||||
Check to see if the named service is enabled to start on boot
|
||||
|
||||
|
@ -262,7 +262,7 @@ def disable(name, **kwargs):
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
|
||||
|
||||
def enabled(name):
|
||||
def enabled(name, **kwargs):
|
||||
'''
|
||||
Check to see if the named service is enabled to start on boot
|
||||
|
||||
|
@ -380,7 +380,7 @@ def _enabled(name):
|
||||
return is_enabled or _templated_instance_enabled(name)
|
||||
|
||||
|
||||
def enabled(name):
|
||||
def enabled(name, **kwargs):
|
||||
'''
|
||||
Return if the named service is enabled to start on boot
|
||||
|
||||
|
@ -474,7 +474,7 @@ def disable(name, **kwargs):
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
|
||||
|
||||
def enabled(name):
|
||||
def enabled(name, **kwargs):
|
||||
'''
|
||||
Check to see if the named service is enabled to start on boot
|
||||
|
||||
|
@ -312,7 +312,7 @@ def disable(name, **kwargs):
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
|
||||
|
||||
def enabled(name):
|
||||
def enabled(name, **kwargs):
|
||||
'''
|
||||
Check to see if the named service is enabled to start on boot
|
||||
|
||||
|
@ -93,7 +93,7 @@ def _enable(name, started, result=True, **kwargs):
|
||||
return ret
|
||||
|
||||
# Service can be enabled
|
||||
if __salt__['service.enabled'](name):
|
||||
if __salt__['service.enabled'](name, **kwargs):
|
||||
# Service is enabled
|
||||
if started is True:
|
||||
ret['changes'][name] = True
|
||||
|
Loading…
Reference in New Issue
Block a user