From a8d5dc5a23bf8a681ab5695b421f04a17547d65c Mon Sep 17 00:00:00 2001
From: Clint Byrum <clint@fewbar.com>
Date: Fri, 13 Sep 2013 08:42:01 -0700
Subject: [PATCH] Add support for merging OS::Nova::Server

Change-Id: Id6a801ee36ae73d8c2133b455e9a850c1a7b6a4d
---
 merge.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/merge.py b/merge.py
index 2004408768..166359bdda 100644
--- a/merge.py
+++ b/merge.py
@@ -44,6 +44,11 @@ def resolve_params(item, param, value):
         item = new_item
     return item
 
+MERGABLE_TYPES = {'OS::Nova::Server':
+                  {'image': 'image'},
+                  'AWS::EC2::Instance':
+                  {'image': 'ImageId'},
+                 }
 
 errors = []
 end_template={'HeatTemplateFormatVersion': '2012-12-12',
@@ -77,10 +82,11 @@ for template_path in templates:
 
     new_resources = template.get('Resources', {})
     for r, rbody in sorted(new_resources.items()):
-        if rbody['Type'] == 'AWS::EC2::Instance':
+        if rbody['Type'] in MERGABLE_TYPES:
+            image_key = MERGABLE_TYPES[rbody['Type']]['image']
             # XXX Assuming ImageId is always a Ref
-            ikey_val = end_template['Parameters'][rbody['Properties']['ImageId']['Ref']]
-            del end_template['Parameters'][rbody['Properties']['ImageId']['Ref']]
+            ikey_val = end_template['Parameters'][rbody['Properties'][image_key]['Ref']]
+            del end_template['Parameters'][rbody['Properties'][image_key]['Ref']]
             role = rbody.get('Metadata', {}).get('OpenStack::Role', r)
             role = translate_role(role)
             if role != r:
@@ -102,7 +108,7 @@ for template_path in templates:
                 end_template['Resources'] = {}
             end_template['Resources'][role] = rbody
             ikey = '%sImage' % (role)
-            end_template['Resources'][role]['Properties']['ImageId'] = {'Ref': ikey}
+            end_template['Resources'][role]['Properties'][image_key] = {'Ref': ikey}
             end_template['Parameters'][ikey] = ikey_val
         elif rbody['Type'] == 'FileInclude':
             with open(rbody['Path']) as rfile: