コード例 #1
0
ファイル: api.py プロジェクト: zhichangwu/icehouse
def _task_get(context, task_id, force_show_deleted=False):
    try:
        task = DATA['tasks'][task_id]
    except KeyError:
        msg = _('Could not find task %s') % task_id
        LOG.info(msg)
        raise exception.TaskNotFound(task_id=task_id)

    if task['deleted'] and not (force_show_deleted or context.show_deleted):
        msg = _('Unable to get deleted task %s') % task_id
        LOG.info(msg)
        raise exception.TaskNotFound(task_id=task_id)

    if not _is_task_visible(context, task):
        msg = (_("Forbidding request, task %s is not visible") % task_id)
        LOG.debug(msg)
        raise exception.Forbidden(msg)

    return task
コード例 #2
0
def _task_info_get(task_id):
    """Get Task Info for Task with given task ID"""
    global DATA
    try:
        task_info = DATA['task_info'][task_id]
    except KeyError:
        msg = _('Could not find task info %s') % task_id
        LOG.info(msg)
        raise exception.TaskNotFound(task_id=task_id)

    return task_info
コード例 #3
0
def task_delete(context, task_id):
    global DATA
    try:
        DATA['tasks'][task_id]['deleted'] = True
        DATA['tasks'][task_id]['deleted_at'] = timeutils.utcnow()
        DATA['tasks'][task_id]['updated_at'] = timeutils.utcnow()
        return copy.deepcopy(DATA['tasks'][task_id])
    except KeyError:
        msg = (_("No task found with ID %s") % task_id)
        LOG.debug(msg)
        raise exception.TaskNotFound(task_id=task_id)
コード例 #4
0
def _task_info_update(task_id, values):
    """Update Task Info for Task with given task ID and updated values"""
    global DATA
    try:
        task_info = DATA['task_info'][task_id]
    except KeyError:
        msg = (_("No task info found with task id %s") % task_id)
        LOG.debug(msg)
        raise exception.TaskNotFound(task_id=task_id)

    task_info.update(values)
    DATA['task_info'][task_id] = task_info

    return task_info
コード例 #5
0
ファイル: api.py プロジェクト: zhichangwu/icehouse
def task_update(context, task_id, values, purge_props=False):
    """Update a task object"""
    global DATA
    try:
        task = DATA['tasks'][task_id]
    except KeyError:
        msg = (_("No task found with ID %s") % task_id)
        LOG.debug(msg)
        raise exception.TaskNotFound(task_id=task_id)

    task.update(values)
    task['updated_at'] = timeutils.utcnow()
    DATA['tasks'][task_id] = task
    return task
コード例 #6
0
def task_delete(context, task_id, session=None):
    """Delete a task"""
    session = session or _get_session()
    query = session.query(models.Task)\
                   .filter_by(id=task_id)\
                   .filter_by(deleted=False)
    try:
        task_ref = query.one()
    except sa_orm.exc.NoResultFound:
        msg = (_("No task found with ID %s") % task_id)
        LOG.debug(msg)
        raise exception.TaskNotFound(task_id=task_id)

    task_ref.delete(session=session)
コード例 #7
0
def task_update(context, task_id, values):
    """Update a task object"""
    global DATA
    task_values = copy.deepcopy(values)
    task_info_values = _pop_task_info_values(task_values)
    try:
        task = DATA['tasks'][task_id]
    except KeyError:
        msg = (_("No task found with ID %s") % task_id)
        LOG.debug(msg)
        raise exception.TaskNotFound(task_id=task_id)

    task.update(task_values)
    task['updated_at'] = timeutils.utcnow()
    DATA['tasks'][task_id] = task
    task_info = _task_info_update(task['id'], task_info_values)

    return _format_task_from_db(task, task_info)
コード例 #8
0
ファイル: api.py プロジェクト: zhichangwu/icehouse
def _task_get(context, task_id, session=None, force_show_deleted=False):
    """Fetch a task entity by id"""
    session = session or _get_session()
    query = session.query(models.Task)
    query = query.filter_by(id=task_id)
    if not force_show_deleted and not _can_show_deleted(context):
        query = query.filter_by(deleted=False)
    try:
        task_ref = query.one()
    except sa_orm.exc.NoResultFound:
        msg = (_("No task found with ID %s") % task_id)
        LOG.debug(msg)
        raise exception.TaskNotFound(task_id=task_id)

    # Make sure the task is visible
    if not _is_task_visible(context, task_ref):
        msg = (_("Forbidding request, task %s is not visible") % task_id)
        LOG.debug(msg)
        raise exception.Forbidden(msg)

    return task_ref
コード例 #9
0
ファイル: api_image_import.py プロジェクト: crowdy/glance
    def _status_callback(self, action, chunk_bytes, total_bytes):
        # NOTE(danms): Only log status every five minutes
        if timeutils.now() - self.last_status > 300:
            LOG.debug('Image import %(image_id)s copied %(copied)i MiB',
                      {'image_id': action.image_id,
                       'copied': total_bytes // units.Mi})
            self.last_status = timeutils.now()

        task = script_utils.get_task(self.task_repo, self.task_id)
        if task is None:
            LOG.error(
                'Status callback for task %(task)s found no task object!',
                {'task': self.task_id})
            raise exception.TaskNotFound(self.task_id)
        if task.status != 'processing':
            LOG.error('Task %(task)s expected "processing" status, '
                      'but found "%(status)s"; aborting.')
            raise exception.TaskAbortedError()

        task.message = _('Copied %i MiB') % (total_bytes // units.Mi)
        self.task_repo.save(task)
コード例 #10
0
def _paginate_tasks(context, tasks, marker, limit, show_deleted):
    start = 0
    end = -1
    if marker is None:
        start = 0
    else:
        # Check that the task is accessible
        _task_get(context, marker, force_show_deleted=show_deleted)

        for i, task in enumerate(tasks):
            if task['id'] == marker:
                start = i + 1
                break
        else:
            if task:
                raise exception.TaskNotFound(task_id=task['id'])
            else:
                msg = _("Task does not exist")
                raise exception.NotFound(message=msg)

    end = start + limit if limit is not None else None
    return tasks[start:end]