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 | |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 18 | #include "sensors.hpp" |
| 19 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 20 | #include <app.hpp> |
| 21 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 22 | namespace redfish |
| 23 | { |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 24 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 25 | inline void requestRoutesThermal(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 26 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 27 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") |
Ed Tanous | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame^] | 28 | .privileges({{"Login"}}) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 29 | .methods(boost::beast::http::verb::get)( |
| 30 | [](const crow::Request&, |
| 31 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 32 | const std::string& chassisName) { |
| 33 | auto thermalPaths = |
| 34 | sensors::dbus::paths.find(sensors::node::thermal); |
| 35 | if (thermalPaths == sensors::dbus::paths.end()) |
| 36 | { |
| 37 | messages::internalError(asyncResp->res); |
| 38 | return; |
| 39 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 40 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 41 | auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( |
| 42 | asyncResp, chassisName, thermalPaths->second, |
| 43 | sensors::node::thermal); |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 44 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [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 | 432a890 | 2021-06-14 15:28:56 -0700 | [diff] [blame^] | 50 | .privileges({{"ConfigureManager"}}) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 51 | .methods(boost::beast::http::verb::patch)( |
| 52 | [](const crow::Request& req, |
| 53 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 54 | const std::string& chassisName) { |
| 55 | auto thermalPaths = |
| 56 | sensors::dbus::paths.find(sensors::node::thermal); |
| 57 | if (thermalPaths == sensors::dbus::paths.end()) |
| 58 | { |
| 59 | messages::internalError(asyncResp->res); |
| 60 | return; |
| 61 | } |
Krzysztof Grobelny | 1b1be67 | 2021-05-07 10:13:15 +0000 | [diff] [blame] | 62 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 63 | std::optional<std::vector<nlohmann::json>> |
| 64 | temperatureCollections; |
| 65 | std::optional<std::vector<nlohmann::json>> fanCollections; |
| 66 | std::unordered_map<std::string, std::vector<nlohmann::json>> |
| 67 | allCollections; |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 68 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 69 | auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>( |
| 70 | asyncResp, chassisName, thermalPaths->second, |
| 71 | sensors::node::thermal); |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 72 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 73 | if (!json_util::readJson(req, sensorsAsyncResp->asyncResp->res, |
| 74 | "Temperatures", temperatureCollections, |
| 75 | "Fans", fanCollections)) |
| 76 | { |
| 77 | return; |
| 78 | } |
| 79 | if (!temperatureCollections && !fanCollections) |
| 80 | { |
| 81 | messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, |
| 82 | "Thermal", |
| 83 | "Temperatures / Voltages"); |
| 84 | return; |
| 85 | } |
| 86 | if (temperatureCollections) |
| 87 | { |
| 88 | allCollections.emplace("Temperatures", |
| 89 | *std::move(temperatureCollections)); |
| 90 | } |
| 91 | if (fanCollections) |
| 92 | { |
| 93 | allCollections.emplace("Fans", *std::move(fanCollections)); |
| 94 | } |
Bruce Lee | 80ac402 | 2021-06-04 15:41:39 +0800 | [diff] [blame] | 95 | setSensorsOverride(sensorsAsyncResp, allCollections); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 96 | }); |
| 97 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 98 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 99 | } // namespace redfish |