mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
parent
b66bbbef1e
commit
48e23ed476
@ -784,8 +784,21 @@ def _get_ssh_or_api_client(cfgfile, ssh=False):
|
|||||||
def _exec(client, tgt, fun, arg, timeout, expr_form, ret, kwarg, **kwargs):
|
def _exec(client, tgt, fun, arg, timeout, expr_form, ret, kwarg, **kwargs):
|
||||||
ret = {}
|
ret = {}
|
||||||
seen = 0
|
seen = 0
|
||||||
for ret_comp in client.cmd_iter(
|
if 'batch' in kwargs:
|
||||||
tgt, fun, arg, timeout, expr_form, ret, kwarg, **kwargs):
|
_cmd = client.cmd_batch
|
||||||
|
cmd_kwargs = {
|
||||||
|
'tgt': tgt, 'fun': fun, 'arg': arg, 'expr_form': expr_form,
|
||||||
|
'ret': ret, 'kwarg': kwarg, 'batch': kwargs['batch'],
|
||||||
|
}
|
||||||
|
del kwargs['batch']
|
||||||
|
else:
|
||||||
|
_cmd = client.cmd_iter
|
||||||
|
cmd_kwargs = {
|
||||||
|
'tgt': tgt, 'fun': fun, 'arg': arg, 'timeout': timeout,
|
||||||
|
'expr_form': expr_form, 'ret': ret, 'kwarg': kwarg,
|
||||||
|
}
|
||||||
|
cmd_kwargs.update(kwargs)
|
||||||
|
for ret_comp in _cmd(**cmd_kwargs):
|
||||||
ret.update(ret_comp)
|
ret.update(ret_comp)
|
||||||
seen += 1
|
seen += 1
|
||||||
# ret can be empty, so we cannot len the whole return dict
|
# ret can be empty, so we cannot len the whole return dict
|
||||||
@ -830,6 +843,14 @@ def cmd(tgt,
|
|||||||
client = _get_ssh_or_api_client(master_cfgfile, ssh)
|
client = _get_ssh_or_api_client(master_cfgfile, ssh)
|
||||||
ret = _exec(
|
ret = _exec(
|
||||||
client, tgt, fun, arg, timeout, expr_form, ret, kwarg, **kwargs)
|
client, tgt, fun, arg, timeout, expr_form, ret, kwarg, **kwargs)
|
||||||
|
if 'batch' in kwargs:
|
||||||
|
old_ret, ret = ret, {}
|
||||||
|
for key, value in old_ret.items():
|
||||||
|
ret[key] = {
|
||||||
|
'out': value.get('out', 'highstate') if isinstance(value, dict) else 'highstate',
|
||||||
|
'ret': value,
|
||||||
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +56,8 @@ def state(
|
|||||||
fail_minions=None,
|
fail_minions=None,
|
||||||
allow_fail=0,
|
allow_fail=0,
|
||||||
concurrent=False,
|
concurrent=False,
|
||||||
timeout=None):
|
timeout=None,
|
||||||
|
batch=None):
|
||||||
'''
|
'''
|
||||||
Invoke a state run on a given target
|
Invoke a state run on a given target
|
||||||
|
|
||||||
@ -213,6 +214,9 @@ def state(
|
|||||||
ret['result'] = False
|
ret['result'] = False
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
if batch is not None:
|
||||||
|
cmd_kw['batch'] = str(batch)
|
||||||
|
|
||||||
cmd_ret = __salt__['saltutil.cmd'](tgt, fun, **cmd_kw)
|
cmd_ret = __salt__['saltutil.cmd'](tgt, fun, **cmd_kw)
|
||||||
|
|
||||||
changes = {}
|
changes = {}
|
||||||
@ -300,7 +304,8 @@ def function(
|
|||||||
fail_function=None,
|
fail_function=None,
|
||||||
arg=None,
|
arg=None,
|
||||||
kwarg=None,
|
kwarg=None,
|
||||||
timeout=None):
|
timeout=None,
|
||||||
|
batch=None):
|
||||||
'''
|
'''
|
||||||
Execute a single module function on a remote minion via salt or salt-ssh
|
Execute a single module function on a remote minion via salt or salt-ssh
|
||||||
|
|
||||||
@ -360,6 +365,9 @@ def function(
|
|||||||
elif not tgt_type and not expr_form:
|
elif not tgt_type and not expr_form:
|
||||||
tgt_type = 'glob'
|
tgt_type = 'glob'
|
||||||
|
|
||||||
|
if batch is not None:
|
||||||
|
cmd_kw['batch'] = str(batch)
|
||||||
|
|
||||||
cmd_kw['expr_form'] = tgt_type
|
cmd_kw['expr_form'] = tgt_type
|
||||||
cmd_kw['ssh'] = ssh
|
cmd_kw['ssh'] = ssh
|
||||||
cmd_kw['expect_minions'] = expect_minions
|
cmd_kw['expect_minions'] = expect_minions
|
||||||
@ -371,6 +379,7 @@ def function(
|
|||||||
).format(fun, tgt, str(False))
|
).format(fun, tgt, str(False))
|
||||||
ret['result'] = None
|
ret['result'] = None
|
||||||
return ret
|
return ret
|
||||||
|
cmd_ret = __salt__['saltutil.cmd'](tgt, fun, **cmd_kw)
|
||||||
try:
|
try:
|
||||||
cmd_ret = __salt__['saltutil.cmd'](tgt, fun, **cmd_kw)
|
cmd_ret = __salt__['saltutil.cmd'](tgt, fun, **cmd_kw)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
Loading…
Reference in New Issue
Block a user