]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Improve the ordering of stopping resources
authorAngus Salkeld <asalkeld@redhat.com>
Mon, 9 Apr 2012 22:57:55 +0000 (08:57 +1000)
committerAngus Salkeld <asalkeld@redhat.com>
Mon, 9 Apr 2012 23:41:39 +0000 (09:41 +1000)
Create a common function to generate the start order
and stop in the reverse order.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
heat/engine/parser.py

index e282327307655032d5a165fcc355a3776b67c191..da26fdfbc5c13c999721a94cd798ff239e1b922c 100644 (file)
@@ -72,9 +72,9 @@ class Stack:
 
     def validate(self):
         '''
-            If you are wondering where the actual validation is, me too.
-            it is just not obvious how to respond to validation failures.
-            http://docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_ValidateTemplate.html
+        If you are wondering where the actual validation is, me too.
+        it is just not obvious how to respond to validation failures.
+        http://docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_ValidateTemplate.html
         '''
         response = { 'ValidateTemplateResult': {
                     'Description': 'bla',
@@ -98,23 +98,48 @@ class Stack:
             response['ValidateTemplateResult']['Parameters'].append(res)
         return response
 
-    def start(self):
-        # start Volumes first.
+    def resource_append_deps(self, resource, order_list):
+        '''
+        For the given resource first append it's dependancies then
+        it's self to order_list.
+        '''
+        for r in resource.depends_on:
+            self.resource_append_deps(self.resources[r], order_list)
+        if not resource.name in order_list:
+            order_list.append(resource.name)
+
+    def get_start_order(self):
+        '''
+        return a list of Resource names in the correct order
+        for startup.
+        '''
+        order = []
         for r in self.t['Resources']:
-            if self.t['Resources'][r]['Type'] == 'AWS::EC2::Volume':
-                self.resources[r].start()
+            if self.t['Resources'][r]['Type'] == 'AWS::EC2::Volume' or \
+               self.t['Resources'][r]['Type'] == 'AWS::EC2::EIP':
+                if len(self.resources[r].depends_on) == 0:
+                    order.append(r)
 
         for r in self.t['Resources']:
-            #print 'calling start [stack->%s]' % (self.resources[r].name)
+            self.resource_append_deps(self.resources[r], order)
+
+        return order
+
+    def start(self):
+        '''
+        start all the resources in the order specified by get_start_order
+        '''
+        order = self.get_start_order()
+        for r in order:
             self.resources[r].start()
 
     def stop(self):
-        # stop VolumeAttachment's first
-        for r in self.t['Resources']:
-            if self.t['Resources'][r]['Type'] == 'AWS::EC2::VolumeAttachment':
-                self.resources[r].stop()
-
-        for r in self.t['Resources']:
+        '''
+        stop all the resources in the reverse order specified by get_start_order
+        '''
+        order = self.get_start_order()
+        order.reverse()
+        for r in order:
             self.resources[r].stop()
 
     def get_outputs(self):