Split resource create into create and check_active

Change-Id: Ib8206f204e8805936defaa3431ecdf34b161e724
Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
Zane Bitter 2013-03-01 17:12:54 +01:00
parent a2c2e6798f
commit d16622c6ec
1 changed files with 12 additions and 0 deletions

View File

@ -15,6 +15,7 @@
import base64 import base64
from datetime import datetime from datetime import datetime
import eventlet
from eventlet.support import greenlets as greenlet from eventlet.support import greenlets as greenlet
from heat.engine import event from heat.engine import event
@ -299,6 +300,8 @@ class Resource(object):
self.state_set(self.CREATE_IN_PROGRESS) self.state_set(self.CREATE_IN_PROGRESS)
if callable(getattr(self, 'handle_create', None)): if callable(getattr(self, 'handle_create', None)):
self.handle_create() self.handle_create()
while not self.check_active():
eventlet.sleep(1)
except Exception as ex: except Exception as ex:
# If we get a GreenletExit exception, the create thread has # If we get a GreenletExit exception, the create thread has
# been killed so we should raise allowing this thread to exit # been killed so we should raise allowing this thread to exit
@ -312,6 +315,15 @@ class Resource(object):
else: else:
self.state_set(self.CREATE_COMPLETE) 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): def update(self, json_snippet=None):
''' '''
update the resource. Subclasses should provide a handle_update() method update the resource. Subclasses should provide a handle_update() method