Add ability to combine roles into one role.
authorClint Byrum <clint@fewbar.com>
Tue, 14 May 2013 18:19:43 +0000 (11:19 -0700)
committerClint Byrum <clint@fewbar.com>
Thu, 6 Jun 2013 16:25:27 +0000 (09:25 -0700)
glance.yaml
heat.yaml
keystone.yaml
merge.py
quantum.yaml
rabbitmq.yaml

index af75b22..b5c0079 100644 (file)
@@ -48,6 +48,7 @@ Resources:
       InstanceType: {Ref: InstanceType}
       KeyName: {Ref: KeyName}
     Metadata:
+      OpenStack::Role: stateless
       OpenStack::ImageBuilder::Elements: [ glance ]
       heat: 
         access_key_id:
index 4c64983..770a648 100644 (file)
--- a/heat.yaml
+++ b/heat.yaml
@@ -83,7 +83,6 @@ Resources:
         {Ref: HeatApiImage}
       InstanceType: {Ref: InstanceType}
       KeyName: {Ref: KeyName}
-      UserData: "#!/bin/bash\ntouch /tmp/userdata-finished\necho Userdata finished $(date)\n"
   HeatAPI:
     Type: OS::Heat::InstanceGroup
     Properties:
index 5c55c11..e4b96d7 100644 (file)
@@ -38,6 +38,7 @@ Resources:
       InstanceType: {Ref: InstanceType}
       KeyName: {Ref: KeyName}
     Metadata:
+      OpenStack::Role: stateless
       OpenStack::ImageBuilder::Elements: [ keystone ]
       heat: 
         access_key_id:
index b1443f2..e0a5645 100644 (file)
--- a/merge.py
+++ b/merge.py
@@ -1,7 +1,33 @@
 import sys
 import yaml
+import argparse
 
-templates = list(sys.argv[1:])
+parser = argparse.ArgumentParser()
+parser.add_argument('templates', nargs='+')
+parser.add_argument('--master-role', nargs='?',
+                    help='Translate slave_roles to this')
+parser.add_argument('--slave-roles', nargs='*',
+                    help='Translate all of these to master_role')
+
+args = parser.parse_args()
+
+templates = args.templates
+
+def _translate_role(role):
+    global args
+    if not args.master_role:
+        return role
+    if role == args.master_role:
+        return role
+    if role not in args.slave_roles:
+        return role
+    return args.master_role
+
+def translate_role(role):
+    r = _translate_role(role)
+    if not isinstance(r, basestring):
+        raise Exception('%s -> %r' % (role, r))
+    return r
 
 errors = []
 end_template={'HeatTemplateFormatVersion': '2012-12-12',
@@ -39,6 +65,7 @@ for template_path in templates:
             # XXX Assuming ImageId is always a Ref
             del end_template['Parameters'][rbody['Properties']['ImageId']['Ref']]
             role = rbody.get('Metadata', {}).get('OpenStack::Role', r)
+            role = translate_role(role)
             if role != r:
                 resource_changes.append((r, role))
             if role in end_template.get('Resources', {}):
index c7eaed0..bc08f01 100644 (file)
@@ -51,6 +51,7 @@ Resources:
       InstanceType: {Ref: InstanceType}
       KeyName: {Ref: KeyName}
     Metadata:
+      OpenStack::Role: networking
       OpenStack::ImageBuilder::Elements: [ quantum ]
       heat: 
         access_key_id:
index 701f2d0..d8fdb5f 100644 (file)
@@ -24,7 +24,6 @@ Resources:
         {Ref: RabbitMQImage}
       InstanceType: {Ref: InstanceType}
       KeyName: {Ref: KeyName}
-      UserData: "#!/bin/bash\ntouch /tmp/userdata-finished\necho Userdata finished $(date)\n"
   RabbitMQPasswordHandle:
     Type: AWS::CloudFormation::WaitConditionHandle
   RabbitMQPassword: