From 70494ab2cb75e7f7ca83a169eac823b22eb6e180 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Thu, 20 Feb 2014 17:14:43 +1300 Subject: 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 --- tripleo_heat_merge/merge.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tripleo_heat_merge') 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): -- cgit 1.2.3-korg