Client hooks to read return data

This commit is contained in:
Thomas S Hatch 2011-03-08 17:24:05 -07:00
parent 747979b054
commit 73cffc9c4b

View file

@ -27,6 +27,8 @@ The data structurte needs to be:
import os
import re
import time
import cPickle as pickle
# Import zmq modules
import zmq
@ -57,6 +59,33 @@ class LocalClient(object):
except:
raise SaltClientError('Failed to read in the salt root key')
def cmd(self, tgt, fun, arg=(), timeout=5):
'''
Execute a salt command and return.
'''
pub_data = self.pub(tgt, fun, arg)
return get_returns(pub_data['jid'], pub_data['minions'], timeout)
def get_returns(self, jid, minions, timeout=5):
'''
This method starts off a watcher looking at the return data for a
specified jid
'''
jid_dir = os.path.join(self.opts['cachedir'], 'jobs', jid)
start = int(time.time())
ret = {}
# Wait for the hosts to check in
while True:
for fn_ in os.listdir(jid_dir):
if not ret.has_key(fn_):
ret[fn_] = pickle.loads(open(os.path.join(jid_dir),
fn_, 'return.p'), 'r')
if len(ret) >= len(minions):
return ret
if int(time.time()) > start + timeout:
return ret
time.sleep(0.02)
def check_minions(self, expr):
'''
Check the passed regex against the available minions' public