diff --git a/XSConsoleTask.py b/XSConsoleTask.py index 9766b96..c462ce8 100644 --- a/XSConsoleTask.py +++ b/XSConsoleTask.py @@ -25,6 +25,7 @@ def __init__(self, inHotOpaqueRef, inSession): self.completed = False self.creationTime = None self.finishTime = None + self.result = None def Completed(self): return self.completed @@ -37,6 +38,8 @@ def HandleCompletion(self, inStatus): self.creationTime = TimeUtils.DateTimeToSecs(self.session.xenapi.task.get_created(self.hotOpaqueRef.OpaqueRef())) self.finishTime = TimeUtils.DateTimeToSecs(self.session.xenapi.task.get_finished(self.hotOpaqueRef.OpaqueRef())) + if inStatus.startswith('success'): + self.result = self.session.xenapi.task.get_result(self.hotOpaqueRef.OpaqueRef()) if inStatus.startswith('failure'): self.errorInfo = self.session.xenapi.task.get_error_info(self.hotOpaqueRef.OpaqueRef()) @@ -53,11 +56,7 @@ def Status(self): return status def Result(self): - if self.Completed(): - result = self.completionStatus - else: - result= self.session.xenapi.task.get_status(self.hotOpaqueRef.OpaqueRef()) - return HotOpaqueRef(result, 'any') + return self.result def CanCancel(self): if self.Completed(): diff --git a/plugins-base/XSFeatureSRCreate.py b/plugins-base/XSFeatureSRCreate.py index 37110a2..6b9ef15 100644 --- a/plugins-base/XSFeatureSRCreate.py +++ b/plugins-base/XSFeatureSRCreate.py @@ -1174,7 +1174,7 @@ def CommitCreate(self, inType, inDeviceConfig, inOtherConfig = None): Layout.Inst().PopDialogue() Layout.Inst().TransientBanner(Lang('Creating Storage Repository...')) try: - srRef = Task.Sync(lambda x: x.xenapi.SR.create( + async_task = Task.New(lambda x: x.xenapi.Async.SR.create( HotAccessor().local_host_ref().OpaqueRef(), # host inDeviceConfig, '0', # physical_size @@ -1185,7 +1185,13 @@ def CommitCreate(self, inType, inDeviceConfig, inOtherConfig = None): True # shared ) ) - + # Wait until the task is completed + while async_task.IsPending(): + time.sleep(2) + + srRef = async_task.Result() + if not srRef: + async_task.RaiseIfFailed() # Set values in other_config only if the SR.create operation hasn't already set them for key, value in FirstValue(inOtherConfig, {}).items(): try: