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 "sensors.hpp" 1908777fb0SLewanczyk, Dawid 207e860f15SJohn Edward Broadbent #include <app.hpp> 21*45ca1b86SEd Tanous #include <query.hpp> 22ed398213SEd Tanous #include <registries/privilege_registry.hpp> 237e860f15SJohn Edward Broadbent 241abe55efSEd Tanous namespace redfish 251abe55efSEd Tanous { 2608777fb0SLewanczyk, Dawid 277e860f15SJohn Edward Broadbent inline void requestRoutesThermal(App& app) 281abe55efSEd Tanous { 297e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") 30ed398213SEd Tanous .privileges(redfish::privileges::getThermal) 317e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 32*45ca1b86SEd Tanous [&app](const crow::Request& req, 337e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 347e860f15SJohn Edward Broadbent const std::string& chassisName) { 35*45ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 36*45ca1b86SEd Tanous { 37*45ca1b86SEd Tanous return; 38*45ca1b86SEd Tanous } 39*45ca1b86SEd Tanous 407e860f15SJohn Edward Broadbent auto thermalPaths = 417e860f15SJohn Edward Broadbent sensors::dbus::paths.find(sensors::node::thermal); 421b1be67fSKrzysztof Grobelny if (thermalPaths == sensors::dbus::paths.end()) 431b1be67fSKrzysztof Grobelny { 441b1be67fSKrzysztof Grobelny messages::internalError(asyncResp->res); 451b1be67fSKrzysztof Grobelny return; 461b1be67fSKrzysztof Grobelny } 471b1be67fSKrzysztof Grobelny 482474adfaSEd Tanous auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( 491b1be67fSKrzysztof Grobelny asyncResp, chassisName, thermalPaths->second, 50a0ec28b6SAdrian Ambrożewicz sensors::node::thermal); 512474adfaSEd Tanous 522474adfaSEd Tanous // TODO Need to get Chassis Redundancy information. 532474adfaSEd Tanous getChassisData(sensorAsyncResp); 547e860f15SJohn Edward Broadbent }); 558d1b46d7Szhanghch05 567e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") 57ed398213SEd Tanous .privileges(redfish::privileges::patchThermal) 587e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 59*45ca1b86SEd Tanous [&app](const crow::Request& req, 607e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 617e860f15SJohn Edward Broadbent const std::string& chassisName) { 62*45ca1b86SEd Tanous if (!redfish::setUpRedfishRoute(app, req, asyncResp->res)) 63*45ca1b86SEd Tanous { 64*45ca1b86SEd Tanous return; 65*45ca1b86SEd Tanous } 66*45ca1b86SEd Tanous 677e860f15SJohn Edward Broadbent auto thermalPaths = 687e860f15SJohn Edward Broadbent sensors::dbus::paths.find(sensors::node::thermal); 691b1be67fSKrzysztof Grobelny if (thermalPaths == sensors::dbus::paths.end()) 701b1be67fSKrzysztof Grobelny { 711b1be67fSKrzysztof Grobelny messages::internalError(asyncResp->res); 721b1be67fSKrzysztof Grobelny return; 731b1be67fSKrzysztof Grobelny } 741b1be67fSKrzysztof Grobelny 757e860f15SJohn Edward Broadbent std::optional<std::vector<nlohmann::json>> 767e860f15SJohn Edward Broadbent temperatureCollections; 774bb3dc34SCarol Wang std::optional<std::vector<nlohmann::json>> fanCollections; 784bb3dc34SCarol Wang std::unordered_map<std::string, std::vector<nlohmann::json>> 794bb3dc34SCarol Wang allCollections; 804bb3dc34SCarol Wang 818d1b46d7Szhanghch05 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>( 821b1be67fSKrzysztof Grobelny asyncResp, chassisName, thermalPaths->second, 83a0ec28b6SAdrian Ambrożewicz sensors::node::thermal); 844bb3dc34SCarol Wang 8515ed6780SWilly Tu if (!json_util::readJsonPatch( 8615ed6780SWilly Tu req, sensorsAsyncResp->asyncResp->res, "Temperatures", 8715ed6780SWilly Tu temperatureCollections, "Fans", fanCollections)) 884bb3dc34SCarol Wang { 894bb3dc34SCarol Wang return; 904bb3dc34SCarol Wang } 914bb3dc34SCarol Wang if (!temperatureCollections && !fanCollections) 924bb3dc34SCarol Wang { 938d1b46d7Szhanghch05 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, 947e860f15SJohn Edward Broadbent "Thermal", 957e860f15SJohn Edward Broadbent "Temperatures / Voltages"); 964bb3dc34SCarol Wang return; 974bb3dc34SCarol Wang } 984bb3dc34SCarol Wang if (temperatureCollections) 994bb3dc34SCarol Wang { 1004bb3dc34SCarol Wang allCollections.emplace("Temperatures", 1014bb3dc34SCarol Wang *std::move(temperatureCollections)); 1024bb3dc34SCarol Wang } 1034bb3dc34SCarol Wang if (fanCollections) 1044bb3dc34SCarol Wang { 1054bb3dc34SCarol Wang allCollections.emplace("Fans", *std::move(fanCollections)); 1064bb3dc34SCarol Wang } 10780ac4024SBruce Lee setSensorsOverride(sensorsAsyncResp, allCollections); 1087e860f15SJohn Edward Broadbent }); 109413961deSRichard Marian Thomaiyar } 11008777fb0SLewanczyk, Dawid 11108777fb0SLewanczyk, Dawid } // namespace redfish 112