Merge pull request #14316 from thatch45/2014.7

backport #14296
This commit is contained in:
Thomas S Hatch 2014-07-17 13:41:10 -06:00
commit 37b17cc965

View File

@ -7,7 +7,6 @@ data.
# Import salt libs # Import salt libs
import salt.utils import salt.utils
from salt.utils import decorators
# Import python libs # Import python libs
import logging import logging
@ -38,6 +37,23 @@ def _format_response(response, msg):
} }
def _get_rabbitmq_plugin():
"""Returns the rabbitmq-plugin command path if we're running an OS that
doesn't put it in the standard /usr/bin or /usr/local/bin
This works by taking the rabbitmq-server version and looking for where it
seems to be hidden in /usr/lib.
"""
rabbitmq = salt.utils.which('rabbitmq-plugins')
if rabbitmq is None:
version = __salt__['pkg.version']('rabbitmq-server').split('-')[0]
path = '/usr/lib/rabbitmq/lib/rabbitmq_server-{0}/sbin/rabbitmq-plugins'
rabbitmq = path.format(version)
return rabbitmq
def list_users(runas=None): def list_users(runas=None):
''' '''
Return a list of users based off of rabbitmqctl user_list. Return a list of users based off of rabbitmqctl user_list.
@ -548,7 +564,6 @@ def policy_exists(vhost, name, runas=None):
return bool(vhost in policies and name in policies[vhost]) return bool(vhost in policies and name in policies[vhost])
@decorators.which('rabbitmq-plugins')
def plugin_is_enabled(name, runas=None): def plugin_is_enabled(name, runas=None):
''' '''
Return whether the plugin is enabled. Return whether the plugin is enabled.
@ -559,11 +574,12 @@ def plugin_is_enabled(name, runas=None):
salt '*' rabbitmq.plugin_is_enabled foo salt '*' rabbitmq.plugin_is_enabled foo
''' '''
ret = __salt__['cmd.run']('rabbitmq-plugins list -m -e', runas=runas) rabbitmq = _get_rabbitmq_plugin()
cmd = '{0} list -m -e'.format(rabbitmq)
ret = __salt__['cmd.run'](cmd, runas=runas)
return bool(name in ret) return bool(name in ret)
@decorators.which('rabbitmq-plugins')
def enable_plugin(name, runas=None): def enable_plugin(name, runas=None):
''' '''
Enable a RabbitMQ plugin via the rabbitmq-plugins command. Enable a RabbitMQ plugin via the rabbitmq-plugins command.
@ -574,13 +590,14 @@ def enable_plugin(name, runas=None):
salt '*' rabbitmq.enable_plugin foo salt '*' rabbitmq.enable_plugin foo
''' '''
ret = __salt__['cmd.run_all']( rabbitmq = _get_rabbitmq_plugin()
'rabbitmq-plugins enable {0}'.format(name), cmd = '{0} enable {1}'.format(rabbitmq, name)
runas=runas)
ret = __salt__['cmd.run_all'](cmd, runas=runas)
return _format_response(ret, 'Enabled') return _format_response(ret, 'Enabled')
@decorators.which('rabbitmq-plugins')
def disable_plugin(name, runas=None): def disable_plugin(name, runas=None):
''' '''
Disable a RabbitMQ plugin via the rabbitmq-plugins command. Disable a RabbitMQ plugin via the rabbitmq-plugins command.
@ -592,7 +609,9 @@ def disable_plugin(name, runas=None):
salt '*' rabbitmq.disable_plugin foo salt '*' rabbitmq.disable_plugin foo
''' '''
ret = __salt__['cmd.run_all']( rabbitmq = _get_rabbitmq_plugin()
'rabbitmq-plugins disable {0}'.format(name), cmd = '{0} disable {1}'.format(rabbitmq, name)
runas=runas)
ret = __salt__['cmd.run_all'](cmd, runas=runas)
return _format_response(ret, 'Disabled') return _format_response(ret, 'Disabled')