Exemple #1
0
def patch_by_id(host_id_list, body):
    try:
        validated_patch_host_data = PatchHostSchema(
            strict=True).load(body).data
    except ValidationError as e:
        logger.exception(
            f"Input validation error while patching host: {host_id_list} - {body}"
        )
        return ({
            "status": 400,
            "title": "Bad Request",
            "detail": str(e.messages),
            "type": "unknown"
        }, 400)

    query = _get_host_list_by_id_list(host_id_list)

    hosts_to_update = query.all()

    if not hosts_to_update:
        log_patch_host_failed(logger, host_id_list)
        return flask.abort(status.HTTP_404_NOT_FOUND)

    for host in hosts_to_update:
        host.patch(validated_patch_host_data)

        if db.session.is_modified(host):
            db.session.commit()
            serialized_host = serialize_host(host, staleness_timestamps(),
                                             EGRESS_HOST_FIELDS)
            _emit_patch_event(serialized_host, host.id,
                              host.canonical_facts.get("insights_id"))

    log_patch_host_success(logger, host_id_list)
    return 200
def patch_by_id(host_id_list, host_data):
    try:
        validated_patch_host_data = PatchHostSchema(
            strict=True).load(host_data).data
    except ValidationError as e:
        logger.exception(
            f"Input validation error while patching host: {host_id_list} - {host_data}"
        )
        return ({
            "status": 400,
            "title": "Bad Request",
            "detail": str(e.messages),
            "type": "unknown"
        }, 400)

    query = _get_host_list_by_id_list(current_identity.account_number,
                                      host_id_list)

    hosts_to_update = query.all()

    if not hosts_to_update:
        logger.debug("Failed to find hosts during patch operation - hosts: %s",
                     host_id_list)
        return flask.abort(status.HTTP_404_NOT_FOUND)

    for host in hosts_to_update:
        host.patch(validated_patch_host_data)

    db.session.commit()

    return 200
Exemple #3
0
def patch_host(host_id, host_data):
    try:
        validated_patch_host_data = PatchHostSchema(strict=True).load(host_data).data
    except ValidationError as e:
        logger.exception("Input validation error while patching host: %s - %s"
                         % (host_id, host_data))
        return ({"status": 400,
                 "title": "Bad Request",
                 "detail": str(e.messages),
                 "type": "unknown",
                 },
                400)

    query = _get_host_list_by_id_list(current_identity.account_number,
                                      [host_id])

    host_to_update = query.first()

    if host_to_update is None:
        logger.debug("Failed to find host (id=%s) during patch operation" %
                     (host_id))
        return flask.abort(status.HTTP_404_NOT_FOUND)

    host_to_update.patch(validated_patch_host_data)

    db.session.commit()

    return 200