Exemple #1
0
def get_pools(session, limit, offset=None):
    """Get all pools"""
    total_entries = session.query(func.count(Pool.id)).scalar()
    pools = session.query(Pool).order_by(
        Pool.id).offset(offset).limit(limit).all()
    return pool_collection_schema.dump(
        PoolCollection(pools=pools, total_entries=total_entries))
 def test_serialize(self):
     pool_model_a = Pool(pool="test_pool_a", slots=3)
     pool_model_b = Pool(pool="test_pool_b", slots=3)
     instance = PoolCollection(pools=[pool_model_a, pool_model_b],
                               total_entries=2)
     assert {
         "pools": [
             {
                 "name": "test_pool_a",
                 "slots": 3,
                 "occupied_slots": 0,
                 "running_slots": 0,
                 "queued_slots": 0,
                 "open_slots": 3,
             },
             {
                 "name": "test_pool_b",
                 "slots": 3,
                 "occupied_slots": 0,
                 "running_slots": 0,
                 "queued_slots": 0,
                 "open_slots": 3,
             },
         ],
         "total_entries":
         2,
     } == pool_collection_schema.dump(instance)
Exemple #3
0
def get_pools(session, limit, order_by='id', offset=None):
    """Get all pools"""
    to_replace = {"name": "pool"}
    allowed_filter_attrs = ['name', 'slots', "id"]
    total_entries = session.query(func.count(Pool.id)).scalar()
    query = session.query(Pool)
    query = apply_sorting(query, order_by, to_replace, allowed_filter_attrs)
    pools = query.offset(offset).limit(limit).all()
    return pool_collection_schema.dump(
        PoolCollection(pools=pools, total_entries=total_entries))
Exemple #4
0
def get_pools(session):
    """
    Get all pools
    """
    offset = request.args.get(parameters.page_offset, 0)
    limit = min(int(request.args.get(parameters.page_limit, 100)), 100)

    query = session.query(Pool)
    total_entries = query.count()
    query_list = query.offset(offset).limit(limit).all()

    return pool_collection_schema.dump(PoolCollection(pools=query_list, total_entries=total_entries)).data
Exemple #5
0
def get_pools(session):
    """
    Get all pools
    """
    offset = request.args.get(parameters.page_offset, 0)
    limit = min(int(request.args.get(parameters.page_limit, 100)), 100)

    total_entries = session.query(func.count(Pool.id)).scalar()
    pools = session.query(Pool).order_by(
        Pool.id).offset(offset).limit(limit).all()
    return pool_collection_schema.dump(
        PoolCollection(pools=pools, total_entries=total_entries)).data
Exemple #6
0
def get_pools(
    *,
    limit: int,
    order_by: str = "id",
    offset: Optional[int] = None,
    session: Session = NEW_SESSION,
) -> APIResponse:
    """Get all pools"""
    to_replace = {"name": "pool"}
    allowed_filter_attrs = ['name', 'slots', "id"]
    total_entries = session.query(func.count(Pool.id)).scalar()
    query = session.query(Pool)
    query = apply_sorting(query, order_by, to_replace, allowed_filter_attrs)
    pools = query.offset(offset).limit(limit).all()
    return pool_collection_schema.dump(
        PoolCollection(pools=pools, total_entries=total_entries))