1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
16
from heat.common import template_format
17
from heat.engine import stack_resource
18
from heat.openstack.common import log as logging
20
logger = logging.getLogger(__name__)
24
"AWSTemplateFormatVersion": "2010-09-09",
25
"Description": "Builtin RDS::DBInstance",
39
"MasterUserPassword" : {
43
"AllocatedStorage" : {
47
"DBSecurityGroups" : {
48
"Type": "CommaDelimitedList",
62
"DBInstanceToInstance" : {
63
"db.m1.small": {"Instance": "m1.small"},
64
"db.m1.large": {"Instance": "m1.large"},
65
"db.m1.xlarge": {"Instance": "m1.xlarge"},
66
"db.m2.xlarge": {"Instance": "m2.xlarge"},
67
"db.m2.2xlarge": {"Instance": "m2.2xlarge"},
68
"db.m2.4xlarge": {"Instance": "m2.4xlarge"}
75
"Type": "AWS::EC2::Instance",
77
"AWS::CloudFormation::Init": {
87
"mysqld" : { "enabled" : "true", "ensureRunning" : "true" }
94
"ImageId": "F17-x86_64-cfntools",
95
"InstanceType": { "Fn::FindInMap": [ "DBInstanceToInstance",
96
{ "Ref": "DBInstanceClass" },
98
"KeyName": { "Ref": "KeyName" },
99
"UserData": { "Fn::Base64": { "Fn::Join": ["", [
101
"# Helper function\n",
102
"function error_exit\n",
104
" /opt/aws/bin/cfn-signal -e 1 -r \"$1\" '",
105
{ "Ref" : "WaitHandle" }, "'\n",
109
"/opt/aws/bin/cfn-init -s ", { "Ref" : "AWS::StackName" },
110
" -r DatabaseInstance",
111
" --region ", { "Ref" : "AWS::Region" },
112
" || error_exit 'Failed to run cfn-init'\n",
113
"# Setup MySQL root password and create a user\n",
114
"mysqladmin -u root password '", {"Ref":"MasterUserPassword"},"'\n",
115
"cat << EOF | mysql -u root --password='",
116
{ "Ref" : "MasterUserPassword" }, "'\n",
117
"CREATE DATABASE ", { "Ref" : "DBName" }, ";\n",
118
"GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" },
119
".* TO \"", { "Ref" : "MasterUsername" }, "\"@\"%\"\n",
120
"IDENTIFIED BY \"", { "Ref" : "MasterUserPassword" }, "\";\n",
121
"FLUSH PRIVILEGES;\n",
124
"# Database setup completed, signal success\n",
125
"/opt/aws/bin/cfn-signal -e 0 -r \"MySQL server setup complete\" '",
126
{ "Ref" : "WaitHandle" }, "'\n"
133
"Type" : "AWS::CloudFormation::WaitConditionHandle"
137
"Type" : "AWS::CloudFormation::WaitCondition",
138
"DependsOn" : "DatabaseInstance",
140
"Handle" : {"Ref" : "WaitHandle"},
152
class DBInstance(stack_resource.StackResource):
154
properties_schema = {
155
'DBSnapshotIdentifier': {'Type': 'String',
156
'Implemented': False},
157
'AllocatedStorage': {'Type': 'String',
159
'AvailabilityZone': {'Type': 'String',
160
'Implemented': False},
161
'BackupRetentionPeriod': {'Type': 'String',
162
'Implemented': False},
163
'DBInstanceClass': {'Type': 'String',
165
'DBName': {'Type': 'String',
167
'DBParameterGroupName': {'Type': 'String',
168
'Implemented': False},
169
'DBSecurityGroups': {'Type': 'List',
170
'Required': False, 'Default': []},
171
'DBSubnetGroupName': {'Type': 'String',
172
'Implemented': False},
173
'Engine': {'Type': 'String',
174
'AllowedValues': ['MySQL'],
176
'EngineVersion': {'Type': 'String',
177
'Implemented': False},
178
'LicenseModel': {'Type': 'String',
179
'Implemented': False},
180
'MasterUsername': {'Type': 'String',
182
'MasterUserPassword': {'Type': 'String',
184
'Port': {'Type': 'String',
187
'PreferredBackupWindow': {'Type': 'String',
188
'Implemented': False},
189
'PreferredMaintenanceWindow': {'Type': 'String',
190
'Implemented': False},
191
'MultiAZ': {'Type': 'Boolean',
192
'Implemented': False},
195
# We only support a couple of the attributes right now
196
attributes_schema = {
197
"Endpoint.Address": "Connection endpoint for the database.",
198
"Endpoint.Port": ("The port number on which the database accepts "
204
'KeyName': {'Ref': 'KeyName'},
207
# Add the DBInstance parameters specified in the user's template
208
# Ignore the not implemented ones
209
for key, value in self.properties_schema.items():
210
if value.get('Implemented', True) and key != 'Engine':
211
# There is a mismatch between the properties "List" format
212
# and the parameters "CommaDelimitedList" format, so we need
213
# to translate lists into the expected comma-delimited form
214
if isinstance(self.properties[key], list):
215
params[key] = ','.join(self.properties[key])
217
params[key] = self.properties[key]
218
p = self.stack.resolve_static_data(params)
221
def handle_create(self):
222
templ = template_format.parse(mysql_template)
223
return self.create_with_template(templ, self._params())
225
def handle_delete(self):
226
return self.delete_nested()
228
def _resolve_attribute(self, name):
230
We don't really support any of these yet.
232
if name == 'Endpoint.Address':
233
if self.nested() and 'DatabaseInstance' in self.nested().resources:
234
return self.nested().resources['DatabaseInstance']._ipaddress()
237
elif name == 'Endpoint.Port':
238
return self.properties['Port']
241
def resource_mapping():
243
'AWS::RDS::DBInstance': DBInstance,