Make LaunchConfiguration resources mergeable

This can be very useful for merging of Metadata to be used
by optional services (e. g. to add services like tuskar to
undercloud on demand).

Change-Id: Ifc4016d6e994064c0772c12e668e98bf055fada9
This commit is contained in:
Roman Podolyaka 2013-10-11 17:54:09 +03:00
parent 8e36320284
commit fcbead3871
5 changed files with 98 additions and 8 deletions

View File

@ -0,0 +1,23 @@
Parameters:
A:
Type: String
Default: test1
B:
Type: String
Default: test2
resource1Image:
Type: String
Default: resource1
Resources:
notcomputeConfigBase:
Type: AWS::AutoScaling::LaunchConfiguration
Metadata:
OpenStack::Role: notcomputeConfig
a: {Ref: A}
b: {Ref: B}
resource1:
Type: OS::Nova::Server
Properties:
flavor: test_flavor
image: {Ref: resource1Image}
key_name: test_key

View File

@ -0,0 +1,19 @@
Parameters:
C:
Type: String
Default: test3
resource2Image:
Type: String
Default: resource2
Resources:
notcomputeConfigMixin:
Type: AWS::AutoScaling::LaunchConfiguration
Metadata:
OpenStack::Role: notcomputeConfig
c: {Ref: C}
resource2:
Type: OS::Nova::Server
Properties:
flavor: test_flavor
image: {Ref: resource2Image}
key_name: test_key

View File

@ -0,0 +1,43 @@
Description: examples/launchconfig1.yaml,examples/launchconfig2.yaml
HeatTemplateFormatVersion: '2012-12-12'
Parameters:
A:
Default: test1
Type: String
B:
Default: test2
Type: String
C:
Default: test3
Type: String
resource1Image:
Default: resource1
Type: String
resource2Image:
Default: resource2
Type: String
Resources:
notcomputeConfig:
Metadata:
OpenStack::Role: notcomputeConfig
a:
Ref: A
b:
Ref: B
c:
Ref: C
Type: AWS::AutoScaling::LaunchConfiguration
resource1:
Properties:
flavor: test_flavor
image:
Ref: resource1Image
key_name: test_key
Type: OS::Nova::Server
resource2:
Properties:
flavor: test_flavor
image:
Ref: resource2Image
key_name: test_key
Type: OS::Nova::Server

View File

@ -48,6 +48,8 @@ MERGABLE_TYPES = {'OS::Nova::Server':
{'image': 'image'}, {'image': 'image'},
'AWS::EC2::Instance': 'AWS::EC2::Instance':
{'image': 'ImageId'}, {'image': 'ImageId'},
'AWS::AutoScaling::LaunchConfiguration':
{},
} }
@ -119,6 +121,7 @@ for template_path in templates:
new_resources = template.get('Resources', {}) new_resources = template.get('Resources', {})
for r, rbody in sorted(new_resources.items()): for r, rbody in sorted(new_resources.items()):
if rbody['Type'] in MERGABLE_TYPES: if rbody['Type'] in MERGABLE_TYPES:
if 'image' in MERGABLE_TYPES[rbody['Type']]:
image_key = MERGABLE_TYPES[rbody['Type']]['image'] image_key = MERGABLE_TYPES[rbody['Type']]['image']
# XXX Assuming ImageId is always a Ref # XXX Assuming ImageId is always a Ref
ikey_val = end_template['Parameters'][rbody['Properties'][image_key]['Ref']] ikey_val = end_template['Parameters'][rbody['Properties'][image_key]['Ref']]
@ -143,6 +146,7 @@ for template_path in templates:
if 'Resources' not in end_template: if 'Resources' not in end_template:
end_template['Resources'] = {} end_template['Resources'] = {}
end_template['Resources'][role] = rbody end_template['Resources'][role] = rbody
if 'image' in MERGABLE_TYPES[rbody['Type']]:
ikey = '%sImage' % (role) ikey = '%sImage' % (role)
end_template['Resources'][role]['Properties'][image_key] = {'Ref': ikey} end_template['Resources'][role]['Properties'][image_key] = {'Ref': ikey}
end_template['Parameters'][ikey] = ikey_val end_template['Parameters'][ikey] = ikey_val

View File

@ -26,6 +26,7 @@ echo
run_test "python merge.py examples/source.yaml" examples/source_lib_result.yaml run_test "python merge.py examples/source.yaml" examples/source_lib_result.yaml
run_test "python merge.py examples/source2.yaml" examples/source2_lib_result.yaml run_test "python merge.py examples/source2.yaml" examples/source2_lib_result.yaml
run_test "python merge.py examples/source_include_subkey.yaml" examples/source_include_subkey_result.yaml run_test "python merge.py examples/source_include_subkey.yaml" examples/source_include_subkey_result.yaml
run_test "python merge.py examples/launchconfig1.yaml examples/launchconfig2.yaml" examples/launchconfig_result.yaml
echo echo
trap - EXIT trap - EXIT
exit $fail exit $fail