blob: 8e01bee1bf1f0b6d7fbd4d17894352b5d5d0789b [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:
Ed Tanouscb13a392020-07-25 19:02:03 +000040 void doGet(crow::Response& res, const crow::Request&,
Ed Tanous1abe55e2018-09-05 08:30:59 -070041 const std::vector<std::string>& params) override
42 {
43 if (params.size() != 1)
44 {
Jason M. Billsf12894f2018-10-09 12:45:45 -070045 messages::internalError(res);
Ed Tanous1abe55e2018-09-05 08:30:59 -070046 res.end();
47 return;
48 }
49 const std::string& chassisName = params[0];
Ed Tanous2474adf2018-09-05 16:31:16 -070050 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +020051 res, chassisName, sensors::dbus::types.at(sensors::node::thermal),
52 sensors::node::thermal);
Ed Tanous2474adf2018-09-05 16:31:16 -070053
54 // TODO Need to get Chassis Redundancy information.
55 getChassisData(sensorAsyncResp);
Ed Tanous1abe55e2018-09-05 08:30:59 -070056 }
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +053057 void doPatch(crow::Response& res, const crow::Request& req,
58 const std::vector<std::string>& params) override
59 {
Carol Wang4bb3dc32019-10-17 18:15:02 +080060 if (params.size() != 1)
61 {
62 res.end();
63 messages::internalError(res);
64 return;
65 }
66
67 const std::string& chassisName = params[0];
68 std::optional<std::vector<nlohmann::json>> temperatureCollections;
69 std::optional<std::vector<nlohmann::json>> fanCollections;
70 std::unordered_map<std::string, std::vector<nlohmann::json>>
71 allCollections;
72
73 auto asyncResp = std::make_shared<SensorsAsyncResp>(
Adrian Ambrożewicza0ec28b2020-04-10 14:47:28 +020074 res, chassisName, sensors::dbus::types.at(sensors::node::thermal),
75 sensors::node::thermal);
Carol Wang4bb3dc32019-10-17 18:15:02 +080076
77 if (!json_util::readJson(req, asyncResp->res, "Temperatures",
78 temperatureCollections, "Fans",
79 fanCollections))
80 {
81 return;
82 }
83 if (!temperatureCollections && !fanCollections)
84 {
85 messages::resourceNotFound(asyncResp->res, "Thermal",
86 "Temperatures / Voltages");
87 return;
88 }
89 if (temperatureCollections)
90 {
91 allCollections.emplace("Temperatures",
92 *std::move(temperatureCollections));
93 }
94 if (fanCollections)
95 {
96 allCollections.emplace("Fans", *std::move(fanCollections));
97 }
98
jayaprakash Mutyala397fd612020-02-06 23:33:34 +000099 checkAndDoSensorsOverride(asyncResp, allCollections);
Richard Marian Thomaiyar413961d2019-02-01 00:43:39 +0530100 }
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100101};
102
Ed Tanous1abe55e2018-09-05 08:30:59 -0700103} // namespace redfish