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 21 namespace redfish 22 { 23 24 class Thermal : public Node 25 { 26 public: 27 Thermal(App& app) : 28 Node((app), "/redfish/v1/Chassis/<str>/Thermal/", std::string()) 29 { 30 entityPrivileges = { 31 {boost::beast::http::verb::get, {{"Login"}}}, 32 {boost::beast::http::verb::head, {{"Login"}}}, 33 {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 34 {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 35 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 36 {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 37 } 38 39 private: 40 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 41 const crow::Request&, 42 const std::vector<std::string>& params) override 43 { 44 if (params.size() != 1) 45 { 46 messages::internalError(asyncResp->res); 47 48 return; 49 } 50 const std::string& chassisName = params[0]; 51 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( 52 asyncResp, chassisName, 53 sensors::dbus::paths.at(sensors::node::thermal), 54 sensors::node::thermal); 55 56 // TODO Need to get Chassis Redundancy information. 57 getChassisData(sensorAsyncResp); 58 } 59 void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 60 const crow::Request& req, 61 const std::vector<std::string>& params) override 62 { 63 if (params.size() != 1) 64 { 65 66 messages::internalError(asyncResp->res); 67 return; 68 } 69 70 const std::string& chassisName = params[0]; 71 std::optional<std::vector<nlohmann::json>> temperatureCollections; 72 std::optional<std::vector<nlohmann::json>> fanCollections; 73 std::unordered_map<std::string, std::vector<nlohmann::json>> 74 allCollections; 75 76 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>( 77 asyncResp, chassisName, 78 sensors::dbus::paths.at(sensors::node::thermal), 79 sensors::node::thermal); 80 81 if (!json_util::readJson(req, sensorsAsyncResp->asyncResp->res, 82 "Temperatures", temperatureCollections, "Fans", 83 fanCollections)) 84 { 85 return; 86 } 87 if (!temperatureCollections && !fanCollections) 88 { 89 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, 90 "Thermal", "Temperatures / Voltages"); 91 return; 92 } 93 if (temperatureCollections) 94 { 95 allCollections.emplace("Temperatures", 96 *std::move(temperatureCollections)); 97 } 98 if (fanCollections) 99 { 100 allCollections.emplace("Fans", *std::move(fanCollections)); 101 } 102 103 checkAndDoSensorsOverride(sensorsAsyncResp, allCollections); 104 } 105 }; 106 107 } // namespace redfish 108