switching the list function in the beacon execution module to use an event to retrieve the list of beacons to ensure consistency when using salt vs salt-call

This commit is contained in:
Gareth J. Greenaway 2015-05-19 11:13:32 -07:00
parent 31680c71e0
commit 5d60c0ff22
3 changed files with 27 additions and 4 deletions

View file

@ -96,6 +96,17 @@ class Beacon(object):
self.interval_map[mod] = 1
return False
def list_beacons(self):
'''
List the beacon items
'''
# Fire the complete event back along with the list of beacons
evt = salt.utils.event.get_event('minion', opts=self.opts)
evt.fire_event({'complete': True, 'beacons': self.opts['beacons']},
tag='/salt/minion/minion_beacons_list_complete')
return True
def add_beacon(self, name, beacon_data):
'''
Add a beacon item

View file

@ -1371,6 +1371,8 @@ class Minion(MinionBase):
self.beacons.enable_beacon(name)
elif func == 'disable_beacon':
self.beacons.disable_beacon(name)
elif func == 'list':
self.beacons.list_beacons()
def environ_setenv(self, package):
'''

View file

@ -34,10 +34,20 @@ def list_(return_yaml=True):
'''
if 'beacons' in __opts__:
beacons = __opts__['beacons'].copy()
else:
return {'beacons': {}}
try:
eventer = salt.utils.event.get_event('minion', opts=__opts__)
res = __salt__['event.fire']({'func': 'list'}, 'manage_beacons')
if res:
event_ret = eventer.get_event(tag='/salt/minion/minion_beacons_list_complete', wait=30)
log.debug('event_ret {0}'.format(event_ret))
if event_ret and event_ret['complete']:
beacons = event_ret['beacons']
except KeyError:
# Effectively a no-op, since we can't really return without an event system
ret = {}
ret['result'] = False
ret['comment'] = 'Event module not available. Beacon add failed.'
return ret
if beacons:
if return_yaml: