Add support for merging OS::Nova::Server
authorClint Byrum <clint@fewbar.com>
Fri, 13 Sep 2013 15:42:01 +0000 (08:42 -0700)
committerClint Byrum <clint@fewbar.com>
Fri, 13 Sep 2013 16:08:53 +0000 (09:08 -0700)
Change-Id: Id6a801ee36ae73d8c2133b455e9a850c1a7b6a4d

merge.py

index 2004408..166359b 100644 (file)
--- 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: