blob: 847d17043c557c687e320a160a0a70235825d1ad [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>
Ed Tanous45ca1b82022-03-25 13:07:27 -070021#include <query.hpp>
Ed Tanoused398212021-06-09 17:05:54 -070022#include <registries/privilege_registry.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070023
Ed Tanous1abe55e2018-09-05 08:30:59 -070024namespace redfish
25{
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010026
John Edward Broadbent7e860f12021-04-08 15:57:16 -070027inline void requestRoutesThermal(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -070028{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070029 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
Ed Tanoused398212021-06-09 17:05:54 -070030 .privileges(redfish::privileges::getThermal)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070031 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -070032 [&app](const crow::Request& req,
33 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
34 const std::string& chassisName) {
35 if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
36 {
37 return;
38 }
39
John Edward Broadbent7e860f12021-04-08 15:57:16 -070040 auto thermalPaths =
41 sensors::dbus::paths.find(sensors::node::thermal);
42 if (thermalPaths == sensors::dbus::paths.end())
43 {
44 messages::internalError(asyncResp->res);
45 return;
46 }
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010047
John Edward Broadbent7e860f12021-04-08 15:57:16 -070048 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
49 asyncResp, chassisName, thermalPaths->second,
50 sensors::node::thermal);
zhanghch058d1b46d2021-04-01 11:18:24 +080051
John Edward Broadbent7e860f12021-04-08 15:57:16 -070052 // TODO Need to get Chassis Redundancy information.
53 getChassisData(sensorAsyncResp);
54 });
Krzysztof Grobelny1b1be672021-05-07 10:13:15 +000055
John Edward Broadbent7e860f12021-04-08 15:57:16 -070056 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
Ed Tanoused398212021-06-09 17:05:54 -070057 .privileges(redfish::privileges::patchThermal)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070058 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -070059 [&app](const crow::Request& req,
60 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
61 const std::string& chassisName) {
62 if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
63 {
64 return;
65 }
66
John Edward Broadbent7e860f12021-04-08 15:57:16 -070067 auto thermalPaths =
68 sensors::dbus::paths.find(sensors::node::thermal);
69 if (thermalPaths == sensors::dbus::paths.end())
70 {
71 messages::internalError(asyncResp->res);
72 return;
73 }
Krzysztof Grobelny1b1be672021-05-07 10:13:15 +000074
John Edward Broadbent7e860f12021-04-08 15:57:16 -070075 std::optional<std::vector<nlohmann::json>>
76 temperatureCollections;
77 std::optional<std::vector<nlohmann::json>> fanCollections;
78 std::unordered_map<std::string, std::vector<nlohmann::json>>
79 allCollections;
Ed Tanous2474adf2018-09-05 16:31:16 -070080
John Edward Broadbent7e860f12021-04-08 15:57:16 -070081 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
82 asyncResp, chassisName, thermalPaths->second,
83 sensors::node::thermal);
zhanghch058d1b46d2021-04-01 11:18:24 +080084
Willy Tu15ed6782021-12-14 11:03:16 -080085 if (!json_util::readJsonPatch(
86 req, sensorsAsyncResp->asyncResp->res, "Temperatures",
87 temperatureCollections, "Fans", fanCollections))
John Edward Broadbent7e860f12021-04-08 15:57:16 -070088 {
89 return;
90 }
91 if (!temperatureCollections && !fanCollections)
92 {
93 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
94 "Thermal",
95 "Temperatures / Voltages");
96 return;
97 }
98 if (temperatureCollections)
99 {
100 allCollections.emplace("Temperatures",
101 *std::move(temperatureCollections));
102 }
103 if (fanCollections)
104 {
105 allCollections.emplace("Fans", *std::move(fanCollections));
106 }
Bruce Lee80ac4022021-06-04 15:41:39 +0800107 setSensorsOverride(sensorsAsyncResp, allCollections);
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700108 });
109}
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +0100110
Ed Tanous1abe55e2018-09-05 08:30:59 -0700111} // namespace redfish