blob: 1b5b1f19c880e98db95383db96373b473e845c62 [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"
7#include "query.hpp"
8#include "registries/privilege_registry.hpp"
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +01009#include "sensors.hpp"
Ed Tanous5b904292024-04-16 11:10:17 -070010#include "utils/json_utils.hpp"
Janet Adkinsc9563602024-08-28 11:37:46 -050011#include "utils/sensor_utils.hpp"
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010012
Ed Tanous1abe55e2018-09-05 08:30:59 -070013namespace redfish
14{
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010015
John Edward Broadbent7e860f12021-04-08 15:57:16 -070016inline void requestRoutesThermal(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -070017{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070018 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
Ed Tanoused398212021-06-09 17:05:54 -070019 .privileges(redfish::privileges::getThermal)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070020 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -070021 [&app](const crow::Request& req,
22 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
23 const std::string& chassisName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040024 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
25 {
26 return;
27 }
Ed Tanous45ca1b82022-03-25 13:07:27 -070028
Patrick Williamsbd79bce2024-08-16 15:22:20 -040029 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
30 asyncResp, chassisName, sensors::dbus::thermalPaths,
Janet Adkins0c728b42024-08-29 11:09:10 -050031 sensor_utils::chassisSubNodeToString(
32 sensor_utils::ChassisSubNode::thermalNode));
zhanghch058d1b46d2021-04-01 11:18:24 +080033
Patrick Williamsbd79bce2024-08-16 15:22:20 -040034 // TODO Need to get Chassis Redundancy information.
35 getChassisData(sensorAsyncResp);
36 });
Krzysztof Grobelny1b1be672021-05-07 10:13:15 +000037
John Edward Broadbent7e860f12021-04-08 15:57:16 -070038 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
Ed Tanoused398212021-06-09 17:05:54 -070039 .privileges(redfish::privileges::patchThermal)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070040 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -070041 [&app](const crow::Request& req,
42 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
43 const std::string& chassisName) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040044 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
45 {
46 return;
47 }
Ed Tanous45ca1b82022-03-25 13:07:27 -070048
Patrick Williamsbd79bce2024-08-16 15:22:20 -040049 std::optional<std::vector<nlohmann::json::object_t>>
50 temperatureCollections;
51 std::optional<std::vector<nlohmann::json::object_t>>
52 fanCollections;
53 std::unordered_map<std::string,
54 std::vector<nlohmann::json::object_t>>
55 allCollections;
Ed Tanous2474adf2018-09-05 16:31:16 -070056
Patrick Williamsbd79bce2024-08-16 15:22:20 -040057 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
58 asyncResp, chassisName, sensors::dbus::thermalPaths,
Janet Adkins0c728b42024-08-29 11:09:10 -050059 sensor_utils::chassisSubNodeToString(
60 sensor_utils::ChassisSubNode::thermalNode));
zhanghch058d1b46d2021-04-01 11:18:24 +080061
Myung Baeafc474a2024-10-09 00:53:29 -070062 if (!json_util::readJsonPatch( //
63 req, sensorsAsyncResp->asyncResp->res, //
64 "Fans", fanCollections, //
65 "Temperatures", temperatureCollections //
66 ))
Patrick Williamsbd79bce2024-08-16 15:22:20 -040067 {
68 return;
69 }
70 if (!temperatureCollections && !fanCollections)
71 {
72 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
73 "Thermal",
74 "Temperatures / Voltages");
75 return;
76 }
77 if (temperatureCollections)
78 {
79 allCollections.emplace("Temperatures",
80 *std::move(temperatureCollections));
81 }
82 if (fanCollections)
83 {
84 allCollections.emplace("Fans", *std::move(fanCollections));
85 }
86 setSensorsOverride(sensorsAsyncResp, allCollections);
87 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -070088}
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010089
Ed Tanous1abe55e2018-09-05 08:30:59 -070090} // namespace redfish