def _poll_task(self, task_ref, done): """Poll the given task, and fires the given Deferred if we get a result. """ try: task_info = self._call_method(vim_util, "get_dynamic_property", task_ref, "Task", "info") task_name = task_info.name if task_info.state in ['queued', 'running']: return elif task_info.state == 'success': LOG.debug("Task [%(task_name)s] %(task_ref)s " "status: success", {'task_name': task_name, 'task_ref': task_ref}) done.send(task_info) else: error_info = str(task_info.error.localizedMessage) LOG.warn(_("Task [%(task_name)s] %(task_ref)s " "status: error %(error_info)s"), {'task_name': task_name, 'task_ref': task_ref, 'error_info': error_info}) # Check if we can raise a specific exception error = task_info.error name = error.fault.__class__.__name__ task_ex = error_util.get_fault_class(name)(error_info) done.send_exception(task_ex) except Exception as excep: LOG.warn(_("In vmwareapi:_poll_task, Got this error %s") % excep) done.send_exception(excep)
def _poll_task(self, task_ref, done): """Poll the given task, and fires the given Deferred if we get a result. """ try: task_info = self._call_method(vim_util, "get_dynamic_property", task_ref, "Task", "info") task_name = task_info.name if task_info.state in ['queued', 'running']: return elif task_info.state == 'success': LOG.debug(_("Task [%(task_name)s] %(task_ref)s " "status: success"), {'task_name': task_name, 'task_ref': task_ref}) done.send(task_info) else: error_info = str(task_info.error.localizedMessage) LOG.warn(_("Task [%(task_name)s] %(task_ref)s " "status: error %(error_info)s"), {'task_name': task_name, 'task_ref': task_ref, 'error_info': error_info}) # Check if we can raise a specific exception error = task_info.error name = error.fault.__class__.__name__ task_ex = error_util.get_fault_class(name)(error_info) done.send_exception(task_ex) except Exception as excep: LOG.warn(_("In vmwareapi:_poll_task, Got this error %s") % excep) done.send_exception(excep)
def _wait_for_task(self, task_ref): task_info = self._call_method('module', "get_dynamic_property", task_ref, "Task", "info") if task_info.state == 'success': return task_info else: error_info = 'fake error' error = task_info.error name = error.fault.__class__.__name__ raise error_util.get_fault_class(name)(error_info)
def _call_method(self, module, method, *args, **kwargs): """Calls a method within the module specified with args provided. """ args = list(args) retry_count = 0 while True: exc_info = False try: if not self._is_vim_object(module): # If it is not the first try, then get the latest # vim object if retry_count > 0: args = args[1:] args = [self.vim] + args retry_count += 1 temp_module = module for method_elem in method.split("."): temp_module = getattr(temp_module, method_elem) return temp_module(*args, **kwargs) except error_util.VimFaultException as excep: # If it is a Session Fault Exception, it may point # to a session gone bad. So we try re-creating a session # and then proceeding ahead with the call. exc_info = sys.exc_info() if error_util.NOT_AUTHENTICATED in excep.fault_list: # Because of the idle session returning an empty # RetrievePropertiesResponse and also the same is returned # when there is say empty answer to the query for # VMs on the host ( as in no VMs on the host), we have no # way to differentiate. We thus check if the session is # active if self._session_is_active(): return [] LOG.warning(_("Session %s is inactive!"), self._session.key) self._create_session() else: # No re-trying for errors for API call has gone through # and is the caller's fault. Caller should handle these # errors. e.g, InvalidArgument fault. # Raise specific exceptions here if possible if excep.fault_list: fault = excep.fault_list[0] raise error_util.get_fault_class(fault)(str(excep)) break except error_util.SessionOverLoadException: # For exceptions which may come because of session overload, # we retry exc_info = sys.exc_info() except error_util.SessionConnectionException: # For exceptions with connections we create the session exc_info = sys.exc_info() self._create_session() except Exception: # If it is a proper exception, say not having furnished # proper data in the SOAP call or the retry limit having # exceeded, we raise the exception exc_info = sys.exc_info() break LOG.debug("_call_method(session=%(key)s) failed. " "Module: %(module)s. " "Method: %(method)s. " "args: %(args)s. " "kwargs: %(kwargs)s. " "Iteration: %(n)s. ", {'key': self._session.key, 'module': module, 'method': method, 'args': args, 'kwargs': kwargs, 'n': retry_count}, exc_info=exc_info) # If retry count has been reached then break and # raise the exception if retry_count > self._api_retry_count: break time.sleep(TIME_BETWEEN_API_CALL_RETRIES) LOG.critical(_("In vmwareapi: _call_method (session=%s)"), self._session.key, exc_info=True) raise
def _call_method(self, module, method, *args, **kwargs): """Calls a method within the module specified with args provided. """ args = list(args) retry_count = 0 while True: exc = None try: if not self._is_vim_object(module): # If it is not the first try, then get the latest # vim object if retry_count > 0: args = args[1:] args = [self.vim] + args retry_count += 1 temp_module = module for method_elem in method.split("."): temp_module = getattr(temp_module, method_elem) return temp_module(*args, **kwargs) except error_util.VimFaultException as excep: # If it is a Session Fault Exception, it may point # to a session gone bad. So we try re-creating a session # and then proceeding ahead with the call. exc = excep if error_util.NOT_AUTHENTICATED in excep.fault_list: # Because of the idle session returning an empty # RetrievePropertiesResponse and also the same is returned # when there is say empty answer to the query for # VMs on the host ( as in no VMs on the host), we have no # way to differentiate. We thus check if the session is # active if self._session_is_active(): return [] LOG.warning(_("Session %s is inactive!"), self._session.key) self._create_session() else: # No re-trying for errors for API call has gone through # and is the caller's fault. Caller should handle these # errors. e.g, InvalidArgument fault. # Raise specific exceptions here if possible if excep.fault_list: raise error_util.get_fault_class(excep.fault_list[0]) break except error_util.SessionOverLoadException as excep: # For exceptions which may come because of session overload, # we retry exc = excep except error_util.SessionConnectionException as excep: # For exceptions with connections we create the session exc = excep self._create_session() except Exception as excep: # If it is a proper exception, say not having furnished # proper data in the SOAP call or the retry limit having # exceeded, we raise the exception exc = excep break LOG.debug(_("_call_method(session=%(key)s) failed. " "Module: %(module)s. " "Method: %(method)s. " "args: %(args)s. " "kwargs: %(kwargs)s. " "Iteration: %(n)s. " "Exception: %(ex)s. "), {'key': self._session.key, 'module': module, 'method': method, 'args': args, 'kwargs': kwargs, 'n': retry_count, 'ex': exc}) # If retry count has been reached then break and # raise the exception if retry_count > self._api_retry_count: break time.sleep(TIME_BETWEEN_API_CALL_RETRIES) LOG.critical(_("In vmwareapi: _call_method (session=%s)"), self._session.key, exc_info=True) raise