Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | // Copyright (c) 2018 Intel Corporation |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | */ |
| 16 | #pragma once |
| 17 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "app.hpp" |
| 19 | #include "query.hpp" |
| 20 | #include "registries/privilege_registry.hpp" |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 21 | #include "sensors.hpp" |
Ed Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 22 | #include "utils/json_utils.hpp" |
Janet Adkins | c956360 | 2024-08-28 11:37:46 -0500 | [diff] [blame^] | 23 | #include "utils/sensor_utils.hpp" |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 24 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 25 | namespace redfish |
| 26 | { |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 27 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 28 | inline void requestRoutesThermal(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 29 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 30 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 31 | .privileges(redfish::privileges::getThermal) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 32 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 33 | [&app](const crow::Request& req, |
| 34 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 35 | const std::string& chassisName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 36 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 37 | { |
| 38 | return; |
| 39 | } |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 40 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 41 | auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( |
| 42 | asyncResp, chassisName, sensors::dbus::thermalPaths, |
Janet Adkins | c956360 | 2024-08-28 11:37:46 -0500 | [diff] [blame^] | 43 | sensor_utils::thermalNode); |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 44 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 45 | // TODO Need to get Chassis Redundancy information. |
| 46 | getChassisData(sensorAsyncResp); |
| 47 | }); |
Krzysztof Grobelny | 1b1be67 | 2021-05-07 10:13:15 +0000 | [diff] [blame] | 48 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 49 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 50 | .privileges(redfish::privileges::patchThermal) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 51 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 52 | [&app](const crow::Request& req, |
| 53 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 54 | const std::string& chassisName) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 55 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 56 | { |
| 57 | return; |
| 58 | } |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 59 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 60 | std::optional<std::vector<nlohmann::json::object_t>> |
| 61 | temperatureCollections; |
| 62 | std::optional<std::vector<nlohmann::json::object_t>> |
| 63 | fanCollections; |
| 64 | std::unordered_map<std::string, |
| 65 | std::vector<nlohmann::json::object_t>> |
| 66 | allCollections; |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 67 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 68 | auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>( |
| 69 | asyncResp, chassisName, sensors::dbus::thermalPaths, |
Janet Adkins | c956360 | 2024-08-28 11:37:46 -0500 | [diff] [blame^] | 70 | sensor_utils::thermalNode); |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 71 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 72 | if (!json_util::readJsonPatch( |
| 73 | req, sensorsAsyncResp->asyncResp->res, "Temperatures", |
| 74 | temperatureCollections, "Fans", fanCollections)) |
| 75 | { |
| 76 | return; |
| 77 | } |
| 78 | if (!temperatureCollections && !fanCollections) |
| 79 | { |
| 80 | messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, |
| 81 | "Thermal", |
| 82 | "Temperatures / Voltages"); |
| 83 | return; |
| 84 | } |
| 85 | if (temperatureCollections) |
| 86 | { |
| 87 | allCollections.emplace("Temperatures", |
| 88 | *std::move(temperatureCollections)); |
| 89 | } |
| 90 | if (fanCollections) |
| 91 | { |
| 92 | allCollections.emplace("Fans", *std::move(fanCollections)); |
| 93 | } |
| 94 | setSensorsOverride(sensorsAsyncResp, allCollections); |
| 95 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 96 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 97 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 98 | } // namespace redfish |