mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Make salt-call register to the job cache
This commit is contained in:
parent
36d1405fd0
commit
ec17974661
@ -47,13 +47,23 @@ class Caller(object):
|
|||||||
'''
|
'''
|
||||||
ret = {}
|
ret = {}
|
||||||
fun = self.opts['fun']
|
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:
|
if fun not in self.minion.functions:
|
||||||
sys.stderr.write('Function {0} is not available\n'.format(fun))
|
sys.stderr.write('Function {0} is not available\n'.format(fun))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
try:
|
try:
|
||||||
args, kw = salt.minion.detect_kwargs(
|
args, kw = salt.minion.detect_kwargs(
|
||||||
self.minion.functions[fun], self.opts['arg'])
|
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)
|
ret['return'] = self.minion.functions[fun](*args, **kw)
|
||||||
except (TypeError, CommandExecutionError) as exc:
|
except (TypeError, CommandExecutionError) as exc:
|
||||||
msg = 'Error running \'{0}\': {1}\n'
|
msg = 'Error running \'{0}\': {1}\n'
|
||||||
@ -67,20 +77,22 @@ class Caller(object):
|
|||||||
msg = 'Command required for \'{0}\' not found: {1}\n'
|
msg = 'Command required for \'{0}\' not found: {1}\n'
|
||||||
sys.stderr.write(msg.format(fun, str(exc)))
|
sys.stderr.write(msg.format(fun, str(exc)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
try:
|
||||||
|
os.remove(proc_fn)
|
||||||
|
except (IOError, OSError):
|
||||||
|
pass
|
||||||
if hasattr(self.minion.functions[fun], '__outputter__'):
|
if hasattr(self.minion.functions[fun], '__outputter__'):
|
||||||
oput = self.minion.functions[fun].__outputter__
|
oput = self.minion.functions[fun].__outputter__
|
||||||
if isinstance(oput, string_types):
|
if isinstance(oput, string_types):
|
||||||
ret['out'] = oput
|
ret['out'] = oput
|
||||||
if self.opts.get('return', ''):
|
if self.opts.get('return', ''):
|
||||||
ret['id'] = self.opts['id']
|
ret['id'] = self.opts['id']
|
||||||
ret['jid'] = '{0:%Y%m%d%H%M%S%f}'.format(datetime.datetime.now())
|
|
||||||
ret['fun'] = fun
|
ret['fun'] = fun
|
||||||
for returner in self.opts['return'].split(','):
|
for returner in self.opts['return'].split(','):
|
||||||
try:
|
try:
|
||||||
self.minion.returners['{0}.returner'.format(returner)](ret)
|
self.minion.returners['{0}.returner'.format(returner)](ret)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def print_docs(self):
|
def print_docs(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user