blob: af3183123830cf7e45d45f6bbbdc5ce674bcf244 [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 }
50 const std::string& chassisName = params[0];
Ed Tanous2474adf2018-09-05 16:31:16 -070051 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
zhanghch058d1b46d2021-04-01 11:18:24 +080052 asyncResp, chassisName,
53 sensors::dbus::paths.at(sensors::node::thermal),
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +020054 sensors::node::thermal);
Ed Tanous2474adf2018-09-05 16:31:16 -070055
56 // TODO Need to get Chassis Redundancy information.
57 getChassisData(sensorAsyncResp);
Ed Tanous1abe55e2018-09-05 08:30:59 -070058 }
zhanghch058d1b46d2021-04-01 11:18:24 +080059 void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
60 const crow::Request& req,
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +053061 const std::vector<std::string>& params) override
62 {
Carol Wang4bb3dc32019-10-17 18:15:02 +080063 if (params.size() != 1)
64 {
zhanghch058d1b46d2021-04-01 11:18:24 +080065
66 messages::internalError(asyncResp->res);
Carol Wang4bb3dc32019-10-17 18:15:02 +080067 return;
68 }
69
70 const std::string& chassisName = params[0];
71 std::optional<std::vector<nlohmann::json>> temperatureCollections;
72 std::optional<std::vector<nlohmann::json>> fanCollections;
73 std::unordered_map<std::string, std::vector<nlohmann::json>>
74 allCollections;
75
zhanghch058d1b46d2021-04-01 11:18:24 +080076 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
77 asyncResp, chassisName,
78 sensors::dbus::paths.at(sensors::node::thermal),
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +020079 sensors::node::thermal);
Carol Wang4bb3dc32019-10-17 18:15:02 +080080
zhanghch058d1b46d2021-04-01 11:18:24 +080081 if (!json_util::readJson(req, sensorsAsyncResp->asyncResp->res,
82 "Temperatures", temperatureCollections, "Fans",
Carol Wang4bb3dc32019-10-17 18:15:02 +080083 fanCollections))
84 {
85 return;
86 }
87 if (!temperatureCollections && !fanCollections)
88 {
zhanghch058d1b46d2021-04-01 11:18:24 +080089 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
90 "Thermal", "Temperatures / Voltages");
Carol Wang4bb3dc32019-10-17 18:15:02 +080091 return;
92 }
93 if (temperatureCollections)
94 {
95 allCollections.emplace("Temperatures",
96 *std::move(temperatureCollections));
97 }
98 if (fanCollections)
99 {
100 allCollections.emplace("Fans", *std::move(fanCollections));
101 }
102
zhanghch058d1b46d2021-04-01 11:18:24 +0800103 checkAndDoSensorsOverride(sensorsAsyncResp, allCollections);
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530104 }
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100105};
106
Ed Tanous1abe55e2018-09-05 08:30:59 -0700107} // namespace redfish