Support the new list configuration format.

Refs #38121

Conflicts:
  - salt/beacons/status.py
This commit is contained in:
Pedro Algarvio 2017-03-09 19:20:22 +00:00 committed by rallytime
parent be06df9b64
commit c7fc09f97d

View file

@ -117,34 +117,43 @@ def beacon(config):
ctime = datetime.datetime.utcnow().isoformat()
if len(config) < 1:
config = {
config = [{
'loadavg': ['all'],
'cpustats': ['all'],
'meminfo': ['all'],
'vmstats': ['all'],
'time': ['all'],
}
}]
if not isinstance(config, list):
# To support the old dictionary config format
config = [config]
ret = {}
for func in config:
try:
data = __salt__['status.{0}'.format(func)]()
except salt.exceptions.CommandExecutionError as exc:
log.debug('Status beacon attempted to process function {0} \
but encountered error: {1}'.format(func, exc))
continue
ret[func] = {}
for item in config[func]:
if item == 'all':
ret[func] = data
for entry in config:
for func in entry:
ret[func] = {}
try:
data = __salt__['status.{0}'.format(func)]()
except salt.exceptions.CommandExecutionError as exc:
log.debug('Status beacon attempted to process function {0} '
'but encountered error: {1}'.format(func, exc))
continue
if not isinstance(entry[func], list):
func_items = [entry[func]]
else:
try:
func_items = entry[func]
for item in func_items:
if item == 'all':
ret[func] = data
else:
try:
ret[func][item] = data[item]
except TypeError:
ret[func][item] = data[int(item)]
except KeyError as exc:
ret[func] = 'Status beacon is incorrectly configured: {0}'.format(exc)
try:
ret[func][item] = data[item]
except TypeError:
ret[func][item] = data[int(item)]
except KeyError as exc:
ret[func] = 'Status beacon is incorrectly configured: {0}'.format(exc)
return [{
'tag': ctime,