mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
parent
d826be13e8
commit
881fa2a7d3
@ -9,6 +9,7 @@ import os
|
|||||||
import salt.client
|
import salt.client
|
||||||
import salt.payload
|
import salt.payload
|
||||||
import salt.utils
|
import salt.utils
|
||||||
|
from salt.exceptions import SaltException
|
||||||
|
|
||||||
# Import Third party libs
|
# Import Third party libs
|
||||||
import yaml
|
import yaml
|
||||||
@ -55,12 +56,13 @@ def lookup_jid(jid):
|
|||||||
Return the printout from a previousely executed job
|
Return the printout from a previousely executed job
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
out = None
|
||||||
|
|
||||||
def _format_ret(full_ret):
|
def _format_ret(full_ret):
|
||||||
'''
|
'''
|
||||||
Take the full return data and format it to simple output
|
Take the full return data and format it to simple output
|
||||||
'''
|
'''
|
||||||
ret = {}
|
ret = {}
|
||||||
out = ''
|
|
||||||
for key, data in full_ret.items():
|
for key, data in full_ret.items():
|
||||||
ret[key] = data['ret']
|
ret[key] = data['ret']
|
||||||
if 'out' in data:
|
if 'out' in data:
|
||||||
@ -69,17 +71,24 @@ def lookup_jid(jid):
|
|||||||
|
|
||||||
client = salt.client.LocalClient(__opts__['conf_file'])
|
client = salt.client.LocalClient(__opts__['conf_file'])
|
||||||
full_ret = client.get_full_returns(jid, [], 0)
|
full_ret = client.get_full_returns(jid, [], 0)
|
||||||
ret, out = _format_ret(full_ret)
|
formatted = _format_ret(full_ret)
|
||||||
|
|
||||||
|
if formatted:
|
||||||
|
ret = formatted[0]
|
||||||
|
out = formatted[1]
|
||||||
|
else:
|
||||||
|
ret = SaltException('Job {0} hasn\'t finished. No data yet :('.format(jid))
|
||||||
|
out = ''
|
||||||
|
|
||||||
# Determine the proper output method and run it
|
# Determine the proper output method and run it
|
||||||
get_outputter = salt.output.get_outputter
|
get_outputter = salt.output.get_outputter
|
||||||
if isinstance(ret, list) or isinstance(ret, dict):
|
if isinstance(ret, (list, dict, basestring)) and out:
|
||||||
if out:
|
printout = get_outputter(out)
|
||||||
printout = get_outputter(out)
|
|
||||||
else:
|
|
||||||
printout = get_outputter(None)
|
|
||||||
# Pretty print any salt exceptions
|
# Pretty print any salt exceptions
|
||||||
elif isinstance(ret, SaltException):
|
elif isinstance(ret, SaltException):
|
||||||
printout = get_outputter("txt")
|
printout = get_outputter("txt")
|
||||||
|
else:
|
||||||
|
printout = get_outputter(None)
|
||||||
printout(ret)
|
printout(ret)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user