mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
tweaking to be able to use beacon module & state module to manage custom beacons
This commit is contained in:
parent
4d174746f9
commit
d5abd98406
3 changed files with 31 additions and 0 deletions
|
@ -214,6 +214,29 @@ class Beacon(object):
|
|||
|
||||
return True
|
||||
|
||||
def validate_beacon(self, name, beacon_data):
|
||||
'''
|
||||
Return available beacon functions
|
||||
'''
|
||||
validate_str = '{}.validate'
|
||||
# Run the validate function if it's available,
|
||||
# otherwise there is a warning about it being missing
|
||||
if validate_str in self.beacons:
|
||||
valid, vcomment = self.beacons[validate_str](b_config[mod])
|
||||
|
||||
if not valid:
|
||||
log.info('Beacon %s configuration invalid, '
|
||||
'not running.\n%s', mod, vcomment)
|
||||
continue
|
||||
|
||||
# Fire the complete event back along with the list of beacons
|
||||
evt = salt.utils.event.get_event('minion', opts=self.opts)
|
||||
log.debug('=== self.beacons {} ==='.format(list(self.beacons)))
|
||||
evt.fire_event({'complete': True, 'beacons': list(self.beacons)},
|
||||
tag='/salt/minion/minion_available_beacons')
|
||||
|
||||
return True
|
||||
|
||||
def add_beacon(self, name, beacon_data):
|
||||
'''
|
||||
Add a beacon item
|
||||
|
|
|
@ -1930,6 +1930,8 @@ class Minion(MinionBase):
|
|||
self.beacons.disable_beacon(name)
|
||||
elif func == u'list':
|
||||
self.beacons.list_beacons()
|
||||
elif func == u'validate_beacon':
|
||||
self.beacons.validate_beacon(name, beacon_data)
|
||||
|
||||
def environ_setenv(self, tag, data):
|
||||
'''
|
||||
|
|
|
@ -97,6 +97,12 @@ def add(name, beacon_data, **kwargs):
|
|||
else:
|
||||
# Attempt to load the beacon module so we have access to the validate function
|
||||
try:
|
||||
eventer = salt.utils.event.get_event('minion', opts=__opts__)
|
||||
res = __salt__['event.fire']({'name': name, 'func': 'available_beacons'}, 'manage_beacons')
|
||||
if res:
|
||||
event_ret = eventer.get_event(tag='/salt/minion/minion_available_beacons', wait=30)
|
||||
log.debug('=== event_ret {} ==='.format(event_ret))
|
||||
|
||||
beacon_module = __import__('salt.beacons.' + name, fromlist=['validate'])
|
||||
log.debug('Successfully imported beacon.')
|
||||
except ImportError:
|
||||
|
|
Loading…
Add table
Reference in a new issue