示例#1
0
def delete_by_id(host_id_list):
    current_identity = get_current_identity()
    payload_tracker = get_payload_tracker(
        account=current_identity.account_number,
        request_id=threadctx.request_id)

    with PayloadTrackerContext(payload_tracker,
                               received_status_message="delete operation",
                               current_operation="delete"):
        query = _get_host_list_by_id_list(host_id_list)

        if not query.count():
            flask.abort(status.HTTP_404_NOT_FOUND)

        for host_id, deleted in delete_hosts(
                query, current_app.event_producer,
                inventory_config().host_delete_chunk_size):
            if deleted:
                log_host_delete_succeeded(logger, host_id, get_control_rule())
                tracker_message = "deleted host"
            else:
                log_host_delete_failed(logger, host_id)
                tracker_message = "not deleted host"

            with PayloadTrackerProcessingContext(
                    payload_tracker, processing_status_message=tracker_message
            ) as payload_tracker_processing_ctx:
                payload_tracker_processing_ctx.inventory_id = host_id

    return flask.Response(None, status.HTTP_200_OK)
def run(config, logger, session, event_producer, shutdown_handler):
    conditions = Conditions.from_config(config)
    query_filter = exclude_edge_filter(stale_timestamp_filter(*conditions.culled()))
    query = session.query(Host).filter(query_filter)

    events = delete_hosts(query, event_producer, config.host_delete_chunk_size, shutdown_handler.shut_down)
    for host_id, deleted in events:
        if deleted:
            log_host_delete_succeeded(logger, host_id, "REAPER")
        else:
            log_host_delete_failed(logger, host_id, "REAPER")