Merge pull request #14706 from alejansa/add_compact_output

Adds compact output method.
This commit is contained in:
Thomas S Hatch 2014-08-04 11:06:25 -06:00
commit c51580e63b

34
salt/output/compact.py Normal file
View File

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
'''
Display compact output data structure
=================================
Example output::
'saltdev': {'test_|-always-passes_|-foo_|-succeed_without_changes': {'comment': 'Success!', 'name': 'foo', 'start_time': '05:16:26.111814', 'result': True, 'duration': 1, '__run_num__': 0, 'changes': {}}, 'test_|-my-custom-combo_|-foo_|-configurable_test_state': {'comment': 'bar.baz', 'name': 'foo', 'start_time': '05:16:26.117177', 'result': False, 'duration': 1, '__run_num__': 4, 'changes': {'testing': {'new': 'Something pretended to change', 'old': 'Unchanged'}}}, 'test_|-always-fails_|-foo_|-fail_without_changes': {'comment': 'Failure!', 'name': 'foo', 'start_time': '05:16:26.113124', 'result': False, 'duration': 1, '__run_num__': 1, 'changes': {}}, 'test_|-always-changes-and-succeeds_|-foo_|-succeed_with_changes': {'comment': 'Success!', 'name': 'foo', 'start_time': '05:16:26.114570', 'result': True, 'duration': 0, '__run_num__': 2, 'changes': {'testing': {'new': 'Something pretended to change', 'old': 'Unchanged'}}}, 'test_|-always-changes-and-fails_|-foo_|-fail_with_changes': {'comment': 'Failure!', 'name': 'foo', 'start_time': '05:16:26.115561', 'result': False, 'duration': 1, '__run_num__': 3, 'changes': {'testing': {'new': 'Something pretended to change', 'old': 'Unchanged'}}}}}
{'myminion': {'foo': {'list': ['Hello', 'World'], 'bar': 'baz', 'dictionary': {'abc': 123, 'def': 456}}}}
'''
from highstate import output as _output
def output(data):
'''
Rather basic....
'''
tmp = {}
for min in data.keys():
for process in data[min].keys():
add = False
if data[min][process]['result'] == False:
add = True
elif data[min][process]['changes'] != {} :
add = True
if add == True:
if not tmp.has_key(min):
tmp[min] = {process:data[min][process]}
else:
tmp[min][process]={process:data[min][process]}
return _output(tmp)