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