Example #1
0
def notifications_get_all_by_filters(context,
                                     filters=None,
                                     sort_keys=None,
                                     sort_dirs=None,
                                     limit=None,
                                     marker=None):

    # NOTE(Dinesh_Bhor): If the limit is 0 there is no point in even going
    # to the database since nothing is going to be returned anyway.
    if limit == 0:
        return []

    sort_keys, sort_dirs = _process_sort_params(sort_keys, sort_dirs)

    filters = filters or {}
    query = model_query(context, models.Notification)

    if 'source_host_uuid' in filters:
        query = query.filter(models.Notification.source_host_uuid ==
                             filters['source_host_uuid'])

    if 'type' in filters:
        query = query.filter(models.Notification.type == filters['type'])

    if 'status' in filters:
        status = filters['status']
        if isinstance(status, (list, tuple, set, frozenset)):
            column_attr = getattr(models.Notification, 'status')
            query = query.filter(column_attr.in_(status))
        else:
            query = query.filter(models.Notification.status == status)

    if 'generated-since' in filters:
        generated_since = timeutils.normalize_time(filters['generated-since'])
        query = query.filter(
            models.Notification.generated_time >= generated_since)

    marker_row = None
    if marker is not None:
        marker_row = model_query(
            context, models.Notification).filter_by(id=marker).first()
        if not marker_row:
            raise exception.MarkerNotFound(marker=marker)

    try:
        query = sqlalchemyutils.paginate_query(query,
                                               models.Notification,
                                               limit,
                                               sort_keys,
                                               marker=marker_row,
                                               sort_dirs=sort_dirs)
    except db_exc.InvalidSortKey as err:
        raise exception.InvalidSortKey(err)

    return query.all()
Example #2
0
def host_get_all_by_filters(context,
                            filters=None,
                            sort_keys=None,
                            sort_dirs=None,
                            limit=None,
                            marker=None):

    # NOTE(Dinesh_Bhor): If the limit is 0 there is no point in even going
    # to the database since nothing is going to be returned anyway.
    if limit == 0:
        return []

    sort_keys, sort_dirs = _process_sort_params(sort_keys, sort_dirs)

    filters = filters or {}
    query = model_query(context,
                        models.Host).options(joinedload('failover_segment'))

    if 'failover_segment_id' in filters:
        query = query.filter(
            models.Host.failover_segment_id == filters['failover_segment_id'])

    if 'type' in filters:
        query = query.filter(models.Host.type == filters['type'])

    if 'on_maintenance' in filters:
        query = query.filter(
            models.Host.on_maintenance == filters['on_maintenance'])

    if 'reserved' in filters:
        query = query.filter(models.Host.reserved == filters['reserved'])

    marker_row = None
    if marker is not None:
        marker_row = model_query(context,
                                 models.Host).filter_by(id=marker).first()
        if not marker_row:
            raise exception.MarkerNotFound(marker=marker)

    try:
        query = sqlalchemyutils.paginate_query(query,
                                               models.Host,
                                               limit,
                                               sort_keys,
                                               marker=marker_row,
                                               sort_dirs=sort_dirs)
    except db_exc.InvalidSortKey as e:
        raise exception.InvalidSortKey(e)

    return query.all()
Example #3
0
def failover_segment_get_all_by_filters(
        context, filters=None, sort_keys=None,
        sort_dirs=None, limit=None, marker=None):

    # NOTE(Dinesh_Bhor): If the limit is 0 there is no point in even going
    # to the database since nothing is going to be returned anyway.
    if limit == 0:
        return []

    sort_keys, sort_dirs = _process_sort_params(sort_keys,
                                                sort_dirs)
    filters = filters or {}
    query = model_query(context, models.FailoverSegment)

    if 'recovery_method' in filters:
        query = query.filter(models.FailoverSegment.recovery_method == filters[
            'recovery_method'])
    if 'service_type' in filters:
        query = query.filter(models.FailoverSegment.service_type == filters[
            'service_type'])

    marker_row = None
    if marker is not None:
        marker_row = model_query(context,
                                 models.FailoverSegment
                                 ).filter_by(id=marker).first()

        if not marker_row:
            raise exception.MarkerNotFound(marker=marker)

    try:
        query = sqlalchemyutils.paginate_query(query, models.FailoverSegment,
                                               limit, sort_keys,
                                               marker=marker_row,
                                               sort_dirs=sort_dirs)
    except db_exc.InvalidSortKey as e:
        raise exception.InvalidSortKey(e.message)

    return query.all()