Updating all instances of check_minions.

This commit is contained in:
Gareth J. Greenaway 2017-08-14 09:01:08 -07:00
parent fcf61844d5
commit 96e8b90d1e
12 changed files with 45 additions and 48 deletions

View file

@ -122,9 +122,10 @@ class SaltCP(object):
if gzip \
else salt.utils.itertools.read_file
minions = salt.utils.minions.CkMinions(self.opts).check_minions(
_res = salt.utils.minions.CkMinions(self.opts).check_minions(
tgt,
tgt_type=selected_target_option or 'glob')
minions = _res['minions']
local = salt.client.get_local_client(self.opts['conf_file'])

View file

@ -348,7 +348,8 @@ class LocalClient(object):
return self._check_pub_data(pub_data)
def gather_minions(self, tgt, expr_form):
return salt.utils.minions.CkMinions(self.opts).check_minions(tgt, tgt_type=expr_form)
_res = salt.utils.minions.CkMinions(self.opts).check_minions(tgt, tgt_type=expr_form)
return _res['minions']
@tornado.gen.coroutine
def run_job_async(

View file

@ -585,11 +585,12 @@ class RemoteFuncs(object):
if match_type.lower() == 'compound':
match_type = 'compound_pillar_exact'
checker = salt.utils.minions.CkMinions(self.opts)
minions = checker.check_minions(
_res = checker.check_minions(
load['tgt'],
match_type,
greedy=False
)
minions = _res['minions']
for minion in minions:
fdata = self.cache.fetch('minions/{0}'.format(minion), 'mine')
if isinstance(fdata, dict):
@ -908,9 +909,10 @@ class RemoteFuncs(object):
pub_load['tgt_type'] = load['tgt_type']
ret = {}
ret['jid'] = self.local.cmd_async(**pub_load)
ret['minions'] = self.ckminions.check_minions(
_res = self.ckminions.check_minions(
load['tgt'],
pub_load['tgt_type'])
ret['minions'] = _res['minions']
auth_cache = os.path.join(
self.opts['cachedir'],
'publish_auth')
@ -1203,11 +1205,12 @@ class LocalFuncs(object):
# Retrieve the minions list
delimiter = load.get('kwargs', {}).get('delimiter', DEFAULT_TARGET_DELIM)
minions = self.ckminions.check_minions(
_res = self.ckminions.check_minions(
load['tgt'],
load.get('tgt_type', 'glob'),
delimiter
)
minions = _res['minions']
# Check for external auth calls
if extra.get('token', False):

View file

@ -167,7 +167,8 @@ def ext_pillar(minion_id,
opts['target'] = match.group(1)
temp = temp.replace(match.group(0), '')
checker = salt.utils.minions.CkMinions(__opts__)
minions = checker.check_minions(opts['target'], 'compound')
_res = checker.check_minions(opts['target'], 'compound')
minions = _res['minions']
if minion_id not in minions:
return {}

View file

@ -336,9 +336,10 @@ def ext_pillar(minion_id,
if (os.path.isdir(nodegroups_dir) and
nodegroup in master_ngroups):
ckminions = salt.utils.minions.CkMinions(__opts__)
match = ckminions.check_minions(
_res = ckminions.check_minions(
master_ngroups[nodegroup],
'compound')
match = _res['minions']
if minion_id in match:
ngroup_dir = os.path.join(
nodegroups_dir, str(nodegroup))

View file

@ -64,9 +64,10 @@ def ext_pillar(minion_id, pillar, pillar_name=None):
ckminions = None
for nodegroup_name in six.iterkeys(all_nodegroups):
ckminions = ckminions or CkMinions(__opts__)
match = ckminions.check_minions(
_res = ckminions.check_minions(
all_nodegroups[nodegroup_name],
'compound')
match = _res['minions']
if minion_id in match:
nodegroups_minion_is_in.append(nodegroup_name)

View file

@ -223,10 +223,11 @@ def save_load(jid, clear_load, minion=None):
if 'tgt' in clear_load and clear_load['tgt'] != '':
ckminions = salt.utils.minions.CkMinions(__opts__)
# Retrieve the minions list
minions = ckminions.check_minions(
_res = ckminions.check_minions(
clear_load['tgt'],
clear_load.get('tgt_type', 'glob')
)
minions = _res['minions']
save_minions(jid, minions)

View file

@ -225,10 +225,11 @@ def save_load(jid, clear_load, minions=None, recurse_count=0):
if minions is None:
ckminions = salt.utils.minions.CkMinions(__opts__)
# Retrieve the minions list
minions = ckminions.check_minions(
_res = ckminions.check_minions(
clear_load['tgt'],
clear_load.get('tgt_type', 'glob')
)
minions = _res['minions']
# save the minions to a cache so we can see in the UI
save_minions(jid, minions)

View file

@ -117,7 +117,8 @@ def targets(tgt, tgt_type='glob', **kwargs): # pylint: disable=W0613
The resulting roster can be configured using ``roster_order`` and ``roster_default``.
'''
minions = salt.utils.minions.CkMinions(__opts__)
minions = minions.check_minions(tgt, tgt_type)
_res = minions.check_minions(tgt, tgt_type)
minions = _res['minions']
ret = {}
if not minions:

View file

@ -827,8 +827,9 @@ class ZeroMQPubServerChannel(salt.transport.server.PubServerChannel):
match_targets = ["pcre", "glob", "list"]
if self.opts['zmq_filtering'] and load['tgt_type'] in match_targets:
# Fetch a list of minions that match
match_ids = self.ckminions.check_minions(load['tgt'],
tgt_type=load['tgt_type'])
_res = self.ckminions.check_minions(load['tgt'],
tgt_type=load['tgt_type'])
match_ids = _res['minions']
log.debug("Publish Side Match: {0}".format(match_ids))
# Send list of miions thru so zmq can target them

View file

@ -248,7 +248,8 @@ class MasterPillarUtil(object):
# Return a list of minion ids that match the target and tgt_type
minion_ids = []
ckminions = salt.utils.minions.CkMinions(self.opts)
minion_ids = ckminions.check_minions(self.tgt, self.tgt_type)
_res = ckminions.check_minions(self.tgt, self.tgt_type)
minion_ids = _res['minions']
if len(minion_ids) == 0:
log.debug('No minions matched for tgt="{0}" and tgt_type="{1}"'.format(self.tgt, self.tgt_type))
return {}

View file

@ -208,17 +208,9 @@ class CkMinions(object):
'''
Return the minions found by looking via a list
'''
import inspect
curframe = inspect.currentframe()
calframe = inspect.getouterframes(curframe, 2)
log.debug('=== {} called _check_list_minions ==='.format(calframe[1][3]))
if isinstance(expr, six.string_types):
expr = [m for m in expr.split(',') if m]
log.debug('== expr {} =='.format(expr))
minions = self._pki_minions()
log.debug('== missing {} =='.format([x for x in expr if x not in minions]))
#return [x for x in expr if x in minions]
return {'minions': [x for x in expr if x in minions],
'missing': [x for x in expr if x not in minions]}
@ -458,11 +450,6 @@ class CkMinions(object):
'''
Return the minions found by looking via compound matcher
'''
import inspect
curframe = inspect.currentframe()
calframe = inspect.getouterframes(curframe, 2)
log.debug('=== {} called _check_compound_minions ==='.format(calframe[1][3]))
if not isinstance(expr, six.string_types) and not isinstance(expr, (list, tuple)):
log.error('Compound target that is neither string, list nor tuple')
return {'minions': list(), 'missing': list()}
@ -571,13 +558,8 @@ class CkMinions(object):
engine_args.append(greedy)
_results = engine(*engine_args)
log.debug('== _results from engine {} =='.format(_results))
#results.append(str(set(engine(*engine_args))))
results.append(str(set(_results['minions'])))
missing.extend(_results['missing'])
log.debug('=== extending missing {} ==='.format(missing))
log.debug('== results {} =='.format(results))
log.debug('== missing {} =='.format(missing))
if unmatched and unmatched[-1] == '-':
results.append(')')
unmatched.pop()
@ -585,9 +567,7 @@ class CkMinions(object):
else:
# The match is not explicitly defined, evaluate as a glob
_results = self._check_glob_minions(word, True)
log.debug('=== running glob here {} ==='.format(_results))
results.append(str(set(_results['minions'])))
log.debug('=== results after glob {} ==='.format(results))
if unmatched and unmatched[-1] == '-':
results.append(')')
unmatched.pop()
@ -671,13 +651,7 @@ class CkMinions(object):
match the regex, this will then be used to parse the returns to
make sure everyone has checked back in.
'''
import inspect
curframe = inspect.currentframe()
calframe = inspect.getouterframes(curframe, 2)
log.debug('=== {} called check_minions ==='.format(calframe[1][3]))
log.debug('=== tgt_type {} ==='.format(tgt_type))
missing = []
try:
if expr is None:
expr = ''
@ -697,7 +671,6 @@ class CkMinions(object):
'Failed matching available minions with {0} pattern: {1}'
.format(tgt_type, expr))
_res = {'minions': list(), 'missing': list()}
log.debug('== inside check_minions, returning _res {} =='.format(_res))
return _res
def _expand_matching(self, auth_entry):
@ -718,7 +691,8 @@ class CkMinions(object):
v_matcher = ref.get(target_info['engine'])
v_expr = target_info['pattern']
return set(self.check_minions(v_expr, v_matcher))
_res = self.check_minions(v_expr, v_matcher)
return set(_res['minions'])
def validate_tgt(self, valid, expr, tgt_type, minions=None, expr_form=None):
'''
@ -738,7 +712,8 @@ class CkMinions(object):
v_minions = self._expand_matching(valid)
if minions is None:
minions = set(self.check_minions(expr, tgt_type))
_res = self.check_minions(expr, tgt_type)
minions = set(_res['minions'])
else:
minions = set(minions)
d_bool = not bool(minions.difference(v_minions))
@ -827,8 +802,12 @@ class CkMinions(object):
v_tgt_type = 'pillar_exact'
elif tgt_type.lower() == 'compound':
v_tgt_type = 'compound_pillar_exact'
v_minions = set(self.check_minions(tgt, v_tgt_type))
minions = set(self.check_minions(tgt, tgt_type))
_res = self.check_minions(tgt, v_tgt_type)
v_minions = set(_res['minions'])
_res = self.check_minions(tgt, tgt_type)
minions = set(_res['minions'])
mismatch = bool(minions.difference(v_minions))
# If the non-exact match gets more minions than the exact match
# then pillar globbing or PCRE is being used, and we have a
@ -915,8 +894,12 @@ class CkMinions(object):
v_tgt_type = 'pillar_exact'
elif tgt_type.lower() == 'compound':
v_tgt_type = 'compound_pillar_exact'
v_minions = set(self.check_minions(tgt, v_tgt_type))
minions = set(self.check_minions(tgt, tgt_type))
_res = self.check_minions(tgt, v_tgt_type)
v_minions = set(_res['minions'])
_res = self.check_minions(tgt, tgt_type)
minions = set(_res['minions'])
mismatch = bool(minions.difference(v_minions))
# If the non-exact match gets more minions than the exact match
# then pillar globbing or PCRE is being used, and we have a
@ -1138,9 +1121,10 @@ def mine_get(tgt, fun, tgt_type='glob', opts=None):
ret = {}
serial = salt.payload.Serial(opts)
checker = CkMinions(opts)
minions = checker.check_minions(
_res = checker.check_minions(
tgt,
tgt_type)
minions = _res['minions']
cache = salt.cache.factory(opts)
for minion in minions:
mdata = cache.fetch('minions/{0}'.format(minion), 'mine')