aboutsummaryrefslogtreecommitdiffstats
path: root/tripleo_heat_merge
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2014-02-20 17:14:43 +1300
committerRobert Collins <rbtcollins@hp.com>2014-02-21 11:13:10 +1300
commit70494ab2cb75e7f7ca83a169eac823b22eb6e180 (patch)
treea39f0002c980c07f8b5b283bde414d2720f8a95e /tripleo_heat_merge
parent8403b8ae9fd7eef452fe7cd96df814e195fea916 (diff)
Add a Merge::Map feature.
We need to scatter gather in a few situations - determining rabbit cluster membership, galera membership and configuring hosts for Nova to permit live migration (which requires host->host communication). This patch is a proof of concept for an eventual heat feature, expressed in merge.py. The example given should work for actual use, but I'll deliver that change separately. Change-Id: I68e9b2471866810cc698ca3ea28ddf5bb1688d7b
Diffstat (limited to 'tripleo_heat_merge')
-rw-r--r--tripleo_heat_merge/merge.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tripleo_heat_merge/merge.py b/tripleo_heat_merge/merge.py
index dd254ab4..0de27e24 100644
--- a/tripleo_heat_merge/merge.py
+++ b/tripleo_heat_merge/merge.py
@@ -4,6 +4,27 @@ import yaml
import argparse
+def apply_maps(template):
+ """Apply Merge::Map within template.
+
+ Any dict {'Merge::Map': {'Foo': 'Bar', 'Baz': 'Quux'}}
+ will resolve to ['Bar', 'Quux'] - that is a dict with key
+ 'Merge::Map' is replaced entirely by that dict['Merge::Map'].values().
+ """
+ if isinstance(template, dict):
+ if 'Merge::Map' in template:
+ return sorted(
+ apply_maps(value) for value in template['Merge::Map'].values()
+ )
+ else:
+ return dict((key, apply_maps(value))
+ for key, value in template.items())
+ elif isinstance(template, list):
+ return [apply_maps(item) for item in template]
+ else:
+ return template
+
+
def apply_scaling(template, scaling, in_copies=None):
"""Apply a set of scaling operations to template.
@@ -301,6 +322,7 @@ def merge(templates, master_role=None, slave_roles=None,
end_template['Resources'][r] = rbody
end_template = apply_scaling(end_template, scaling)
+ end_template = apply_maps(end_template)
def fix_ref(item, old, new):
if isinstance(item, dict):