Add ability to combine roles into one role.

This commit is contained in:
Clint Byrum 2013-05-14 11:19:43 -07:00
parent 621a4dd9ca
commit d5e511f945
6 changed files with 31 additions and 3 deletions

View File

@ -48,6 +48,7 @@ Resources:
InstanceType: {Ref: InstanceType}
KeyName: {Ref: KeyName}
Metadata:
OpenStack::Role: stateless
OpenStack::ImageBuilder::Elements: [ glance ]
heat:
access_key_id:

View File

@ -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:

View File

@ -38,6 +38,7 @@ Resources:
InstanceType: {Ref: InstanceType}
KeyName: {Ref: KeyName}
Metadata:
OpenStack::Role: stateless
OpenStack::ImageBuilder::Elements: [ keystone ]
heat:
access_key_id:

View File

@ -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', {}):

View File

@ -51,6 +51,7 @@ Resources:
InstanceType: {Ref: InstanceType}
KeyName: {Ref: KeyName}
Metadata:
OpenStack::Role: networking
OpenStack::ImageBuilder::Elements: [ quantum ]
heat:
access_key_id:

View 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: