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.engine import resource
17
from heat.engine import stack_resource
18
from heat.engine import properties
19
from heat.common import template_format
21
from heat.openstack.common import log as logging
23
logger = logging.getLogger(__name__)
26
class TemplateResource(stack_resource.StackResource):
27
'''A Nested Stack Resource representing another Resource.'''
28
def __init__(self, name, json_snippet, stack):
29
self.template_name = stack.env.get_resource_type(json_snippet['Type'],
31
# on purpose don't pass in the environment so we get
32
# the official/facade class to copy it's schema.
33
cls_facade = resource.get_class(json_snippet['Type'])
34
self.properties_schema = cls_facade.properties_schema
35
self.attributes_schema = cls_facade.attributes_schema
37
super(TemplateResource, self).__init__(name, json_snippet, stack)
39
def _to_parameters(self):
40
'''Convert CommaDelimitedList to List.'''
42
for n, v in iter(self.properties.props.items()):
43
if not v.implemented():
45
elif v.type() == properties.LIST:
46
# take a list and create a CommaDelimitedList
47
val = self.properties[n]
49
params[n] = ','.join(val)
51
# for MAP, the JSON param takes either a collection or string,
52
# so just pass it on and let the param validate as appropriate
53
params[n] = self.properties[n]
57
def handle_create(self):
58
template_data = self.stack.t.files.get(self.template_name)
59
template = template_format.parse(template_data)
61
return self.create_with_template(template,
62
self._to_parameters())
64
def handle_delete(self):
68
return self.nested().identifier().arn()
71
resource.register_template_class(TemplateResource)