Merge pull request #33828 from eyj/manage_target

Fixed manage.down for targeting subset of nodes
This commit is contained in:
Mike Place 2016-06-08 06:32:43 -07:00
commit 6846547d68

View File

@ -34,6 +34,30 @@ FINGERPRINT_REGEX = re.compile(r'^([a-f0-9]{2}:){15}([a-f0-9]{2})$')
log = logging.getLogger(__name__)
def _ping(tgt, expr_form, timeout):
client = salt.client.get_local_client(__opts__['conf_file'])
pub_data = client.run_job(tgt, 'test.ping', (), expr_form, '', timeout, '')
if not pub_data:
return pub_data
returned = set()
for fn_ret in client.get_cli_event_returns(
pub_data['jid'],
pub_data['minions'],
client._get_timeout(timeout),
tgt,
expr_form):
if fn_ret:
for mid, _ in six.iteritems(fn_ret):
returned.add(mid)
not_returned = set(pub_data['minions']) - returned
return list(returned), list(not_returned)
def status(output=True, tgt='*', expr_form='glob'):
'''
Print the status of all known salt minions
@ -46,18 +70,7 @@ def status(output=True, tgt='*', expr_form='glob'):
salt-run manage.status tgt="webservers" expr_form="nodegroup"
'''
ret = {}
client = salt.client.get_local_client(__opts__['conf_file'])
try:
minions = client.cmd(tgt, 'test.ping', timeout=__opts__['timeout'],
expr_form=expr_form)
except SaltClientError as client_error:
print(client_error)
return ret
key = salt.key.Key(__opts__)
keys = key.list_keys()
ret['up'] = sorted(minions)
ret['down'] = sorted(set(keys['minions']) - set(minions))
ret['up'], ret['down'] = _ping(tgt, expr_form, __opts__['timeout'])
return ret