add batch to orchestrate runner

closes #12556
This commit is contained in:
Daniel Wallace 2015-08-16 01:49:39 -05:00
parent b66bbbef1e
commit 48e23ed476
2 changed files with 34 additions and 4 deletions

View File

@ -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):
ret = {}
seen = 0
for ret_comp in client.cmd_iter(
tgt, fun, arg, timeout, expr_form, ret, kwarg, **kwargs):
if 'batch' in 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)
seen += 1
# 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)
ret = _exec(
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

View File

@ -56,7 +56,8 @@ def state(
fail_minions=None,
allow_fail=0,
concurrent=False,
timeout=None):
timeout=None,
batch=None):
'''
Invoke a state run on a given target
@ -213,6 +214,9 @@ def state(
ret['result'] = False
return ret
if batch is not None:
cmd_kw['batch'] = str(batch)
cmd_ret = __salt__['saltutil.cmd'](tgt, fun, **cmd_kw)
changes = {}
@ -300,7 +304,8 @@ def function(
fail_function=None,
arg=None,
kwarg=None,
timeout=None):
timeout=None,
batch=None):
'''
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:
tgt_type = 'glob'
if batch is not None:
cmd_kw['batch'] = str(batch)
cmd_kw['expr_form'] = tgt_type
cmd_kw['ssh'] = ssh
cmd_kw['expect_minions'] = expect_minions
@ -371,6 +379,7 @@ def function(
).format(fun, tgt, str(False))
ret['result'] = None
return ret
cmd_ret = __salt__['saltutil.cmd'](tgt, fun, **cmd_kw)
try:
cmd_ret = __salt__['saltutil.cmd'](tgt, fun, **cmd_kw)
except Exception as exc: