mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #19476 from thatch45/sr_shell
s-r modules shell migrate
This commit is contained in:
commit
7550c76afd
@ -155,6 +155,7 @@ def add_user(name, password=None, runas=None):
|
||||
res = __salt__['cmd.run'](
|
||||
'rabbitmqctl add_user {0} {1!r}'.format(name, password),
|
||||
output_loglevel='quiet',
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
|
||||
if clear_pw:
|
||||
@ -185,6 +186,7 @@ def delete_user(name, runas=None):
|
||||
if runas is None:
|
||||
runas = salt.utils.get_user()
|
||||
res = __salt__['cmd.run']('rabbitmqctl delete_user {0}'.format(name),
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
msg = 'Deleted'
|
||||
|
||||
@ -206,6 +208,7 @@ def change_password(name, password, runas=None):
|
||||
res = __salt__['cmd.run'](
|
||||
'rabbitmqctl change_password {0} {1!r}'.format(name, password),
|
||||
output_loglevel='quiet',
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
msg = 'Password Changed'
|
||||
|
||||
@ -225,6 +228,7 @@ def clear_password(name, runas=None):
|
||||
if runas is None:
|
||||
runas = salt.utils.get_user()
|
||||
res = __salt__['cmd.run']('rabbitmqctl clear_password {0}'.format(name),
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
msg = 'Password Cleared'
|
||||
|
||||
@ -244,6 +248,7 @@ def add_vhost(vhost, runas=None):
|
||||
if runas is None:
|
||||
runas = salt.utils.get_user()
|
||||
res = __salt__['cmd.run']('rabbitmqctl add_vhost {0}'.format(vhost),
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
|
||||
msg = 'Added'
|
||||
@ -263,6 +268,7 @@ def delete_vhost(vhost, runas=None):
|
||||
if runas is None:
|
||||
runas = salt.utils.get_user()
|
||||
res = __salt__['cmd.run']('rabbitmqctl delete_vhost {0}'.format(vhost),
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
msg = 'Deleted'
|
||||
return _format_response(res, msg)
|
||||
@ -283,6 +289,7 @@ def set_permissions(vhost, user, conf='.*', write='.*', read='.*', runas=None):
|
||||
res = __salt__['cmd.run'](
|
||||
'rabbitmqctl set_permissions -p {0} {1} "{2}" "{3}" "{4}"'.format(
|
||||
vhost, user, conf, write, read),
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
msg = 'Permissions Set'
|
||||
return _format_response(res, msg)
|
||||
@ -302,6 +309,7 @@ def list_permissions(vhost, runas=None):
|
||||
runas = salt.utils.get_user()
|
||||
res = __salt__['cmd.run'](
|
||||
'rabbitmqctl list_permissions -p {0}'.format(vhost),
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
return [r.split('\t') for r in res.splitlines()]
|
||||
|
||||
@ -320,6 +328,7 @@ def list_user_permissions(name, runas=None):
|
||||
runas = salt.utils.get_user()
|
||||
res = __salt__['cmd.run'](
|
||||
'rabbitmqctl list_user_permissions {0}'.format(name),
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
return [r.split('\t') for r in res.splitlines()]
|
||||
|
||||
@ -337,6 +346,7 @@ def set_user_tags(name, tags, runas=None):
|
||||
runas = salt.utils.get_user()
|
||||
res = __salt__['cmd.run'](
|
||||
'rabbitmqctl set_user_tags {0} {1}'.format(name, tags),
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
msg = "Tag(s) set"
|
||||
return _format_response(res, msg)
|
||||
@ -395,6 +405,7 @@ def join_cluster(host, user='rabbit', runas=None):
|
||||
stop_app(runas)
|
||||
res = __salt__['cmd.run'](
|
||||
'rabbitmqctl join_cluster {0}@{1}'.format(user, host),
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
start_app(runas)
|
||||
|
||||
@ -491,6 +502,7 @@ def list_queues(runas=None, *kwargs):
|
||||
runas = salt.utils.get_user()
|
||||
res = __salt__['cmd.run'](
|
||||
'rabbitmqctl list_queues {0}'.format(' '.join(list(kwargs))),
|
||||
python_shell=False,
|
||||
runas=runas,
|
||||
)
|
||||
return res
|
||||
@ -516,6 +528,7 @@ def list_queues_vhost(vhost, runas=None, *kwargs):
|
||||
vhost,
|
||||
' '.join(list(kwargs))
|
||||
),
|
||||
python_shell=False,
|
||||
runas=runas,
|
||||
)
|
||||
return res
|
||||
@ -579,6 +592,7 @@ def set_policy(vhost, name, pattern, definition, priority=None, runas=None):
|
||||
name,
|
||||
pattern,
|
||||
definition.replace("'", '"')),
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
log.debug('Set policy: {0}'.format(res))
|
||||
return _format_response(res, 'Set')
|
||||
@ -601,6 +615,7 @@ def delete_policy(vhost, name, runas=None):
|
||||
res = __salt__['cmd.run'](
|
||||
'rabbitmqctl clear_policy -p {0} {1}'.format(
|
||||
vhost, name),
|
||||
python_shell=False,
|
||||
runas=runas)
|
||||
log.debug('Delete policy: {0}'.format(res))
|
||||
return _format_response(res, 'Deleted')
|
||||
@ -638,7 +653,7 @@ def plugin_is_enabled(name, runas=None):
|
||||
cmd = '{0} list -m -e'.format(rabbitmq)
|
||||
if runas is None:
|
||||
runas = salt.utils.get_user()
|
||||
ret = __salt__['cmd.run'](cmd, runas=runas)
|
||||
ret = __salt__['cmd.run'](cmd, python_shell=False, runas=runas)
|
||||
return bool(name in ret)
|
||||
|
||||
|
||||
@ -657,7 +672,7 @@ def enable_plugin(name, runas=None):
|
||||
|
||||
if runas is None:
|
||||
runas = salt.utils.get_user()
|
||||
ret = __salt__['cmd.run_all'](cmd, runas=runas)
|
||||
ret = __salt__['cmd.run_all'](cmd, python_shell=False, runas=runas)
|
||||
|
||||
return _format_response(ret, 'Enabled')
|
||||
|
||||
@ -678,6 +693,6 @@ def disable_plugin(name, runas=None):
|
||||
|
||||
if runas is None:
|
||||
runas = salt.utils.get_user()
|
||||
ret = __salt__['cmd.run_all'](cmd, runas=runas)
|
||||
ret = __salt__['cmd.run_all'](cmd, python_shell=False, runas=runas)
|
||||
|
||||
return _format_response(ret, 'Disabled')
|
||||
|
@ -97,7 +97,7 @@ def _chkconfig_add(name):
|
||||
run-levels.
|
||||
'''
|
||||
cmd = '/sbin/chkconfig --add {0}'.format(name)
|
||||
if __salt__['cmd.retcode'](cmd) == 0:
|
||||
if __salt__['cmd.retcode'](cmd, python_shell=False) == 0:
|
||||
log.info('Added initscript "{0}" to chkconfig'.format(name))
|
||||
return True
|
||||
else:
|
||||
@ -130,7 +130,7 @@ def _service_is_chkconfig(name):
|
||||
Return True if the service is managed by chkconfig.
|
||||
'''
|
||||
cmdline = '/sbin/chkconfig --list {0}'.format(name)
|
||||
return __salt__['cmd.retcode'](cmdline, ignore_retcode=True) == 0
|
||||
return __salt__['cmd.retcode'](cmdline, python_shell=False, ignore_retcode=True) == 0
|
||||
|
||||
|
||||
def _sysv_is_enabled(name, runlevel=None):
|
||||
@ -156,7 +156,7 @@ def _chkconfig_is_enabled(name, runlevel=None):
|
||||
return False. If `runlevel` is None, then use the current runlevel.
|
||||
'''
|
||||
cmdline = '/sbin/chkconfig --list {0}'.format(name)
|
||||
result = __salt__['cmd.run_all'](cmdline)
|
||||
result = __salt__['cmd.run_all'](cmdline, python_shell=False)
|
||||
if result['retcode'] == 0:
|
||||
cols = result['stdout'].splitlines()[0].split()
|
||||
try:
|
||||
@ -181,7 +181,7 @@ def _sysv_enable(name):
|
||||
if not _service_is_chkconfig(name) and not _chkconfig_add(name):
|
||||
return False
|
||||
cmd = '/sbin/chkconfig {0} on'.format(name)
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
return not __salt__['cmd.retcode'](cmd, python_shell=False)
|
||||
|
||||
|
||||
def _sysv_disable(name):
|
||||
@ -194,7 +194,7 @@ def _sysv_disable(name):
|
||||
if not _service_is_chkconfig(name) and not _chkconfig_add(name):
|
||||
return False
|
||||
cmd = '/sbin/chkconfig {0} off'.format(name)
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
return not __salt__['cmd.retcode'](cmd, python_shell=False)
|
||||
|
||||
|
||||
def _upstart_services():
|
||||
@ -359,7 +359,7 @@ def start(name):
|
||||
cmd = 'start {0}'.format(name)
|
||||
else:
|
||||
cmd = '/sbin/service {0} start'.format(name)
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
return not __salt__['cmd.retcode'](cmd, python_shell=False)
|
||||
|
||||
|
||||
def stop(name):
|
||||
@ -376,7 +376,7 @@ def stop(name):
|
||||
cmd = 'stop {0}'.format(name)
|
||||
else:
|
||||
cmd = '/sbin/service {0} stop'.format(name)
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
return not __salt__['cmd.retcode'](cmd, python_shell=False)
|
||||
|
||||
|
||||
def restart(name):
|
||||
@ -393,7 +393,7 @@ def restart(name):
|
||||
cmd = 'restart {0}'.format(name)
|
||||
else:
|
||||
cmd = '/sbin/service {0} restart'.format(name)
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
return not __salt__['cmd.retcode'](cmd, python_shell=False)
|
||||
|
||||
|
||||
def reload_(name):
|
||||
@ -410,7 +410,7 @@ def reload_(name):
|
||||
cmd = 'reload {0}'.format(name)
|
||||
else:
|
||||
cmd = '/sbin/service {0} reload'.format(name)
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
return not __salt__['cmd.retcode'](cmd, python_shell=False)
|
||||
|
||||
|
||||
def status(name, sig=None):
|
||||
@ -426,11 +426,11 @@ def status(name, sig=None):
|
||||
'''
|
||||
if _service_is_upstart(name):
|
||||
cmd = 'status {0}'.format(name)
|
||||
return 'start/running' in __salt__['cmd.run'](cmd)
|
||||
return 'start/running' in __salt__['cmd.run'](cmd, python_shell=False)
|
||||
if sig:
|
||||
return bool(__salt__['status.pid'](sig))
|
||||
cmd = '/sbin/service {0} status'.format(name)
|
||||
return __salt__['cmd.retcode'](cmd, ignore_retcode=True) == 0
|
||||
return __salt__['cmd.retcode'](cmd, python_shell=False, ignore_retcode=True) == 0
|
||||
|
||||
|
||||
def enable(name, **kwargs):
|
||||
|
@ -59,7 +59,8 @@ def cluster_join(riak_user=None, riak_host=None):
|
||||
if not all((riak_user, riak_host)):
|
||||
return False
|
||||
return not bool(__salt__['cmd.retcode'](
|
||||
'riak-admin cluster join {0}@{1}'.format(riak_user, riak_host))
|
||||
'riak-admin cluster join {0}@{1}'.format(riak_user, riak_host),
|
||||
python_shell=False)
|
||||
)
|
||||
|
||||
|
||||
|
@ -54,7 +54,7 @@ def list_pkgs(*packages):
|
||||
cmd = 'rpm -q --qf \'%{{NAME}} %{{VERSION}}\\n\' {0}'.format(
|
||||
' '.join(packages)
|
||||
)
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace')
|
||||
out = __salt__['cmd.run'](cmd, python_shell=False, output_loglevel='trace')
|
||||
for line in out.splitlines():
|
||||
if 'is not installed' in line:
|
||||
errors.append(line)
|
||||
@ -92,7 +92,11 @@ def verify(*package, **kwargs):
|
||||
cmd = 'rpm -V {0}'.format(packages)
|
||||
else:
|
||||
cmd = 'rpm -Va'
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace', ignore_retcode=True)
|
||||
out = __salt__['cmd.run'](
|
||||
cmd,
|
||||
python_shell=False,
|
||||
output_loglevel='trace',
|
||||
ignore_retcode=True)
|
||||
for line in out.splitlines():
|
||||
fdict = {'mismatch': []}
|
||||
if 'missing' in line:
|
||||
@ -143,7 +147,10 @@ def file_list(*packages):
|
||||
cmd = 'rpm -qla'
|
||||
else:
|
||||
cmd = 'rpm -ql {0}'.format(' '.join(packages))
|
||||
ret = __salt__['cmd.run'](cmd, output_loglevel='trace').splitlines()
|
||||
ret = __salt__['cmd.run'](
|
||||
cmd,
|
||||
python_shell=False,
|
||||
output_loglevel='trace').splitlines()
|
||||
return {'errors': [], 'files': ret}
|
||||
|
||||
|
||||
@ -170,7 +177,7 @@ def file_dict(*packages):
|
||||
cmd = 'rpm -q --qf \'%{{NAME}} %{{VERSION}}\\n\' {0}'.format(
|
||||
' '.join(packages)
|
||||
)
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace')
|
||||
out = __salt__['cmd.run'](cmd, python_shell=False, output_loglevel='trace')
|
||||
for line in out.splitlines():
|
||||
if 'is not installed' in line:
|
||||
errors.append(line)
|
||||
@ -180,7 +187,7 @@ def file_dict(*packages):
|
||||
for pkg in pkgs:
|
||||
files = []
|
||||
cmd = 'rpm -ql {0}'.format(pkg)
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace')
|
||||
out = __salt__['cmd.run'](cmd, python_shell=False, output_loglevel='trace')
|
||||
for line in out.splitlines():
|
||||
files.append(line)
|
||||
ret[pkg] = files
|
||||
|
@ -91,7 +91,7 @@ def rsync(src,
|
||||
)
|
||||
|
||||
try:
|
||||
ret = __salt__['cmd.run_all'](cmd)
|
||||
ret = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
except (IOError, OSError) as exc:
|
||||
raise CommandExecutionError(exc.strerror)
|
||||
|
||||
@ -142,7 +142,7 @@ def config(confile='/etc/rsyncd.conf'):
|
||||
)
|
||||
|
||||
try:
|
||||
ret = __salt__['cmd.run_all'](cmd)
|
||||
ret = __salt__['cmd.run_all'](cmd, python_shell=False)
|
||||
except (IOError, OSError) as exc:
|
||||
raise CommandExecutionError(exc.strerror)
|
||||
|
||||
|
@ -39,7 +39,7 @@ def create(name, profile):
|
||||
salt <minion-id> saltcloud.create webserver rackspace_centos_512
|
||||
'''
|
||||
cmd = 'salt-cloud --out json -p {0} {1}'.format(profile, name)
|
||||
out = __salt__['cmd.run_stdout'](cmd)
|
||||
out = __salt__['cmd.run_stdout'](cmd, python_shell=False)
|
||||
try:
|
||||
ret = json.loads(out, object_hook=salt.utils.decode_dict)
|
||||
except ValueError:
|
||||
|
@ -143,7 +143,7 @@ def setsebool(boolean, value, persist=False):
|
||||
cmd = 'setsebool -P {0} {1}'.format(boolean, value)
|
||||
else:
|
||||
cmd = 'setsebool {0} {1}'.format(boolean, value)
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
return not __salt__['cmd.retcode'](cmd, python_shell=False)
|
||||
|
||||
|
||||
def setsebools(pairs, persist=False):
|
||||
@ -164,7 +164,7 @@ def setsebools(pairs, persist=False):
|
||||
cmd = 'setsebool '
|
||||
for boolean, value in pairs.items():
|
||||
cmd = '{0} {1}={2}'.format(cmd, boolean, value)
|
||||
return not __salt__['cmd.retcode'](cmd)
|
||||
return not __salt__['cmd.retcode'](cmd, python_shell=False)
|
||||
|
||||
|
||||
def list_sebool():
|
||||
|
@ -45,7 +45,7 @@ def sense(chip, fahrenheit=False):
|
||||
extra_args = ''
|
||||
if fahrenheit is True:
|
||||
extra_args = '-f'
|
||||
sensors = __salt__['cmd.run']('/usr/bin/sensors {0} {1}'.format(chip, extra_args), python_shell=True).splitlines()
|
||||
sensors = __salt__['cmd.run']('/usr/bin/sensors {0} {1}'.format(chip, extra_args), python_shell=False).splitlines()
|
||||
ret = {}
|
||||
for sensor in sensors:
|
||||
sensor_list = sensor.split(':')
|
||||
|
@ -87,7 +87,7 @@ def set_inactdays(name, inactdays):
|
||||
if inactdays == pre_info['inact']:
|
||||
return True
|
||||
cmd = 'chage -I {0} {1}'.format(inactdays, name)
|
||||
__salt__['cmd.run'](cmd)
|
||||
__salt__['cmd.run'](cmd, python_shell=False)
|
||||
post_info = info(name)
|
||||
if post_info['inact'] != pre_info['inact']:
|
||||
return post_info['inact'] == inactdays
|
||||
@ -108,7 +108,7 @@ def set_maxdays(name, maxdays):
|
||||
if maxdays == pre_info['max']:
|
||||
return True
|
||||
cmd = 'chage -M {0} {1}'.format(maxdays, name)
|
||||
__salt__['cmd.run'](cmd)
|
||||
__salt__['cmd.run'](cmd, python_shell=False)
|
||||
post_info = info(name)
|
||||
if post_info['max'] != pre_info['max']:
|
||||
return post_info['max'] == maxdays
|
||||
@ -128,7 +128,7 @@ def set_mindays(name, mindays):
|
||||
if mindays == pre_info['min']:
|
||||
return True
|
||||
cmd = 'chage -m {0} {1}'.format(mindays, name)
|
||||
__salt__['cmd.run'](cmd)
|
||||
__salt__['cmd.run'](cmd, python_shell=False)
|
||||
post_info = info(name)
|
||||
if post_info['min'] != pre_info['min']:
|
||||
return post_info['min'] == mindays
|
||||
@ -180,7 +180,7 @@ def del_password(name):
|
||||
salt '*' shadow.del_password username
|
||||
'''
|
||||
cmd = 'passwd -d {0}'.format(name)
|
||||
__salt__['cmd.run'](cmd, output_loglevel='quiet')
|
||||
__salt__['cmd.run'](cmd, python_shell=False, output_loglevel='quiet')
|
||||
uinfo = info(name)
|
||||
return not uinfo['passwd']
|
||||
|
||||
@ -235,7 +235,7 @@ def set_password(name, password, use_usermod=False):
|
||||
else:
|
||||
# Use usermod -p (less secure, but more feature-complete)
|
||||
cmd = 'usermod -p {0} {1}'.format(name, password)
|
||||
__salt__['cmd.run'](cmd, output_loglevel='quiet')
|
||||
__salt__['cmd.run'](cmd, python_shell=False, output_loglevel='quiet')
|
||||
uinfo = info(name)
|
||||
return uinfo['passwd'] == password
|
||||
|
||||
@ -255,7 +255,7 @@ def set_warndays(name, warndays):
|
||||
if warndays == pre_info['warn']:
|
||||
return True
|
||||
cmd = 'chage -W {0} {1}'.format(warndays, name)
|
||||
__salt__['cmd.run'](cmd)
|
||||
__salt__['cmd.run'](cmd, python_shell=False)
|
||||
post_info = info(name)
|
||||
if post_info['warn'] != pre_info['warn']:
|
||||
return post_info['warn'] == warndays
|
||||
@ -274,7 +274,7 @@ def set_date(name, date):
|
||||
salt '*' shadow.set_date username 0
|
||||
'''
|
||||
cmd = 'chage -d {0} {1}'.format(date, name)
|
||||
__salt__['cmd.run'](cmd)
|
||||
__salt__['cmd.run'](cmd, python_shell=False)
|
||||
|
||||
|
||||
def set_expire(name, expire):
|
||||
@ -292,4 +292,4 @@ def set_expire(name, expire):
|
||||
salt '*' shadow.set_expire username -1
|
||||
'''
|
||||
cmd = 'chage -E {0} {1}'.format(expire, name)
|
||||
__salt__['cmd.run'](cmd)
|
||||
__salt__['cmd.run'](cmd, python_shell=False)
|
||||
|
Loading…
Reference in New Issue
Block a user