mirror of
https://github.com/valitydev/salt.git
synced 2024-11-06 16:45:27 +00:00
Add in command query structure
This commit is contained in:
parent
21c9287855
commit
a8ec3697c7
@ -38,6 +38,20 @@ class SaltCMD(object):
|
||||
action='store_true'
|
||||
help='Instead of using shell globs to evaluate the target'\
|
||||
+ ' servers, use pcre regular expressions')
|
||||
parser.add_option('-Q',
|
||||
'--query',
|
||||
dest='query',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Execute a salt command query, this can be used to find'\
|
||||
+ ' previous function calls, of to look up a call that'\
|
||||
+ ' occured at a specific time.')
|
||||
parser.add_option('-c',
|
||||
'--cmd',
|
||||
dest='cmd',
|
||||
default='',
|
||||
help='Used with the Query option, pass in the command to get'\
|
||||
+ ' results from.')
|
||||
|
||||
options, args = parser.parse_args()
|
||||
|
||||
@ -45,9 +59,13 @@ class SaltCMD(object):
|
||||
|
||||
opts['timeout'] = options.timeout
|
||||
opts['pcre'] = options.pcre
|
||||
opts['tgt'] = args[0]
|
||||
opts['fun'] = args[1]
|
||||
opts['arg'] = args[2:]
|
||||
if options.query:
|
||||
opts['query'] = options.query
|
||||
opts['cmd'] = options.cmd
|
||||
else:
|
||||
opts['tgt'] = args[0]
|
||||
opts['fun'] = args[1]
|
||||
opts['arg'] = args[2:]
|
||||
|
||||
return opts
|
||||
|
||||
@ -55,6 +73,8 @@ class SaltCMD(object):
|
||||
'''
|
||||
Execute the salt command line
|
||||
'''
|
||||
if opts['query']:
|
||||
cli =
|
||||
local = salt.client.LocalClient()
|
||||
args = [self.opts['tgt'],
|
||||
self.opts['fun'],
|
||||
|
@ -117,6 +117,34 @@ class LocalClient(object):
|
||||
return ret
|
||||
time.sleep(0.02)
|
||||
|
||||
def find_cmd(self, cmd):
|
||||
'''
|
||||
Hunt through the old salt calls for when cmd was run, return a dict:
|
||||
{'<jid>': <return_obj>}
|
||||
'''
|
||||
job_dir = os.path.join(self.opts['cachedir'], 'jobs')
|
||||
ret = {}
|
||||
for jid in os.listdir(job_dir):
|
||||
jid_dir = os.path.join(job_dir, jid)
|
||||
loadp = os.path.join(jid_dir, '.load.p')
|
||||
if os.path.isfile(loadp):
|
||||
try:
|
||||
load = pickle.load(open(loadp, 'r'))
|
||||
if load['fun'] == cmd:
|
||||
# We found a match! Add the return values
|
||||
ret[jid] = {}
|
||||
for host in os.listdir(jid_dir):
|
||||
host_dir = os.path.join(jid_dir, host)
|
||||
retp = os.path.join(host_dir, 'return.p')
|
||||
if not os.path.isfile(retp):
|
||||
continue
|
||||
ret[jid][host] = pickle.load(open(retp))
|
||||
except:
|
||||
continue
|
||||
else:
|
||||
continue
|
||||
return ret
|
||||
|
||||
def check_minions(self, expr, expr_form='glob'):
|
||||
'''
|
||||
Check the passed regex against the available minions' public
|
||||
|
Loading…
Reference in New Issue
Block a user