108777fb0SLewanczyk, Dawid /* 208777fb0SLewanczyk, Dawid // Copyright (c) 2018 Intel Corporation 308777fb0SLewanczyk, Dawid // 408777fb0SLewanczyk, Dawid // Licensed under the Apache License, Version 2.0 (the "License"); 508777fb0SLewanczyk, Dawid // you may not use this file except in compliance with the License. 608777fb0SLewanczyk, Dawid // You may obtain a copy of the License at 708777fb0SLewanczyk, Dawid // 808777fb0SLewanczyk, Dawid // http://www.apache.org/licenses/LICENSE-2.0 908777fb0SLewanczyk, Dawid // 1008777fb0SLewanczyk, Dawid // Unless required by applicable law or agreed to in writing, software 1108777fb0SLewanczyk, Dawid // distributed under the License is distributed on an "AS IS" BASIS, 1208777fb0SLewanczyk, Dawid // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1308777fb0SLewanczyk, Dawid // See the License for the specific language governing permissions and 1408777fb0SLewanczyk, Dawid // limitations under the License. 1508777fb0SLewanczyk, Dawid */ 1608777fb0SLewanczyk, Dawid #pragma once 1708777fb0SLewanczyk, Dawid 1808777fb0SLewanczyk, Dawid #include "node.hpp" 1908777fb0SLewanczyk, Dawid #include "sensors.hpp" 2008777fb0SLewanczyk, Dawid 211abe55efSEd Tanous namespace redfish 221abe55efSEd Tanous { 2308777fb0SLewanczyk, Dawid 241abe55efSEd Tanous class Thermal : public Node 251abe55efSEd Tanous { 2608777fb0SLewanczyk, Dawid public: 2752cc112dSEd Tanous Thermal(App& app) : 281abe55efSEd Tanous Node((app), "/redfish/v1/Chassis/<str>/Thermal/", std::string()) 291abe55efSEd Tanous { 30e0d918bcSEd Tanous entityPrivileges = { 31e0d918bcSEd Tanous {boost::beast::http::verb::get, {{"Login"}}}, 32e0d918bcSEd Tanous {boost::beast::http::verb::head, {{"Login"}}}, 331b1b43f2Sjayaprakash Mutyala {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 34e0d918bcSEd Tanous {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 35e0d918bcSEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 36e0d918bcSEd Tanous {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3708777fb0SLewanczyk, Dawid } 3808777fb0SLewanczyk, Dawid 3908777fb0SLewanczyk, Dawid private: 408d1b46d7Szhanghch05 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 418d1b46d7Szhanghch05 const crow::Request&, 421abe55efSEd Tanous const std::vector<std::string>& params) override 431abe55efSEd Tanous { 441abe55efSEd Tanous if (params.size() != 1) 451abe55efSEd Tanous { 468d1b46d7Szhanghch05 messages::internalError(asyncResp->res); 478d1b46d7Szhanghch05 4808777fb0SLewanczyk, Dawid return; 4908777fb0SLewanczyk, Dawid } 50*1b1be67fSKrzysztof Grobelny 51*1b1be67fSKrzysztof Grobelny auto thermalPaths = sensors::dbus::paths.find(sensors::node::thermal); 52*1b1be67fSKrzysztof Grobelny if (thermalPaths == sensors::dbus::paths.end()) 53*1b1be67fSKrzysztof Grobelny { 54*1b1be67fSKrzysztof Grobelny messages::internalError(asyncResp->res); 55*1b1be67fSKrzysztof Grobelny return; 56*1b1be67fSKrzysztof Grobelny } 57*1b1be67fSKrzysztof Grobelny 5855c7b7a2SEd Tanous const std::string& chassisName = params[0]; 592474adfaSEd Tanous auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( 60*1b1be67fSKrzysztof Grobelny asyncResp, chassisName, thermalPaths->second, 61a0ec28b6SAdrian Ambrożewicz sensors::node::thermal); 622474adfaSEd Tanous 632474adfaSEd Tanous // TODO Need to get Chassis Redundancy information. 642474adfaSEd Tanous getChassisData(sensorAsyncResp); 6508777fb0SLewanczyk, Dawid } 668d1b46d7Szhanghch05 void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 678d1b46d7Szhanghch05 const crow::Request& req, 68413961deSRichard Marian Thomaiyar const std::vector<std::string>& params) override 69413961deSRichard Marian Thomaiyar { 704bb3dc34SCarol Wang if (params.size() != 1) 714bb3dc34SCarol Wang { 728d1b46d7Szhanghch05 738d1b46d7Szhanghch05 messages::internalError(asyncResp->res); 744bb3dc34SCarol Wang return; 754bb3dc34SCarol Wang } 764bb3dc34SCarol Wang 77*1b1be67fSKrzysztof Grobelny auto thermalPaths = sensors::dbus::paths.find(sensors::node::thermal); 78*1b1be67fSKrzysztof Grobelny if (thermalPaths == sensors::dbus::paths.end()) 79*1b1be67fSKrzysztof Grobelny { 80*1b1be67fSKrzysztof Grobelny messages::internalError(asyncResp->res); 81*1b1be67fSKrzysztof Grobelny return; 82*1b1be67fSKrzysztof Grobelny } 83*1b1be67fSKrzysztof Grobelny 844bb3dc34SCarol Wang const std::string& chassisName = params[0]; 854bb3dc34SCarol Wang std::optional<std::vector<nlohmann::json>> temperatureCollections; 864bb3dc34SCarol Wang std::optional<std::vector<nlohmann::json>> fanCollections; 874bb3dc34SCarol Wang std::unordered_map<std::string, std::vector<nlohmann::json>> 884bb3dc34SCarol Wang allCollections; 894bb3dc34SCarol Wang 908d1b46d7Szhanghch05 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>( 91*1b1be67fSKrzysztof Grobelny asyncResp, chassisName, thermalPaths->second, 92a0ec28b6SAdrian Ambrożewicz sensors::node::thermal); 934bb3dc34SCarol Wang 948d1b46d7Szhanghch05 if (!json_util::readJson(req, sensorsAsyncResp->asyncResp->res, 958d1b46d7Szhanghch05 "Temperatures", temperatureCollections, "Fans", 964bb3dc34SCarol Wang fanCollections)) 974bb3dc34SCarol Wang { 984bb3dc34SCarol Wang return; 994bb3dc34SCarol Wang } 1004bb3dc34SCarol Wang if (!temperatureCollections && !fanCollections) 1014bb3dc34SCarol Wang { 1028d1b46d7Szhanghch05 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, 1038d1b46d7Szhanghch05 "Thermal", "Temperatures / Voltages"); 1044bb3dc34SCarol Wang return; 1054bb3dc34SCarol Wang } 1064bb3dc34SCarol Wang if (temperatureCollections) 1074bb3dc34SCarol Wang { 1084bb3dc34SCarol Wang allCollections.emplace("Temperatures", 1094bb3dc34SCarol Wang *std::move(temperatureCollections)); 1104bb3dc34SCarol Wang } 1114bb3dc34SCarol Wang if (fanCollections) 1124bb3dc34SCarol Wang { 1134bb3dc34SCarol Wang allCollections.emplace("Fans", *std::move(fanCollections)); 1144bb3dc34SCarol Wang } 1154bb3dc34SCarol Wang 1168d1b46d7Szhanghch05 checkAndDoSensorsOverride(sensorsAsyncResp, allCollections); 117413961deSRichard Marian Thomaiyar } 11808777fb0SLewanczyk, Dawid }; 11908777fb0SLewanczyk, Dawid 12008777fb0SLewanczyk, Dawid } // namespace redfish 121