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 | |
| 18 | #include "node.hpp" |
| 19 | #include "sensors.hpp" |
| 20 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 21 | namespace redfish |
| 22 | { |
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 | class Thermal : public Node |
| 25 | { |
| 26 | public: |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 27 | Thermal(App& app) : |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 28 | Node((app), "/redfish/v1/Chassis/<str>/Thermal/", std::string()) |
| 29 | { |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 30 | entityPrivileges = { |
| 31 | {boost::beast::http::verb::get, {{"Login"}}}, |
| 32 | {boost::beast::http::verb::head, {{"Login"}}}, |
jayaprakash Mutyala | 1b1b43f | 2020-03-28 22:56:06 +0000 | [diff] [blame] | 33 | {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 34 | {boost::beast::http::verb::put, {{"ConfigureManager"}}}, |
| 35 | {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, |
| 36 | {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 37 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 38 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 39 | private: |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 40 | void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 41 | const crow::Request&, |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 42 | const std::vector<std::string>& params) override |
| 43 | { |
| 44 | if (params.size() != 1) |
| 45 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 46 | messages::internalError(asyncResp->res); |
| 47 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 48 | return; |
| 49 | } |
Krzysztof Grobelny | 1b1be67 | 2021-05-07 10:13:15 +0000 | [diff] [blame^] | 50 | |
| 51 | auto thermalPaths = sensors::dbus::paths.find(sensors::node::thermal); |
| 52 | if (thermalPaths == sensors::dbus::paths.end()) |
| 53 | { |
| 54 | messages::internalError(asyncResp->res); |
| 55 | return; |
| 56 | } |
| 57 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 58 | const std::string& chassisName = params[0]; |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 59 | auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( |
Krzysztof Grobelny | 1b1be67 | 2021-05-07 10:13:15 +0000 | [diff] [blame^] | 60 | asyncResp, chassisName, thermalPaths->second, |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 61 | sensors::node::thermal); |
Ed Tanous | 2474adf | 2018-09-05 16:31:16 -0700 | [diff] [blame] | 62 | |
| 63 | // TODO Need to get Chassis Redundancy information. |
| 64 | getChassisData(sensorAsyncResp); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 65 | } |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 66 | void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 67 | const crow::Request& req, |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 68 | const std::vector<std::string>& params) override |
| 69 | { |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 70 | if (params.size() != 1) |
| 71 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 72 | |
| 73 | messages::internalError(asyncResp->res); |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 74 | return; |
| 75 | } |
| 76 | |
Krzysztof Grobelny | 1b1be67 | 2021-05-07 10:13:15 +0000 | [diff] [blame^] | 77 | auto thermalPaths = sensors::dbus::paths.find(sensors::node::thermal); |
| 78 | if (thermalPaths == sensors::dbus::paths.end()) |
| 79 | { |
| 80 | messages::internalError(asyncResp->res); |
| 81 | return; |
| 82 | } |
| 83 | |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 84 | const std::string& chassisName = params[0]; |
| 85 | std::optional<std::vector<nlohmann::json>> temperatureCollections; |
| 86 | std::optional<std::vector<nlohmann::json>> fanCollections; |
| 87 | std::unordered_map<std::string, std::vector<nlohmann::json>> |
| 88 | allCollections; |
| 89 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 90 | auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>( |
Krzysztof Grobelny | 1b1be67 | 2021-05-07 10:13:15 +0000 | [diff] [blame^] | 91 | asyncResp, chassisName, thermalPaths->second, |
Adrian Ambrożewicz | a0ec28b | 2020-04-10 14:47:28 +0200 | [diff] [blame] | 92 | sensors::node::thermal); |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 93 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 94 | if (!json_util::readJson(req, sensorsAsyncResp->asyncResp->res, |
| 95 | "Temperatures", temperatureCollections, "Fans", |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 96 | fanCollections)) |
| 97 | { |
| 98 | return; |
| 99 | } |
| 100 | if (!temperatureCollections && !fanCollections) |
| 101 | { |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 102 | messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, |
| 103 | "Thermal", "Temperatures / Voltages"); |
Carol Wang | 4bb3dc3 | 2019-10-17 18:15:02 +0800 | [diff] [blame] | 104 | return; |
| 105 | } |
| 106 | if (temperatureCollections) |
| 107 | { |
| 108 | allCollections.emplace("Temperatures", |
| 109 | *std::move(temperatureCollections)); |
| 110 | } |
| 111 | if (fanCollections) |
| 112 | { |
| 113 | allCollections.emplace("Fans", *std::move(fanCollections)); |
| 114 | } |
| 115 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 116 | checkAndDoSensorsOverride(sensorsAsyncResp, allCollections); |
Richard Marian Thomaiyar | 413961d | 2019-02-01 00:43:39 +0530 | [diff] [blame] | 117 | } |
Lewanczyk, Dawid | 08777fb | 2018-03-22 23:33:49 +0100 | [diff] [blame] | 118 | }; |
| 119 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 120 | } // namespace redfish |