~ubuntu-branches/ubuntu/trusty/heat/trusty-security

« back to all changes in this revision

Viewing changes to heat/engine/resources/template_resource.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Yolanda Robla, Chuck Short
  • Date: 2013-07-22 16:22:29 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130722162229-zzvfu40id94ii0hc
Tags: 2013.2~b2-0ubuntu1
[ Yolanda Robla ]
* debian/tests: added autopkg tests

[ Chuck Short ]
* New upstream release
* debian/control:
  - Add python-pbr to build-depends.
  - Add python-d2to to build-depends.
  - Dropped python-argparse.
  - Add python-six to build-depends.
  - Dropped python-sendfile.
  - Dropped python-nose.
  - Added testrepository.
  - Added python-testtools.
* debian/rules: Run testrepository instead of nosetets.
* debian/patches/removes-lxml-version-limitation-from-pip-requires.patch: Dropped
  no longer needed.
* debian/patches/fix-package-version-detection-when-building-doc.patch: Dropped
  no longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
#
 
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
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
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
 
14
#    under the License.
 
15
 
 
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
 
20
 
 
21
from heat.openstack.common import log as logging
 
22
 
 
23
logger = logging.getLogger(__name__)
 
24
 
 
25
 
 
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'],
 
30
                                                         name)
 
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
 
36
 
 
37
        super(TemplateResource, self).__init__(name, json_snippet, stack)
 
38
 
 
39
    def _to_parameters(self):
 
40
        '''Convert CommaDelimitedList to List.'''
 
41
        params = {}
 
42
        for n, v in iter(self.properties.props.items()):
 
43
            if not v.implemented():
 
44
                continue
 
45
            elif v.type() == properties.LIST:
 
46
                # take a list and create a CommaDelimitedList
 
47
                val = self.properties[n]
 
48
                if val:
 
49
                    params[n] = ','.join(val)
 
50
            else:
 
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]
 
54
 
 
55
        return params
 
56
 
 
57
    def handle_create(self):
 
58
        template_data = self.stack.t.files.get(self.template_name)
 
59
        template = template_format.parse(template_data)
 
60
 
 
61
        return self.create_with_template(template,
 
62
                                         self._to_parameters())
 
63
 
 
64
    def handle_delete(self):
 
65
        self.delete_nested()
 
66
 
 
67
    def FnGetRefId(self):
 
68
        return self.nested().identifier().arn()
 
69
 
 
70
 
 
71
resource.register_template_class(TemplateResource)