xref: /openbmc/bmcweb/features/redfish/lib/thermal.hpp (revision 6ea007a2faec52ad62680015d2a3f00371a1e351)
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 "node.hpp"
19 #include "sensors.hpp"
20 
21 namespace redfish
22 {
23 
24 class Thermal : public Node
25 {
26   public:
27     Thermal(CrowApp& app) :
28         Node((app), "/redfish/v1/Chassis/<str>/Thermal/", std::string())
29     {
30         entityPrivileges = {
31             {boost::beast::http::verb::get, {{"Login"}}},
32             {boost::beast::http::verb::head, {{"Login"}}},
33             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
34             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
35             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
36             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
37     }
38 
39   private:
40     std::vector<const char*> typeList = {
41         "/xyz/openbmc_project/sensors/fan_tach",
42         "/xyz/openbmc_project/sensors/temperature",
43         "/xyz/openbmc_project/sensors/fan_pwm"};
44     void doGet(crow::Response& res, const crow::Request& req,
45                const std::vector<std::string>& params) override
46     {
47         if (params.size() != 1)
48         {
49             messages::internalError(res);
50             res.end();
51             return;
52         }
53         const std::string& chassisName = params[0];
54 #ifdef BMCWEB_ENABLE_REDFISH_ONE_CHASSIS
55         // In a one chassis system the only supported name is "chassis"
56         if (chassisName != "chassis")
57         {
58             messages::resourceNotFound(res, "#Chassis.v1_4_0.Chassis",
59                                        chassisName);
60             res.end();
61             return;
62         }
63 #endif
64 
65         res.jsonValue["@odata.type"] = "#Thermal.v1_4_0.Thermal";
66         res.jsonValue["@odata.context"] =
67             "/redfish/v1/$metadata#Thermal.Thermal";
68         res.jsonValue["Id"] = "Thermal";
69         res.jsonValue["Name"] = "Thermal";
70 
71         res.jsonValue["@odata.id"] =
72             "/redfish/v1/Chassis/" + chassisName + "/Thermal";
73 
74         auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
75             res, chassisName, typeList, "Thermal");
76 
77         // TODO Need to get Chassis Redundancy information.
78         getChassisData(sensorAsyncResp);
79     }
80     void doPatch(crow::Response& res, const crow::Request& req,
81                  const std::vector<std::string>& params) override
82     {
83         setSensorOverride(res, req, params, typeList, "Thermal");
84     }
85 };
86 
87 } // namespace redfish
88