diff options
author | Thomas Wiest <twiest@users.noreply.github.com> | 2015-07-16 14:00:52 -0400 |
---|---|---|
committer | Thomas Wiest <twiest@users.noreply.github.com> | 2015-07-16 14:00:52 -0400 |
commit | e0211ca67ce18fc9f74d0a9c82cf14a28f395e4d (patch) | |
tree | 1f349f91d3c20baab4b29b7b3207ca29e0801816 /filter_plugins | |
parent | adce78d68470b341b761372a70d06b5aec88de06 (diff) | |
parent | 4b439253e7b4486947d201714d4f52a4a7e0fc01 (diff) | |
download | openshift-e0211ca67ce18fc9f74d0a9c82cf14a28f395e4d.tar.gz openshift-e0211ca67ce18fc9f74d0a9c82cf14a28f395e4d.tar.bz2 openshift-e0211ca67ce18fc9f74d0a9c82cf14a28f395e4d.tar.xz openshift-e0211ca67ce18fc9f74d0a9c82cf14a28f395e4d.zip |
Merge pull request #315 from lhuard1A/all_os_in_heat
Make all the OpenStack resources be managed by a Heat Stack
Diffstat (limited to 'filter_plugins')
-rw-r--r-- | filter_plugins/oo_filters.py | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py index aeeeb4b68..18229631c 100644 --- a/filter_plugins/oo_filters.py +++ b/filter_plugins/oo_filters.py @@ -8,6 +8,8 @@ Custom filters for use in openshift-ansible from ansible import errors from operator import itemgetter import pdb +import re +import json class FilterModule(object): @@ -239,6 +241,73 @@ class FilterModule(object): rval.append({string: value}) return rval + @staticmethod + def oo_parse_heat_stack_outputs(data): + ''' Formats the HEAT stack output into a usable form + + The goal is to transform something like this: + + +---------------+-------------------------------------------------+ + | Property | Value | + +---------------+-------------------------------------------------+ + | capabilities | [] | | + | creation_time | 2015-06-26T12:26:26Z | | + | description | OpenShift cluster | | + | … | … | + | outputs | [ | + | | { | + | | "output_value": "value_A" | + | | "description": "This is the value of Key_A" | + | | "output_key": "Key_A" | + | | }, | + | | { | + | | "output_value": [ | + | | "value_B1", | + | | "value_B2" | + | | ], | + | | "description": "This is the value of Key_B" | + | | "output_key": "Key_B" | + | | }, | + | | ] | + | parameters | { | + | … | … | + +---------------+-------------------------------------------------+ + + into something like this: + + { + "Key_A": "value_A", + "Key_B": [ + "value_B1", + "value_B2" + ] + } + ''' + + # Extract the “outputs” JSON snippet from the pretty-printed array + in_outputs = False + outputs = '' + + line_regex = re.compile(r'\|\s*(.*?)\s*\|\s*(.*?)\s*\|') + for line in data['stdout_lines']: + match = line_regex.match(line) + if match: + if match.group(1) == 'outputs': + in_outputs = True + elif match.group(1) != '': + in_outputs = False + if in_outputs: + outputs += match.group(2) + + outputs = json.loads(outputs) + + # Revamp the “outputs” to put it in the form of a “Key: value” map + revamped_outputs = {} + for output in outputs: + revamped_outputs[output['output_key']] = output['output_value'] + + return revamped_outputs + def filters(self): ''' returns a mapping of filters to methods ''' return { @@ -252,5 +321,6 @@ class FilterModule(object): "oo_combine_key_value": self.oo_combine_key_value, "oo_split": self.oo_split, "oo_filter_list": self.oo_filter_list, - "oo_build_zabbix_list_dict": self.oo_build_zabbix_list_dict + "oo_build_zabbix_list_dict": self.oo_build_zabbix_list_dict, + "oo_parse_heat_stack_outputs": self.oo_parse_heat_stack_outputs } |