Beispiel #1
0
def list_active_computers():
    """
    Query the inventory client for active records with a given projection.

    :return: List of inventory objects.
    """
    projection = get_projection_from_qsa()
    page_info = get_paging_info_from_qsa()
    if not projection:
        projection = {'mercury_id': 1}

    data = inventory_client.query(
        {
            'active': {
                '$ne': None
            }
        },
        projection=projection,
        limit=page_info['limit'],
        sort=page_info['sort'],
        sort_direction=page_info['sort_direction'],
        offset_id=page_info['offset_id']
    )

    return jsonify(data)
Beispiel #2
0
def list_jobs():
    """
    Query the RPC service for job records with a given projection.

    :return: List of job objects. 
    """
    projection = get_projection_from_qsa() or {'instruction': 0}
    data = rpc_client.get_jobs(projection)

    return jsonify(data)
Beispiel #3
0
def get_job_task(job_id):
    """
    Query the RPC service for tasks associated to a given job_id.

    :param job_id: RPC job id.
    :return: List of task objects. 
    """
    projection = get_projection_from_qsa()
    tasks = rpc_client.get_job_tasks(job_id, projection)
    if tasks['count'] == 0:
        raise HTTPError('No tasks exist for job {}'.format(job_id),
                        status_code=404)
    return jsonify(tasks)
Beispiel #4
0
def get_job(job_id):
    """
    Get the job status by job_id.

    :param job_id: RPC job id, default is None.
    :return: Job object. 
    """
    projection = get_projection_from_qsa()
    data = rpc_client.get_job(job_id, projection)
    if not data:
        raise HTTPError('Job {} does not exist'.format(job_id),
                        status_code=404)

    return jsonify(data)
Beispiel #5
0
def get_inventory(mercury_id):
    """
    Get one inventory object by mercury_id.

    :param mercury_id: Device mercury id.
    :return: Inventory object.
    """
    projection = get_projection_from_qsa()
    data = inventory_client.get_one(mercury_id, projection=projection)
    if not data:
        message = 'mercury_id {} does not exist in inventory'
        raise HTTPError(message.format(mercury_id), status_code=404)

    return jsonify(data)
Beispiel #6
0
def list_inventory():
    """
    Query the inventory client for device records with a given projection
    or get one by mercury_id.

    :return: List of inventory objects.
    """
    projection = get_projection_from_qsa()
    paging_info = get_paging_info_from_qsa()
    data = inventory_client.query({},
                                  projection=projection,
                                  limit=paging_info['limit'],
                                  sort=paging_info['sort'],
                                  sort_direction=paging_info['sort_direction'],
                                  offset_id=paging_info['offset_id'])

    return jsonify(data)
Beispiel #7
0
def query_inventory_devices():
    """
    Query inventory devices with a given projection.

    :return: List of inventory objects.
    """
    query = request.json.get('query')
    projection = get_projection_from_qsa()
    page_info = get_paging_info_from_qsa()
    log.debug('QUERY: {}'.format(query))

    data = inventory_client.query(query,
                                  projection=projection,
                                  limit=page_info['limit'],
                                  sort=page_info['sort'],
                                  sort_direction=page_info['sort_direction'],
                                  offset_id=page_info['offset_id'])
    return jsonify(data)
Beispiel #8
0
def query_active_computers():
    """
    Query the active inventory with a given projection.

    :return: List of inventory objects.
    """
    query = request.json.get('query')
    # Make sure we get only active devices
    query.update({'active': {'$ne': None}})
    projection = get_projection_from_qsa()
    page_info = get_paging_info_from_qsa()
    data = inventory_client.query(query,
                                  projection=projection,
                                  limit=page_info['limit'],
                                  sort=page_info['sort'],
                                  sort_direction=page_info['sort_direction'],
                                  offset_id=page_info['offset_id'])
    return jsonify(data)