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 "app.hpp" 19 #include "query.hpp" 20 #include "registries/privilege_registry.hpp" 21 #include "sensors.hpp" 22 23 namespace redfish 24 { 25 26 inline void requestRoutesThermal(App& app) 27 { 28 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") 29 .privileges(redfish::privileges::getThermal) 30 .methods(boost::beast::http::verb::get)( 31 [&app](const crow::Request& req, 32 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 33 const std::string& chassisName) { 34 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 35 { 36 return; 37 } 38 39 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( 40 asyncResp, chassisName, sensors::dbus::thermalPaths, 41 sensors::node::thermal); 42 43 // TODO Need to get Chassis Redundancy information. 44 getChassisData(sensorAsyncResp); 45 }); 46 47 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") 48 .privileges(redfish::privileges::patchThermal) 49 .methods(boost::beast::http::verb::patch)( 50 [&app](const crow::Request& req, 51 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 52 const std::string& chassisName) { 53 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 54 { 55 return; 56 } 57 58 std::optional<std::vector<nlohmann::json>> temperatureCollections; 59 std::optional<std::vector<nlohmann::json>> fanCollections; 60 std::unordered_map<std::string, std::vector<nlohmann::json>> 61 allCollections; 62 63 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>( 64 asyncResp, chassisName, sensors::dbus::thermalPaths, 65 sensors::node::thermal); 66 67 if (!json_util::readJsonPatch(req, sensorsAsyncResp->asyncResp->res, 68 "Temperatures", temperatureCollections, 69 "Fans", fanCollections)) 70 { 71 return; 72 } 73 if (!temperatureCollections && !fanCollections) 74 { 75 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, 76 "Thermal", "Temperatures / Voltages"); 77 return; 78 } 79 if (temperatureCollections) 80 { 81 allCollections.emplace("Temperatures", 82 *std::move(temperatureCollections)); 83 } 84 if (fanCollections) 85 { 86 allCollections.emplace("Fans", *std::move(fanCollections)); 87 } 88 setSensorsOverride(sensorsAsyncResp, allCollections); 89 }); 90 } 91 92 } // namespace redfish 93