Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame^] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| 3 | // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 4 | #pragma once |
| 5 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 6 | #include "app.hpp" |
| 7 | #include "query.hpp" |
| 8 | #include "registries/privilege_registry.hpp" |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 9 | #include "sensors.hpp" |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 10 | #include "utils/json_utils.hpp" |
Janet Adkins | c956360 | 2024-08-28 11:37:46 -0500 | [diff] [blame] | 11 | #include "utils/sensor_utils.hpp" |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 12 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 13 | namespace redfish |
| 14 | { |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 15 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 16 | inline void requestRoutesThermal(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 17 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 18 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 19 | .privileges(redfish::privileges::getThermal) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 20 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 21 | [&app](const crow::Request& req, |
| 22 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 23 | const std::string& chassisName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 24 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 25 | { |
| 26 | return; |
| 27 | } |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 28 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 29 | auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( |
| 30 | asyncResp, chassisName, sensors::dbus::thermalPaths, |
Janet Adkins | 0c728b4 | 2024-08-29 11:09:10 -0500 | [diff] [blame] | 31 | sensor_utils::chassisSubNodeToString( |
| 32 | sensor_utils::ChassisSubNode::thermalNode)); |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 33 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 34 | // TODO Need to get Chassis Redundancy information. |
| 35 | getChassisData(sensorAsyncResp); |
| 36 | }); |
Krzysztof Grobelny | 1b1be67 | 2021-05-07 10:13:15 +0000 | [diff] [blame] | 37 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 38 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 39 | .privileges(redfish::privileges::patchThermal) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 40 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 41 | [&app](const crow::Request& req, |
| 42 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 43 | const std::string& chassisName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 44 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 45 | { |
| 46 | return; |
| 47 | } |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 48 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 49 | 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 Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 56 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 57 | auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>( |
| 58 | asyncResp, chassisName, sensors::dbus::thermalPaths, |
Janet Adkins | 0c728b4 | 2024-08-29 11:09:10 -0500 | [diff] [blame] | 59 | sensor_utils::chassisSubNodeToString( |
| 60 | sensor_utils::ChassisSubNode::thermalNode)); |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 61 | |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 62 | if (!json_util::readJsonPatch( // |
| 63 | req, sensorsAsyncResp->asyncResp->res, // |
| 64 | "Fans", fanCollections, // |
| 65 | "Temperatures", temperatureCollections // |
| 66 | )) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 67 | { |
| 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 Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 88 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 89 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 90 | } // namespace redfish |