xref: /openbmc/bmcweb/features/redfish/lib/thermal.hpp (revision 52cc112d962920b035c870127784bcbd98948fad)
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:
27*52cc112dSEd 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:
4055c7b7a2SEd Tanous     void doGet(crow::Response& res, const crow::Request& req,
411abe55efSEd Tanous                const std::vector<std::string>& params) override
421abe55efSEd Tanous     {
431abe55efSEd Tanous         if (params.size() != 1)
441abe55efSEd Tanous         {
45f12894f8SJason M. Bills             messages::internalError(res);
4608777fb0SLewanczyk, Dawid             res.end();
4708777fb0SLewanczyk, Dawid             return;
4808777fb0SLewanczyk, Dawid         }
4955c7b7a2SEd Tanous         const std::string& chassisName = params[0];
502474adfaSEd Tanous         auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
51a0ec28b6SAdrian Ambrożewicz             res, chassisName, sensors::dbus::types.at(sensors::node::thermal),
52a0ec28b6SAdrian Ambrożewicz             sensors::node::thermal);
532474adfaSEd Tanous 
542474adfaSEd Tanous         // TODO Need to get Chassis Redundancy information.
552474adfaSEd Tanous         getChassisData(sensorAsyncResp);
5608777fb0SLewanczyk, Dawid     }
57413961deSRichard Marian Thomaiyar     void doPatch(crow::Response& res, const crow::Request& req,
58413961deSRichard Marian Thomaiyar                  const std::vector<std::string>& params) override
59413961deSRichard Marian Thomaiyar     {
604bb3dc34SCarol Wang         if (params.size() != 1)
614bb3dc34SCarol Wang         {
624bb3dc34SCarol Wang             res.end();
634bb3dc34SCarol Wang             messages::internalError(res);
644bb3dc34SCarol Wang             return;
654bb3dc34SCarol Wang         }
664bb3dc34SCarol Wang 
674bb3dc34SCarol Wang         const std::string& chassisName = params[0];
684bb3dc34SCarol Wang         std::optional<std::vector<nlohmann::json>> temperatureCollections;
694bb3dc34SCarol Wang         std::optional<std::vector<nlohmann::json>> fanCollections;
704bb3dc34SCarol Wang         std::unordered_map<std::string, std::vector<nlohmann::json>>
714bb3dc34SCarol Wang             allCollections;
724bb3dc34SCarol Wang 
734bb3dc34SCarol Wang         auto asyncResp = std::make_shared<SensorsAsyncResp>(
74a0ec28b6SAdrian Ambrożewicz             res, chassisName, sensors::dbus::types.at(sensors::node::thermal),
75a0ec28b6SAdrian Ambrożewicz             sensors::node::thermal);
764bb3dc34SCarol Wang 
774bb3dc34SCarol Wang         if (!json_util::readJson(req, asyncResp->res, "Temperatures",
784bb3dc34SCarol Wang                                  temperatureCollections, "Fans",
794bb3dc34SCarol Wang                                  fanCollections))
804bb3dc34SCarol Wang         {
814bb3dc34SCarol Wang             return;
824bb3dc34SCarol Wang         }
834bb3dc34SCarol Wang         if (!temperatureCollections && !fanCollections)
844bb3dc34SCarol Wang         {
854bb3dc34SCarol Wang             messages::resourceNotFound(asyncResp->res, "Thermal",
864bb3dc34SCarol Wang                                        "Temperatures / Voltages");
874bb3dc34SCarol Wang             return;
884bb3dc34SCarol Wang         }
894bb3dc34SCarol Wang         if (temperatureCollections)
904bb3dc34SCarol Wang         {
914bb3dc34SCarol Wang             allCollections.emplace("Temperatures",
924bb3dc34SCarol Wang                                    *std::move(temperatureCollections));
934bb3dc34SCarol Wang         }
944bb3dc34SCarol Wang         if (fanCollections)
954bb3dc34SCarol Wang         {
964bb3dc34SCarol Wang             allCollections.emplace("Fans", *std::move(fanCollections));
974bb3dc34SCarol Wang         }
984bb3dc34SCarol Wang 
99397fd61fSjayaprakash Mutyala         checkAndDoSensorsOverride(asyncResp, allCollections);
100413961deSRichard Marian Thomaiyar     }
10108777fb0SLewanczyk, Dawid };
10208777fb0SLewanczyk, Dawid 
10308777fb0SLewanczyk, Dawid } // namespace redfish
104