Updating error messages to be more clear when beacons are configured in pillar. Updating the list to ensure the parameters are clear.

This commit is contained in:
Gareth J. Greenaway 2017-10-16 14:30:37 -07:00
parent 2738a124fe
commit 00063e8fc7
No known key found for this signature in database
GPG key ID: 10B62F8A7CAD7A41
3 changed files with 32 additions and 24 deletions

View file

@ -218,21 +218,19 @@ class Beacon(object):
beacons.update(opts_beacons)
return beacons
def list_beacons(self, where=None):
def list_beacons(self,
include_pillar=True,
include_opts=True):
'''
List the beacon items
where: Whether to include beacon data from, either opts
or pillar, default is None which would include data
from both.
include_pillar: Whether to include beacons that are
configured in pillar, default is True.
include_opts: Whether to include beacons that are
configured in opts, default is True.
'''
if where == 'pillar':
beacons = self._get_beacons(include_opts=False)
elif where == 'opts':
beacons = self._get_beacons(include_pillar=False)
else:
beacons = self._get_beacons()
beacons = self._get_beacons(include_pillar, include_opts)
# Fire the complete event back along with the list of beacons
evt = salt.utils.event.get_event('minion', opts=self.opts)
@ -290,7 +288,7 @@ class Beacon(object):
if name in self._get_beacons(include_opts=False):
comment = 'Cannot update beacon item {0}, ' \
'it is in pillar.'.format(name)
'because it is configured in pillar.'.format(name)
complete = False
else:
if name in self.opts['beacons']:
@ -319,7 +317,7 @@ class Beacon(object):
if name in self._get_beacons(include_opts=False):
comment = 'Cannot modify beacon item {0}, ' \
'it is in pillar.'.format(name)
'it is configured in pillar.'.format(name)
complete = False
else:
comment = 'Updating settings for beacon ' \
@ -342,7 +340,7 @@ class Beacon(object):
if name in self._get_beacons(include_opts=False):
comment = 'Cannot delete beacon item {0}, ' \
'it is in pillar.'.format(name)
'it is configured in pillar.'.format(name)
complete = False
else:
if name in self.opts['beacons']:
@ -395,7 +393,7 @@ class Beacon(object):
if name in self._get_beacons(include_opts=False):
comment = 'Cannot enable beacon item {0}, ' \
'it is in pillar.'.format(name)
'it is configured in pillar.'.format(name)
complete = False
else:
self._update_enabled(name, True)
@ -417,7 +415,7 @@ class Beacon(object):
if name in self._get_beacons(include_opts=False):
comment = 'Cannot disable beacon item {0}, ' \
'it is in pillar.'.format(name)
'it is configured in pillar.'.format(name)
complete = False
else:
self._update_enabled(name, False)

View file

@ -2063,7 +2063,8 @@ class Minion(MinionBase):
func = data.get(u'func', None)
name = data.get(u'name', None)
beacon_data = data.get(u'beacon_data', None)
where = data.get(u'where', None)
include_pillar = data.get(u'include_pillar', None)
include_opts = data.get(u'include_opts', None)
if func == u'add':
self.beacons.add_beacon(name, beacon_data)
@ -2080,7 +2081,7 @@ class Minion(MinionBase):
elif func == u'disable_beacon':
self.beacons.disable_beacon(name)
elif func == u'list':
self.beacons.list_beacons(where)
self.beacons.list_beacons(include_opts, include_pillar)
elif func == u'list_available':
self.beacons.list_available_beacons()
elif func == u'validate_beacon':

View file

@ -28,14 +28,22 @@ __func_alias__ = {
}
def list_(return_yaml=True, where=None):
def list_(return_yaml=True,
include_pillar=True,
include_opts=True):
'''
List the beacons currently configured on the minion
:param return_yaml: Whether to return YAML formatted output, default True
:param where: Return beacon data from opts or pillar, default is
None which will return data from opts and pillar.
:return: List of currently configured Beacons.
:param return_yaml: Whether to return YAML formatted output,
default True
:param include_pillar: Whether to include beacons that are
configured in pillar, default is True.
:param include_opts: Whether to include beacons that are
configured in opts, default is True.
:return: List of currently configured Beacons.
CLI Example:
@ -49,7 +57,8 @@ def list_(return_yaml=True, where=None):
try:
eventer = salt.utils.event.get_event('minion', opts=__opts__)
res = __salt__['event.fire']({'func': 'list',
'where': where},
'include_pillar': include_pillar,
'include_opts': include_opts},
'manage_beacons')
if res:
event_ret = eventer.get_event(tag='/salt/minion/minion_beacons_list_complete', wait=30)
@ -343,7 +352,7 @@ def save():
ret = {'comment': [],
'result': True}
beacons = list_(return_yaml=False, where='opts')
beacons = list_(return_yaml=False, include_pillar=False)
# move this file into an configurable opt
sfn = '{0}/{1}/beacons.conf'.format(__opts__['config_dir'],