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" |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 23 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 24 | namespace redfish |
| 25 | { |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 26 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 27 | inline void requestRoutesThermal(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 28 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 29 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 30 | .privileges(redfish::privileges::getThermal) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 31 | .methods(boost::beast::http::verb::get)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 32 | [&app](const crow::Request& req, |
| 33 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 34 | const std::string& chassisName) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 35 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 36 | { |
| 37 | return; |
| 38 | } |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 39 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 40 | auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( |
| 41 | asyncResp, chassisName, sensors::dbus::thermalPaths, |
| 42 | sensors::node::thermal); |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 43 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 44 | // TODO Need to get Chassis Redundancy information. |
| 45 | getChassisData(sensorAsyncResp); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 46 | }); |
Krzysztof Grobelny | 1b1be67 | 2021-05-07 10:13:15 +0000 | [diff] [blame] | 47 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 48 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 49 | .privileges(redfish::privileges::patchThermal) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 50 | .methods(boost::beast::http::verb::patch)( |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 51 | [&app](const crow::Request& req, |
| 52 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 53 | const std::string& chassisName) { |
Carson Labrado | 3ba0007 | 2022-06-06 19:40:56 +0000 | [diff] [blame] | 54 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 55 | { |
| 56 | return; |
| 57 | } |
Ed Tanous | 45ca1b8 | 2022-03-25 13:07:27 -0700 | [diff] [blame] | 58 | |
Ed Tanous | 0885057 | 2024-03-06 15:09:17 -0800 | [diff] [blame] | 59 | std::optional<std::vector<nlohmann::json::object_t>> |
| 60 | temperatureCollections; |
| 61 | std::optional<std::vector<nlohmann::json::object_t>> fanCollections; |
| 62 | std::unordered_map<std::string, std::vector<nlohmann::json::object_t>> |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 63 | allCollections; |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 64 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 65 | auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>( |
| 66 | asyncResp, chassisName, sensors::dbus::thermalPaths, |
| 67 | sensors::node::thermal); |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 68 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 69 | if (!json_util::readJsonPatch(req, sensorsAsyncResp->asyncResp->res, |
| 70 | "Temperatures", temperatureCollections, |
| 71 | "Fans", fanCollections)) |
| 72 | { |
| 73 | return; |
| 74 | } |
| 75 | if (!temperatureCollections && !fanCollections) |
| 76 | { |
| 77 | messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, |
| 78 | "Thermal", "Temperatures / Voltages"); |
| 79 | return; |
| 80 | } |
| 81 | if (temperatureCollections) |
| 82 | { |
| 83 | allCollections.emplace("Temperatures", |
| 84 | *std::move(temperatureCollections)); |
| 85 | } |
| 86 | if (fanCollections) |
| 87 | { |
| 88 | allCollections.emplace("Fans", *std::move(fanCollections)); |
| 89 | } |
| 90 | setSensorsOverride(sensorsAsyncResp, allCollections); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 91 | }); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 92 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 93 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 94 | } // namespace redfish |