summaryrefslogtreecommitdiffstats
path: root/filter_plugins
diff options
context:
space:
mode:
authorLénaïc Huard <lhuard@amadeus.com>2015-06-25 10:08:52 +0200
committerLénaïc Huard <lhuard@amadeus.com>2015-07-15 17:48:38 +0200
commit4b439253e7b4486947d201714d4f52a4a7e0fc01 (patch)
tree3f73f7b7f904a35ceb22b93998c076a3c9adf00d /filter_plugins
parenta1fe1b25b588ba995192b99e44a7950ee0c6e032 (diff)
downloadopenshift-4b439253e7b4486947d201714d4f52a4a7e0fc01.tar.gz
openshift-4b439253e7b4486947d201714d4f52a4a7e0fc01.tar.bz2
openshift-4b439253e7b4486947d201714d4f52a4a7e0fc01.tar.xz
openshift-4b439253e7b4486947d201714d4f52a4a7e0fc01.zip
Make all the OpenStack resources be managed by a Heat Stack
Diffstat (limited to 'filter_plugins')
-rw-r--r--filter_plugins/oo_filters.py72
1 files changed, 71 insertions, 1 deletions
diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py
index 4e4a7309d..cd197c0fe 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):
@@ -232,6 +234,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 {
@@ -245,5 +314,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
}