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