Added List of minions that ran a particular job to the job list cache data returned by runners

runner.jobs.list_jobs
runner.jobs.list_job

Also added function runner.jobs.list_job to list a single job given by jid
This commit is contained in:
Samuel M Smith 2013-10-01 17:21:45 -06:00
parent a97f51deee
commit 2fa941c473
4 changed files with 52 additions and 7 deletions

View File

@ -130,7 +130,7 @@ class APIClient(object):
'''
return self.localClient.run_job(**kwargs)
def minion_sync(self, *args, **kwargs):
def minion_sync(self, **kwargs):
'''
Wrap LocalClient for running :ref:`execution modules <all-salt.modules>`

View File

@ -2359,6 +2359,11 @@ class ClearFuncs(object):
clear_load,
salt.utils.fopen(os.path.join(jid_dir, '.load.p'), 'w+')
)
# save the minions to a cache so we can see in the UI
self.serial.dump(
minions,
salt.utils.fopen(os.path.join(jid_dir, '.minions.p'), 'w+')
)
if self.opts['ext_job_cache']:
try:
fstr = '{0}.save_load'.format(self.opts['ext_job_cache'])

View File

@ -30,7 +30,7 @@ class RunnerClient(object):
self.opts = opts
self.functions = salt.loader.runner(opts)
def _proc_runner(self, tag, fun, low, user):
def _proc_runner(self, fun, low, user, tag, jid):
'''
Run this method in a multiprocess target to execute the runner in a
multiprocess and fire the return data on the event bus
@ -38,7 +38,7 @@ class RunnerClient(object):
salt.utils.daemonize()
event = salt.utils.event.MasterEvent(self.opts['sock_dir'])
data = {'fun': "runner.{0}".format(fun),
'jid': low['jid'],
'jid': jid,
'user': user,
}
event.fire_event(data, tagify('new', base=tag))
@ -101,12 +101,12 @@ class RunnerClient(object):
'''
jid = '{0:%Y%m%d%H%M%S%f}'.format(datetime.datetime.now())
tag = tagify(jid, prefix='run')
low['tag'] = tag
low['jid'] = jid
#low['tag'] = tag
#low['jid'] = jid
proc = multiprocessing.Process(
target=self._proc_runner,
args=(tag, fun, low, user))
args=(fun, low, user, tag, jid))
proc.start()
return tag

View File

@ -97,6 +97,40 @@ def lookup_jid(jid, ext_source=None):
return ret
def list_job(jid):
'''
List a specific job given by its jid
CLI Example:
.. code-block:: bash
salt-run jobs.list_job 20130916125524463507
'''
serial = salt.payload.Serial(__opts__)
ret = {}
jid_dir = salt.utils.jid_dir(jid, __opts__['cachedir'], __opts__['hash_type'])
loadpath = os.path.join(jid_dir, '.load.p')
minionspath = os.path.join(jid_dir, '.minions.p')
if os.path.isfile(loadpath):
load = serial.load(salt.utils.fopen(loadpath, 'rb'))
jid = load['jid']
ret = { 'jid': jid,
'Start Time': salt.utils.jid_to_time(jid),
'Function': load['fun'],
'Arguments': list(load['arg']),
'Target': load['tgt'],
'Target-type': load['tgt_type'],
'User': load.get('user', 'root')}
if os.path.isfile(minionspath):
minions = serial.load(salt.utils.fopen(minionspath, 'rb'))
ret['Minions'] = minions
salt.output.display_output(ret, 'yaml', __opts__)
return ret
def list_jobs():
'''
List all detectable jobs and associated functions
@ -114,16 +148,22 @@ def list_jobs():
t_path = os.path.join(job_dir, top)
for final in os.listdir(t_path):
loadpath = os.path.join(t_path, final, '.load.p')
minionspath = os.path.join(t_path, final, '.minions.p')
if not os.path.isfile(loadpath):
continue
load = serial.load(salt.utils.fopen(loadpath, 'rb'))
jid = load['jid']
ret[jid] = {'Start Time': salt.utils.jid_to_time(jid),
ret[jid] = {'jid': jid,
'Start Time': salt.utils.jid_to_time(jid),
'Function': load['fun'],
'Arguments': list(load['arg']),
'Target': load['tgt'],
'Target-type': load['tgt_type'],
'User': load.get('user', 'root')}
if os.path.isfile(minionspath):
minions = serial.load(salt.utils.fopen(minionspath, 'rb'))
ret[jid]['Minions'] = minions
salt.output.display_output(ret, 'yaml', __opts__)
return ret