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)
dataset/ETHPy150Open nii-cloud/dodai-compute/nova/virt/vmwareapi_conn.py/VMWareAPISession._poll_task/original