blob: 90f04e823759249126dda395abf89329e5db5048 [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
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010018#include "sensors.hpp"
19
John Edward Broadbent7e860f12021-04-08 15:57:16 -070020#include <app.hpp>
21
Ed Tanous1abe55e2018-09-05 08:30:59 -070022namespace redfish
23{
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010024
John Edward Broadbent7e860f12021-04-08 15:57:16 -070025inline void requestRoutesThermal(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -070026{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070027 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
Ed Tanous432a8902021-06-14 15:28:56 -070028 .privileges({{"Login"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -070029 .methods(boost::beast::http::verb::get)(
30 [](const crow::Request&,
31 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
32 const std::string& chassisName) {
33 auto thermalPaths =
34 sensors::dbus::paths.find(sensors::node::thermal);
35 if (thermalPaths == sensors::dbus::paths.end())
36 {
37 messages::internalError(asyncResp->res);
38 return;
39 }
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010040
John Edward Broadbent7e860f12021-04-08 15:57:16 -070041 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
42 asyncResp, chassisName, thermalPaths->second,
43 sensors::node::thermal);
zhanghch058d1b46d2021-04-01 11:18:24 +080044
John Edward Broadbent7e860f12021-04-08 15:57:16 -070045 // TODO Need to get Chassis Redundancy information.
46 getChassisData(sensorAsyncResp);
47 });
Krzysztof Grobelny1b1be672021-05-07 10:13:15 +000048
John Edward Broadbent7e860f12021-04-08 15:57:16 -070049 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
Ed Tanous432a8902021-06-14 15:28:56 -070050 .privileges({{"ConfigureManager"}})
John Edward Broadbent7e860f12021-04-08 15:57:16 -070051 .methods(boost::beast::http::verb::patch)(
52 [](const crow::Request& req,
53 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
54 const std::string& chassisName) {
55 auto thermalPaths =
56 sensors::dbus::paths.find(sensors::node::thermal);
57 if (thermalPaths == sensors::dbus::paths.end())
58 {
59 messages::internalError(asyncResp->res);
60 return;
61 }
Krzysztof Grobelny1b1be672021-05-07 10:13:15 +000062
John Edward Broadbent7e860f12021-04-08 15:57:16 -070063 std::optional<std::vector<nlohmann::json>>
64 temperatureCollections;
65 std::optional<std::vector<nlohmann::json>> fanCollections;
66 std::unordered_map<std::string, std::vector<nlohmann::json>>
67 allCollections;
Ed Tanous2474adf2018-09-05 16:31:16 -070068
John Edward Broadbent7e860f12021-04-08 15:57:16 -070069 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
70 asyncResp, chassisName, thermalPaths->second,
71 sensors::node::thermal);
zhanghch058d1b46d2021-04-01 11:18:24 +080072
John Edward Broadbent7e860f12021-04-08 15:57:16 -070073 if (!json_util::readJson(req, sensorsAsyncResp->asyncResp->res,
74 "Temperatures", temperatureCollections,
75 "Fans", fanCollections))
76 {
77 return;
78 }
79 if (!temperatureCollections && !fanCollections)
80 {
81 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
82 "Thermal",
83 "Temperatures / Voltages");
84 return;
85 }
86 if (temperatureCollections)
87 {
88 allCollections.emplace("Temperatures",
89 *std::move(temperatureCollections));
90 }
91 if (fanCollections)
92 {
93 allCollections.emplace("Fans", *std::move(fanCollections));
94 }
Bruce Lee80ac4022021-06-04 15:41:39 +080095 setSensorsOverride(sensorsAsyncResp, allCollections);
John Edward Broadbent7e860f12021-04-08 15:57:16 -070096 });
97}
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010098
Ed Tanous1abe55e2018-09-05 08:30:59 -070099} // namespace redfish