'Implemented': False}
}
- def _params(self):
- # total hack - probably need an admin key here.
- params = {'KeyName': {'Ref': 'KeyName'}}
- p = self.stack.resolve_static_data(params)
- return p
-
def _instance_to_ipaddress(self, inst):
'''
Return the server's IP address, fetching it from Nova
cfg = self._haproxy_config(templ, self.properties['Instances'])
files['/etc/haproxy/haproxy.cfg']['content'] = cfg
- self.create_with_template(templ)
+ # total hack - probably need an admin key here.
+ param = self.stack.resolve_static_data({'KeyName': {'Ref': 'KeyName'}})
+
+ self.create_with_template(templ, param)
def validate(self):
'''
key=key)
if key == 'DNSName':
- return stack.Stack.FnGetAtt(self, 'Outputs.PublicIp')
+ return self.get_output('PublicIp')
else:
return ''
class Stack(resource.Resource):
- properties_schema = {PROP_TEMPLATE_URL: {'Type': 'String',
- 'Required': True},
- PROP_TIMEOUT_MINS: {'Type': 'Number'},
- PROP_PARAMETERS: {'Type': 'Map'}}
-
def __init__(self, name, json_snippet, stack):
super(Stack, self).__init__(name, json_snippet, stack)
self._nested = None
- def _params(self):
- p = self.stack.resolve_runtime_data(self.properties[PROP_PARAMETERS])
- return p
-
def nested(self):
if self._nested is None and self.resource_id is not None:
self._nested = parser.Stack.load(self.context,
return self._nested
- def create_with_template(self, child_template):
+ def create_with_template(self, child_template, user_params):
'''
Handle the creation of the nested stack from a given JSON template.
'''
template = parser.Template(child_template)
params = parser.Parameters(self.physical_resource_name(), template,
- self._params())
+ user_params)
self._nested = parser.Stack(self.context,
self.physical_resource_name(),
if self._nested.state != self._nested.CREATE_COMPLETE:
raise exception.Error(self._nested.state_description)
+ def get_output(self, op):
+ stack = self.nested()
+ if op not in stack.outputs:
+ raise exception.InvalidTemplateAttribute(
+ resource=self.physical_resource_name(), key=key)
+
+ return stack.output(op)
+
+
+class NestedStack(Stack):
+ properties_schema = {PROP_TEMPLATE_URL: {'Type': 'String',
+ 'Required': True},
+ PROP_TIMEOUT_MINS: {'Type': 'Number'},
+ PROP_PARAMETERS: {'Type': 'Map'}}
+
def handle_create(self):
template_data = urlfetch.get(self.properties[PROP_TEMPLATE_URL])
template = template_format.parse(template_data)
- self.create_with_template(template)
+ self.create_with_template(template, self.properties[PROP_PARAMETERS])
def handle_update(self):
return self.UPDATE_REPLACE
resource=self.physical_resource_name(), key=key)
prefix, dot, op = key.partition('.')
- stack = self.nested()
- if stack is None:
- # This seems like a hack, to get past validation
- return ''
- if op not in stack.outputs:
- raise exception.InvalidTemplateAttribute(
- resource=self.physical_resource_name(), key=key)
-
- return stack.output(op)
+ return self.get_output(op)
def resource_mapping():
return {
- 'AWS::CloudFormation::Stack': Stack,
+ 'AWS::CloudFormation::Stack': NestedStack,
}
class FakeNested:
resources = {'DatabaseInstance': FakeDatabaseInstance()}
- stack.Stack.create_with_template(mox.IgnoreArg()).AndReturn(None)
+ params = {
+ 'AllocatedStorage': u'5',
+ 'DBInstanceClass': u'db.m1.small',
+ 'DBName': u'wordpress',
+ 'DBSecurityGroups': [],
+ 'KeyName': 'test',
+ 'MasterUserPassword': u'admin',
+ 'MasterUsername': u'admin',
+ 'Port': '3306'
+ }
+
+ stack.Stack.create_with_template(mox.IgnoreArg(),
+ params).AndReturn(None)
fn = FakeNested()
s = self.parse_stack(t)
resource = self.create_dbinstance(t, s, 'DatabaseServer')
- self.assertEqual({'AllocatedStorage': u'5',
- 'DBInstanceClass': u'db.m1.small',
- 'DBName': u'wordpress',
- 'DBSecurityGroups': [],
- 'KeyName': 'test',
- 'MasterUserPassword': u'admin',
- 'MasterUsername': u'admin',
- 'Port': '3306'}, resource._params())
-
self.assertEqual('0.0.0.0', resource.FnGetAtt('Endpoint.Address'))
self.assertEqual('10.0.0.1', resource.FnGetAtt('Endpoint.Address'))
self.assertEqual('3306', resource.FnGetAtt('Endpoint.Port'))