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

« back to all changes in this revision

Viewing changes to heat/engine/stack_resource.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandelman
  • Date: 2013-09-08 21:51:19 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130908215119-r939tu4aumqgdrkx
Tags: 2013.2~b3-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/control: Add python-netaddr as build-dep.
* debian/heat-common.install: Remove heat-boto and associated man-page
* debian/heat-common.install: Remove heat-cfn and associated man-page
* debian/heat-common.install: Remove heat-watch and associated man-page
* debian/patches/fix-sqlalchemy-0.8.patch: Dropped

[ Adam Gandelman ]
* debian/patches/default-kombu.patch: Dropped.
* debian/patches/default-sqlite.patch: Refreshed.
* debian/*.install, rules: Install heat.conf.sample as common
  config file in heat-common. Drop other per-package configs, they
  are no longer used.
* debian/rules: Clean pbr .egg from build dir if it exists.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#    License for the specific language governing permissions and limitations
14
14
#    under the License.
15
15
 
 
16
from oslo.config import cfg
 
17
 
16
18
from heat.common import exception
17
19
from heat.engine import attributes
18
20
from heat.engine import environment
34
36
    def __init__(self, name, json_snippet, stack):
35
37
        super(StackResource, self).__init__(name, json_snippet, stack)
36
38
        self._nested = None
 
39
        if self.stack.parent_resource:
 
40
            self.recursion_depth = (
 
41
                self.stack.parent_resource.recursion_depth + 1)
 
42
        else:
 
43
            self.recursion_depth = 0
37
44
 
38
45
    def _outputs_to_attribs(self, json_snippet):
39
46
        if not self.attributes and 'Outputs' in json_snippet:
63
70
        '''
64
71
        Handle the creation of the nested stack from a given JSON template.
65
72
        '''
 
73
        if self.recursion_depth >= cfg.CONF.max_nested_stack_depth:
 
74
            raise exception.StackRecursionLimitReached(
 
75
                cfg.CONF.max_nested_stack_depth)
66
76
        template = parser.Template(child_template)
67
77
        self._outputs_to_attribs(child_template)
68
78
 
69
79
        # Note we disable rollback for nested stacks, since they
70
80
        # should be rolled back by the parent stack on failure
71
 
        self._nested = parser.Stack(self.context,
72
 
                                    self.physical_resource_name(),
73
 
                                    template,
74
 
                                    environment.Environment(user_params),
75
 
                                    timeout_mins=timeout_mins,
76
 
                                    disable_rollback=True,
77
 
                                    parent_resource=self)
78
 
 
79
 
        nested_id = self._nested.store(self.stack)
 
81
        nested = parser.Stack(self.context,
 
82
                              self.physical_resource_name(),
 
83
                              template,
 
84
                              environment.Environment(user_params),
 
85
                              timeout_mins=timeout_mins,
 
86
                              disable_rollback=True,
 
87
                              parent_resource=self,
 
88
                              owner_id=self.stack.id)
 
89
        nested.validate()
 
90
        self._nested = nested
 
91
        nested_id = self._nested.store()
80
92
        self.resource_id_set(nested_id)
81
93
 
82
94
        stack_creator = scheduler.TaskRunner(self._nested.stack_task,
83
 
                                             action=self.CREATE)
 
95
                                             action=self._nested.CREATE)
84
96
        stack_creator.start(timeout=self._nested.timeout_secs())
85
97
        return stack_creator
86
98
 
111
123
                             environment.Environment(user_params),
112
124
                             timeout_mins=timeout_mins,
113
125
                             disable_rollback=True,
114
 
                             parent_resource=self)
115
 
        return self._nested.update(stack)
 
126
                             parent_resource=self,
 
127
                             owner_id=self.stack.id)
 
128
        stack.validate()
 
129
 
 
130
        nested_stack = self.nested()
 
131
        if nested_stack is None:
 
132
            raise exception.Error(_('Cannot update %s, stack not created')
 
133
                                  % self.name)
 
134
 
 
135
        if not hasattr(type(self), 'attributes_schema'):
 
136
            self.attributes = None
 
137
            self._outputs_to_attribs(child_template)
 
138
 
 
139
        updater = scheduler.TaskRunner(nested_stack.update_task, stack)
 
140
        updater.start()
 
141
        return updater
 
142
 
 
143
    def check_update_complete(self, updater):
 
144
        if updater is None:
 
145
            return True
 
146
 
 
147
        if not updater.step():
 
148
            return False
 
149
 
 
150
        nested_stack = self.nested()
 
151
        if nested_stack.state != (nested_stack.UPDATE,
 
152
                                  nested_stack.COMPLETE):
 
153
            raise exception.Error("Nested stack update failed: %s" %
 
154
                                  nested_stack.status_reason)
 
155
        return True
116
156
 
117
157
    def delete_nested(self):
118
158
        '''
124
164
            logger.info("Stack not found to delete")
125
165
        else:
126
166
            if stack is not None:
127
 
                stack.delete()
 
167
                delete_task = scheduler.TaskRunner(stack.delete)
 
168
                delete_task.start()
 
169
                return delete_task
 
170
 
 
171
    def check_delete_complete(self, delete_task):
 
172
        if delete_task is None:
 
173
            return True
 
174
 
 
175
        done = delete_task.step()
 
176
        if done:
 
177
            nested_stack = self.nested()
 
178
            if nested_stack.state != (nested_stack.DELETE,
 
179
                                      nested_stack.COMPLETE):
 
180
                raise exception.Error(nested_stack.status_reason)
 
181
 
 
182
        return done
128
183
 
129
184
    def handle_suspend(self):
130
185
        stack = self.nested()
133
188
                                  % self.name)
134
189
 
135
190
        suspend_task = scheduler.TaskRunner(self._nested.stack_task,
136
 
                                            action=self.SUSPEND,
 
191
                                            action=self._nested.SUSPEND,
137
192
                                            reverse=True)
138
193
 
139
194
        suspend_task.start(timeout=self._nested.timeout_secs())
155
210
                                  % self.name)
156
211
 
157
212
        resume_task = scheduler.TaskRunner(self._nested.stack_task,
158
 
                                           action=self.RESUME,
 
213
                                           action=self._nested.RESUME,
159
214
                                           reverse=False)
160
215
 
161
216
        resume_task.start(timeout=self._nested.timeout_secs())