blob: e064f1f6bde755c1c0392726334d5fb3ae4d4c07 [file] [log] [blame]
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +01001/*
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
Ed Tanous1abe55e2018-09-05 08:30:59 -070021namespace redfish
22{
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010023
Ed Tanous1abe55e2018-09-05 08:30:59 -070024class Thermal : public Node
25{
26 public:
Ed Tanous52cc1122020-07-18 13:51:21 -070027 Thermal(App& app) :
Ed Tanous1abe55e2018-09-05 08:30:59 -070028 Node((app), "/redfish/v1/Chassis/<str>/Thermal/", std::string())
29 {
Ed Tanous1abe55e2018-09-05 08:30:59 -070030 entityPrivileges = {
31 {boost::beast::http::verb::get, {{"Login"}}},
32 {boost::beast::http::verb::head, {{"Login"}}},
jayaprakash Mutyala1b1b43f2020-03-28 22:56:06 +000033 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
Ed Tanous1abe55e2018-09-05 08:30:59 -070034 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
35 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
36 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010037 }
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010038
Ed Tanous1abe55e2018-09-05 08:30:59 -070039 private:
zhanghch058d1b46d2021-04-01 11:18:24 +080040 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
41 const crow::Request&,
Ed Tanous1abe55e2018-09-05 08:30:59 -070042 const std::vector<std::string>& params) override
43 {
44 if (params.size() != 1)
45 {
zhanghch058d1b46d2021-04-01 11:18:24 +080046 messages::internalError(asyncResp->res);
47
Ed Tanous1abe55e2018-09-05 08:30:59 -070048 return;
49 }
Krzysztof Grobelny1b1be672021-05-07 10:13:15 +000050
51 auto thermalPaths = sensors::dbus::paths.find(sensors::node::thermal);
52 if (thermalPaths == sensors::dbus::paths.end())
53 {
54 messages::internalError(asyncResp->res);
55 return;
56 }
57
Ed Tanous1abe55e2018-09-05 08:30:59 -070058 const std::string& chassisName = params[0];
Ed Tanous2474adf2018-09-05 16:31:16 -070059 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
Krzysztof Grobelny1b1be672021-05-07 10:13:15 +000060 asyncResp, chassisName, thermalPaths->second,
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +020061 sensors::node::thermal);
Ed Tanous2474adf2018-09-05 16:31:16 -070062
63 // TODO Need to get Chassis Redundancy information.
64 getChassisData(sensorAsyncResp);
Ed Tanous1abe55e2018-09-05 08:30:59 -070065 }
zhanghch058d1b46d2021-04-01 11:18:24 +080066 void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
67 const crow::Request& req,
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +053068 const std::vector<std::string>& params) override
69 {
Carol Wang4bb3dc32019-10-17 18:15:02 +080070 if (params.size() != 1)
71 {
zhanghch058d1b46d2021-04-01 11:18:24 +080072
73 messages::internalError(asyncResp->res);
Carol Wang4bb3dc32019-10-17 18:15:02 +080074 return;
75 }
76
Krzysztof Grobelny1b1be672021-05-07 10:13:15 +000077 auto thermalPaths = sensors::dbus::paths.find(sensors::node::thermal);
78 if (thermalPaths == sensors::dbus::paths.end())
79 {
80 messages::internalError(asyncResp->res);
81 return;
82 }
83
Carol Wang4bb3dc32019-10-17 18:15:02 +080084 const std::string& chassisName = params[0];
85 std::optional<std::vector<nlohmann::json>> temperatureCollections;
86 std::optional<std::vector<nlohmann::json>> fanCollections;
87 std::unordered_map<std::string, std::vector<nlohmann::json>>
88 allCollections;
89
zhanghch058d1b46d2021-04-01 11:18:24 +080090 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
Krzysztof Grobelny1b1be672021-05-07 10:13:15 +000091 asyncResp, chassisName, thermalPaths->second,
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +020092 sensors::node::thermal);
Carol Wang4bb3dc32019-10-17 18:15:02 +080093
zhanghch058d1b46d2021-04-01 11:18:24 +080094 if (!json_util::readJson(req, sensorsAsyncResp->asyncResp->res,
95 "Temperatures", temperatureCollections, "Fans",
Carol Wang4bb3dc32019-10-17 18:15:02 +080096 fanCollections))
97 {
98 return;
99 }
100 if (!temperatureCollections && !fanCollections)
101 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800102 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
103 "Thermal", "Temperatures / Voltages");
Carol Wang4bb3dc32019-10-17 18:15:02 +0800104 return;
105 }
106 if (temperatureCollections)
107 {
108 allCollections.emplace("Temperatures",
109 *std::move(temperatureCollections));
110 }
111 if (fanCollections)
112 {
113 allCollections.emplace("Fans", *std::move(fanCollections));
114 }
115
zhanghch058d1b46d2021-04-01 11:18:24 +0800116 checkAndDoSensorsOverride(sensorsAsyncResp, allCollections);
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530117 }
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100118};
119
Ed Tanous1abe55e2018-09-05 08:30:59 -0700120} // namespace redfish