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, 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(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) _emit_patch_event( serialize_host(host, staleness_timestamps(), EGRESS_HOST_FIELDS)) db.session.commit() return 200
def _add_host(input_host): if not current_identity.is_trusted_system and current_identity.account_number != input_host.account: raise InventoryException( title="Invalid request", detail="The account number associated with the user does not match the account number associated with the " "host", ) return add_host(input_host, staleness_timestamps(), update_system_profile=False)
def host_checkin(body): canonical_facts = deserialize_canonical_facts(body) existing_host = find_existing_host(current_identity.account_number, canonical_facts) if existing_host: existing_host._update_modified_date() db.session.commit() serialized_host = serialize_host(existing_host, staleness_timestamps(), EGRESS_HOST_FIELDS) _emit_patch_event(serialized_host, existing_host.id, existing_host.canonical_facts.get("insights_id")) return flask_json_response(serialized_host, 201) else: flask.abort(404, "No hosts match the provided canonical facts.")