jobs.exit_success allow to check if a job has executed and exit successfully

This commit is contained in:
Pablo Suárez Hernández 2016-05-24 09:21:43 +01:00
parent c8b4f338d8
commit 7ba40c4f31

View file

@ -488,6 +488,48 @@ def print_job(jid, ext_source=None, outputter=None):
return ret
def exit_success(jid, ext_source=None):
'''
Check if a job has been executed and exit successfully
jid
The jid to look up.
ext_source
The external job cache to use. Default: `None`.
CLI Example:
.. code-block:: bash
salt-run jobs.exit_success 20160520145827701627
'''
ret = {}
mminion = salt.minion.MasterMinion(__opts__)
returner = _get_returner((
__opts__['ext_job_cache'],
ext_source,
__opts__['master_job_cache']
))
try:
data = list_job(
jid,
ext_source=ext_source
)
except TypeError:
return ('Requested returner could not be loaded. '
'No JIDs could be retrieved.')
returns = data.get('Result', {})
for minion in returns:
minion_ret = returns[minion].get('return', {})
if minion_ret['retcode'] == 0:
ret[minion] = True
else:
ret[minion] = False
return ret
def last_run(ext_source=None,
outputter=None,
metadata=None,