mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Client hooks to read return data
This commit is contained in:
parent
747979b054
commit
73cffc9c4b
1 changed files with 29 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue