xref: /openbmc/bmcweb/features/redfish/lib/thermal.hpp (revision 397fd61f34fab6922cdf84c4f411a2b1bd174a1f)
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:
271abe55efSEd Tanous     Thermal(CrowApp& 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"}}},
336f4fd479SRichard Marian Thomaiyar             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
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:
4085e1424fSEd Tanous     std::vector<const char*> typeList = {
418afa1b9bSRichard Marian Thomaiyar         "/xyz/openbmc_project/sensors/fan_tach",
42413961deSRichard Marian Thomaiyar         "/xyz/openbmc_project/sensors/temperature",
43413961deSRichard Marian Thomaiyar         "/xyz/openbmc_project/sensors/fan_pwm"};
4455c7b7a2SEd Tanous     void doGet(crow::Response& res, const crow::Request& req,
451abe55efSEd Tanous                const std::vector<std::string>& params) override
461abe55efSEd Tanous     {
471abe55efSEd Tanous         if (params.size() != 1)
481abe55efSEd Tanous         {
49f12894f8SJason M. Bills             messages::internalError(res);
5008777fb0SLewanczyk, Dawid             res.end();
5108777fb0SLewanczyk, Dawid             return;
5208777fb0SLewanczyk, Dawid         }
5355c7b7a2SEd Tanous         const std::string& chassisName = params[0];
542474adfaSEd Tanous         auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
55413961deSRichard Marian Thomaiyar             res, chassisName, typeList, "Thermal");
562474adfaSEd Tanous 
572474adfaSEd Tanous         // TODO Need to get Chassis Redundancy information.
582474adfaSEd Tanous         getChassisData(sensorAsyncResp);
5908777fb0SLewanczyk, Dawid     }
60413961deSRichard Marian Thomaiyar     void doPatch(crow::Response& res, const crow::Request& req,
61413961deSRichard Marian Thomaiyar                  const std::vector<std::string>& params) override
62413961deSRichard Marian Thomaiyar     {
634bb3dc34SCarol Wang         if (params.size() != 1)
644bb3dc34SCarol Wang         {
654bb3dc34SCarol Wang             res.end();
664bb3dc34SCarol Wang             messages::internalError(res);
674bb3dc34SCarol Wang             return;
684bb3dc34SCarol Wang         }
694bb3dc34SCarol Wang 
704bb3dc34SCarol Wang         const std::string& chassisName = params[0];
714bb3dc34SCarol Wang         std::optional<std::vector<nlohmann::json>> temperatureCollections;
724bb3dc34SCarol Wang         std::optional<std::vector<nlohmann::json>> fanCollections;
734bb3dc34SCarol Wang         std::unordered_map<std::string, std::vector<nlohmann::json>>
744bb3dc34SCarol Wang             allCollections;
754bb3dc34SCarol Wang 
764bb3dc34SCarol Wang         auto asyncResp = std::make_shared<SensorsAsyncResp>(
774bb3dc34SCarol Wang             res, chassisName, typeList, "Thermal");
784bb3dc34SCarol Wang 
794bb3dc34SCarol Wang         if (!json_util::readJson(req, asyncResp->res, "Temperatures",
804bb3dc34SCarol Wang                                  temperatureCollections, "Fans",
814bb3dc34SCarol Wang                                  fanCollections))
824bb3dc34SCarol Wang         {
834bb3dc34SCarol Wang             return;
844bb3dc34SCarol Wang         }
854bb3dc34SCarol Wang         if (!temperatureCollections && !fanCollections)
864bb3dc34SCarol Wang         {
874bb3dc34SCarol Wang             messages::resourceNotFound(asyncResp->res, "Thermal",
884bb3dc34SCarol Wang                                        "Temperatures / Voltages");
894bb3dc34SCarol Wang             return;
904bb3dc34SCarol Wang         }
914bb3dc34SCarol Wang         if (temperatureCollections)
924bb3dc34SCarol Wang         {
934bb3dc34SCarol Wang             allCollections.emplace("Temperatures",
944bb3dc34SCarol Wang                                    *std::move(temperatureCollections));
954bb3dc34SCarol Wang         }
964bb3dc34SCarol Wang         if (fanCollections)
974bb3dc34SCarol Wang         {
984bb3dc34SCarol Wang             allCollections.emplace("Fans", *std::move(fanCollections));
994bb3dc34SCarol Wang         }
1004bb3dc34SCarol Wang 
101*397fd61fSjayaprakash Mutyala         checkAndDoSensorsOverride(asyncResp, allCollections);
102413961deSRichard Marian Thomaiyar     }
10308777fb0SLewanczyk, Dawid };
10408777fb0SLewanczyk, Dawid 
10508777fb0SLewanczyk, Dawid } // namespace redfish
106