blob: 8417dba8c75290d4636051b10a3b5d59d199a467 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +01004#pragma once
5
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08006#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08007#include "async_resp.hpp"
8#include "error_messages.hpp"
9#include "http_request.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080010#include "query.hpp"
11#include "registries/privilege_registry.hpp"
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010012#include "sensors.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070013#include "utils/json_utils.hpp"
Janet Adkinsc9563602024-08-28 11:37:46 -050014#include "utils/sensor_utils.hpp"
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010015
Ed Tanousd7857202025-01-28 15:32:26 -080016#include <boost/beast/http/verb.hpp>
17#include <nlohmann/json.hpp>
18
19#include <memory>
20#include <optional>
21#include <unordered_map>
22#include <utility>
23#include <vector>
24
Ed Tanous1abe55e2018-09-05 08:30:59 -070025namespace redfish
26{
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010027
John Edward Broadbent7e860f12021-04-08 15:57:16 -070028inline void requestRoutesThermal(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -070029{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070030 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
Ed Tanoused398212021-06-09 17:05:54 -070031 .privileges(redfish::privileges::getThermal)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070032 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -070033 [&app](const crow::Request& req,
34 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
35 const std::string& chassisName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040036 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
37 {
38 return;
39 }
Ed Tanous45ca1b82022-03-25 13:07:27 -070040
Patrick Williamsbd79bce2024-08-16 15:22:20 -040041 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
42 asyncResp, chassisName, sensors::dbus::thermalPaths,
Janet Adkins0c728b42024-08-29 11:09:10 -050043 sensor_utils::chassisSubNodeToString(
44 sensor_utils::ChassisSubNode::thermalNode));
zhanghch058d1b46d2021-04-01 11:18:24 +080045
Patrick Williamsbd79bce2024-08-16 15:22:20 -040046 // TODO Need to get Chassis Redundancy information.
47 getChassisData(sensorAsyncResp);
48 });
Krzysztof Grobelny1b1be672021-05-07 10:13:15 +000049
John Edward Broadbent7e860f12021-04-08 15:57:16 -070050 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
Ed Tanoused398212021-06-09 17:05:54 -070051 .privileges(redfish::privileges::patchThermal)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070052 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -070053 [&app](const crow::Request& req,
54 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
55 const std::string& chassisName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040056 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
57 {
58 return;
59 }
Ed Tanous45ca1b82022-03-25 13:07:27 -070060
Patrick Williamsbd79bce2024-08-16 15:22:20 -040061 std::optional<std::vector<nlohmann::json::object_t>>
62 temperatureCollections;
63 std::optional<std::vector<nlohmann::json::object_t>>
64 fanCollections;
65 std::unordered_map<std::string,
66 std::vector<nlohmann::json::object_t>>
67 allCollections;
Ed Tanous2474adf2018-09-05 16:31:16 -070068
Patrick Williamsbd79bce2024-08-16 15:22:20 -040069 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
70 asyncResp, chassisName, sensors::dbus::thermalPaths,
Janet Adkins0c728b42024-08-29 11:09:10 -050071 sensor_utils::chassisSubNodeToString(
72 sensor_utils::ChassisSubNode::thermalNode));
zhanghch058d1b46d2021-04-01 11:18:24 +080073
Myung Baeafc474a2024-10-09 00:53:29 -070074 if (!json_util::readJsonPatch( //
75 req, sensorsAsyncResp->asyncResp->res, //
76 "Fans", fanCollections, //
77 "Temperatures", temperatureCollections //
78 ))
Patrick Williamsbd79bce2024-08-16 15:22:20 -040079 {
80 return;
81 }
82 if (!temperatureCollections && !fanCollections)
83 {
84 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
85 "Thermal",
86 "Temperatures / Voltages");
87 return;
88 }
89 if (temperatureCollections)
90 {
91 allCollections.emplace("Temperatures",
92 *std::move(temperatureCollections));
93 }
94 if (fanCollections)
95 {
96 allCollections.emplace("Fans", *std::move(fanCollections));
97 }
98 setSensorsOverride(sensorsAsyncResp, allCollections);
99 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700100}
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100101
Ed Tanous1abe55e2018-09-05 08:30:59 -0700102} // namespace redfish