def _poll_task(self, instance_uuid, 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 action = dict(instance_uuid=instance_uuid, action=task_name[0:255], error=None) if task_info.state in ['queued', 'running']: return elif task_info.state == 'success': LOG.debug( _("Task [%(task_name)s] %(task_ref)s " "status: success") % locals()) done.send("success") else: error_info = str(task_info.error.localizedMessage) action["error"] = error_info LOG.warn( _("Task [%(task_name)s] %(task_ref)s " "status: error %(error_info)s") % locals()) done.send_exception(exception.Error(error_info)) db.instance_action_create(context.get_admin_context(), action) except Exception, excep: LOG.warn(_("In vmwareapi:_poll_task, Got this error %s") % excep) done.send_exception(excep)
def _poll_task(): """Poll the given XenAPI task, and return the result if the action was completed successfully or not. """ try: name = self._session.xenapi.task.get_name_label(task) status = self._session.xenapi.task.get_status(task) if id: action = dict( instance_id=int(id), action=name[0:255], # Ensure action is never > 255 error=None) if status == "pending": return elif status == "success": result = self._session.xenapi.task.get_result(task) LOG.info( _("Task [%(name)s] %(task)s status:" " success %(result)s") % locals()) done.send(_parse_xmlrpc_value(result)) else: error_info = self._session.xenapi.task.get_error_info(task) action["error"] = str(error_info) LOG.warn( _("Task [%(name)s] %(task)s status:" " %(status)s %(error_info)s") % locals()) done.send_exception(self.XenAPI.Failure(error_info)) if id: db.instance_action_create(context.get_admin_context(), action) except self.XenAPI.Failure, exc: LOG.warn(exc) done.send_exception(*sys.exc_info())
def _poll_task(self, instance_id, 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 action = dict( instance_id=int(instance_id), action=task_name[0:255], error=None) if task_info.state in ['queued', 'running']: return elif task_info.state == 'success': LOG.debug(_("Task [%(task_name)s] %(task_ref)s " "status: success") % locals()) done.send("success") else: error_info = str(task_info.error.localizedMessage) action["error"] = error_info LOG.warn(_("Task [%(task_name)s] %(task_ref)s " "status: error %(error_info)s") % locals()) done.send_exception(exception.Error(error_info)) db.instance_action_create(context.get_admin_context(), action) except Exception, excep: LOG.warn(_("In vmwareapi:_poll_task, Got this error %s") % excep) done.send_exception(excep)
def _poll_task(): """Poll the given XenAPI task, and return the result if the action was completed successfully or not. """ try: name = self._session.xenapi.task.get_name_label(task) status = self._session.xenapi.task.get_status(task) if id: action = dict( instance_id=int(id), action=name[0:255], # Ensure action is never > 255 error=None) if status == "pending": return elif status == "success": result = self._session.xenapi.task.get_result(task) LOG.info(_("Task [%(name)s] %(task)s status:" " success %(result)s") % locals()) done.send(_parse_xmlrpc_value(result)) else: error_info = self._session.xenapi.task.get_error_info(task) action["error"] = str(error_info) LOG.warn(_("Task [%(name)s] %(task)s status:" " %(status)s %(error_info)s") % locals()) done.send_exception(self.XenAPI.Failure(error_info)) if id: db.instance_action_create(context.get_admin_context(), action) except self.XenAPI.Failure, exc: LOG.warn(exc) done.send_exception(*sys.exc_info())
def _poll_task(): """Poll the given XenAPI task, and return the result if the action was completed successfully or not. """ try: ctxt = context.get_admin_context() name = self.call_xenapi("task.get_name_label", task) status = self.call_xenapi("task.get_status", task) # Ensure action is never > 255 action = dict(action=name[:255], error=None) log_instance_actions = (FLAGS.xenapi_log_instance_actions and uuid) if log_instance_actions: action["instance_uuid"] = uuid if status == "pending": return elif status == "success": result = self.call_xenapi("task.get_result", task) LOG.info( _("Task [%(name)s] %(task)s status:" " success %(result)s") % locals()) if log_instance_actions: db.instance_action_create(ctxt, action) done.send(_parse_xmlrpc_value(result)) else: error_info = self.call_xenapi("task.get_error_info", task) LOG.warn( _("Task [%(name)s] %(task)s status:" " %(status)s %(error_info)s") % locals()) if log_instance_actions: action["error"] = str(error_info) db.instance_action_create(ctxt, action) done.send_exception(self.XenAPI.Failure(error_info)) except self.XenAPI.Failure, exc: LOG.warn(exc) done.send_exception(*sys.exc_info())
def wait_for_task(self, task, uuid=None): """Return the result of the given task. The task is polled until it completes.""" while True: """Poll the given XenAPI task, and return the result if the action was completed successfully or not. """ ctxt = context.get_admin_context() name = self.call_xenapi("task.get_name_label", task) status = self.call_xenapi("task.get_status", task) # Ensure action is never > 255 action = dict(action=name[:255], error=None) log_instance_actions = (FLAGS.xenapi_log_instance_actions and uuid) if log_instance_actions: action["instance_uuid"] = uuid if status == "pending": pass elif status == "success": result = self.call_xenapi("task.get_result", task) LOG.info( _("Task [%(name)s] %(task)s status:" " success %(result)s") % locals()) if log_instance_actions: db.instance_action_create(ctxt, action) return _parse_xmlrpc_value(result) else: error_info = self.call_xenapi("task.get_error_info", task) LOG.warn( _("Task [%(name)s] %(task)s status:" " %(status)s %(error_info)s") % locals()) if log_instance_actions: action["error"] = str(error_info) db.instance_action_create(ctxt, action) raise self.XenAPI.Failure(error_info) greenthread.sleep(FLAGS.xenapi_task_poll_interval)
def wait_for_task(self, task, uuid=None): """Return the result of the given task. The task is polled until it completes.""" while True: """Poll the given XenAPI task, and return the result if the action was completed successfully or not. """ ctxt = context.get_admin_context() name = self.call_xenapi("task.get_name_label", task) status = self.call_xenapi("task.get_status", task) # Ensure action is never > 255 action = dict(action=name[:255], error=None) log_instance_actions = (FLAGS.xenapi_log_instance_actions and uuid) if log_instance_actions: action["instance_uuid"] = uuid if status == "pending": pass elif status == "success": result = self.call_xenapi("task.get_result", task) LOG.info(_("Task [%(name)s] %(task)s status:" " success %(result)s") % locals()) if log_instance_actions: db.instance_action_create(ctxt, action) return _parse_xmlrpc_value(result) else: error_info = self.call_xenapi("task.get_error_info", task) LOG.warn(_("Task [%(name)s] %(task)s status:" " %(status)s %(error_info)s") % locals()) if log_instance_actions: action["error"] = str(error_info) db.instance_action_create(ctxt, action) raise self.XenAPI.Failure(error_info) greenthread.sleep(FLAGS.xenapi_task_poll_interval)
def _poll_task(): """Poll the given XenAPI task, and return the result if the action was completed successfully or not. """ try: ctxt = context.get_admin_context() name = self.call_xenapi("task.get_name_label", task) status = self.call_xenapi("task.get_status", task) # Ensure action is never > 255 action = dict(action=name[:255], error=None) log_instance_actions = (FLAGS.xenapi_log_instance_actions and uuid) if log_instance_actions: action["instance_uuid"] = uuid if status == "pending": return elif status == "success": result = self.call_xenapi("task.get_result", task) LOG.info(_("Task [%(name)s] %(task)s status:" " success %(result)s") % locals()) if log_instance_actions: db.instance_action_create(ctxt, action) done.send(_parse_xmlrpc_value(result)) else: error_info = self.call_xenapi("task.get_error_info", task) LOG.warn(_("Task [%(name)s] %(task)s status:" " %(status)s %(error_info)s") % locals()) if log_instance_actions: action["error"] = str(error_info) db.instance_action_create(ctxt, action) done.send_exception(self.XenAPI.Failure(error_info)) except self.XenAPI.Failure, exc: LOG.warn(exc) done.send_exception(*sys.exc_info())