]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Split resource create into create and check_active
authorZane Bitter <zbitter@redhat.com>
Fri, 1 Mar 2013 16:12:54 +0000 (17:12 +0100)
committerZane Bitter <zbitter@redhat.com>
Fri, 1 Mar 2013 16:12:54 +0000 (17:12 +0100)
Change-Id: Ib8206f204e8805936defaa3431ecdf34b161e724
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/engine/resource.py

index 9b5dd911f206ab3555abc0c81a01b3ae1321ccd9..b5c91a17916385fbcc3ee553c7cad0561b023fe3 100644 (file)
@@ -15,6 +15,7 @@
 
 import base64
 from datetime import datetime
+import eventlet
 from eventlet.support import greenlets as greenlet
 
 from heat.engine import event
@@ -299,6 +300,8 @@ class Resource(object):
             self.state_set(self.CREATE_IN_PROGRESS)
             if callable(getattr(self, 'handle_create', None)):
                 self.handle_create()
+            while not self.check_active():
+                eventlet.sleep(1)
         except Exception as ex:
             # If we get a GreenletExit exception, the create thread has
             # been killed so we should raise allowing this thread to exit
@@ -312,6 +315,15 @@ class Resource(object):
         else:
             self.state_set(self.CREATE_COMPLETE)
 
+    def check_active(self):
+        '''
+        Check if the resource is active (ready to move to the CREATE_COMPLETE
+        state). By default this happens as soon as the handle_create() method
+        has completed successfully, but subclasses may customise this by
+        overriding this function.
+        '''
+        return True
+
     def update(self, json_snippet=None):
         '''
         update the resource. Subclasses should provide a handle_update() method