Make salt-call register to the job cache

This commit is contained in:
Thomas S Hatch 2012-11-13 23:00:30 -07:00
parent 36d1405fd0
commit ec17974661

View File

@ -47,13 +47,23 @@ class Caller(object):
'''
ret = {}
fun = self.opts['fun']
ret['jid'] = '{0:%Y%m%d%H%M%S%f}'.format(datetime.datetime.now())
proc_fn = os.path.join(
salt.minion.get_proc_dir(self.opts['cachedir']),
data['jid'])
if fun not in self.minion.functions:
sys.stderr.write('Function {0} is not available\n'.format(fun))
sys.exit(1)
try:
args, kw = salt.minion.detect_kwargs(
self.minion.functions[fun], self.opts['arg'])
sdata = {
'fun': fun,
'pid': os.getpid(),
'jid': ret['jid'],
'tgt': 'salt-call'}
with open(proc_fn, 'w+') as fp_:
fp_.write(self.serial.dumps(sdata))
ret['return'] = self.minion.functions[fun](*args, **kw)
except (TypeError, CommandExecutionError) as exc:
msg = 'Error running \'{0}\': {1}\n'
@ -67,20 +77,22 @@ class Caller(object):
msg = 'Command required for \'{0}\' not found: {1}\n'
sys.stderr.write(msg.format(fun, str(exc)))
sys.exit(1)
try:
os.remove(proc_fn)
except (IOError, OSError):
pass
if hasattr(self.minion.functions[fun], '__outputter__'):
oput = self.minion.functions[fun].__outputter__
if isinstance(oput, string_types):
ret['out'] = oput
if self.opts.get('return', ''):
ret['id'] = self.opts['id']
ret['jid'] = '{0:%Y%m%d%H%M%S%f}'.format(datetime.datetime.now())
ret['fun'] = fun
for returner in self.opts['return'].split(','):
try:
self.minion.returners['{0}.returner'.format(returner)](ret)
except Exception as exc:
pass
return ret
def print_docs(self):