blob: e58e86fa4bb54a548fdf6c8d224d11d33dae674a [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 sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
Ed Tanous02da7c52022-02-27 00:09:02 -080041 asyncResp, chassisName, sensors::dbus::thermalPaths,
John Edward Broadbent7e860f12021-04-08 15:57:16 -070042 sensors::node::thermal);
zhanghch058d1b46d2021-04-01 11:18:24 +080043
John Edward Broadbent7e860f12021-04-08 15:57:16 -070044 // TODO Need to get Chassis Redundancy information.
45 getChassisData(sensorAsyncResp);
46 });
Krzysztof Grobelny1b1be672021-05-07 10:13:15 +000047
John Edward Broadbent7e860f12021-04-08 15:57:16 -070048 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
Ed Tanoused398212021-06-09 17:05:54 -070049 .privileges(redfish::privileges::patchThermal)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070050 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -070051 [&app](const crow::Request& req,
52 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
53 const std::string& chassisName) {
54 if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
55 {
56 return;
57 }
58
John Edward Broadbent7e860f12021-04-08 15:57:16 -070059 std::optional<std::vector<nlohmann::json>>
60 temperatureCollections;
61 std::optional<std::vector<nlohmann::json>> fanCollections;
62 std::unordered_map<std::string, std::vector<nlohmann::json>>
63 allCollections;
Ed Tanous2474adf2018-09-05 16:31:16 -070064
John Edward Broadbent7e860f12021-04-08 15:57:16 -070065 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
Ed Tanous02da7c52022-02-27 00:09:02 -080066 asyncResp, chassisName, sensors::dbus::thermalPaths,
John Edward Broadbent7e860f12021-04-08 15:57:16 -070067 sensors::node::thermal);
zhanghch058d1b46d2021-04-01 11:18:24 +080068
Willy Tu15ed6782021-12-14 11:03:16 -080069 if (!json_util::readJsonPatch(
70 req, sensorsAsyncResp->asyncResp->res, "Temperatures",
71 temperatureCollections, "Fans", fanCollections))
John Edward Broadbent7e860f12021-04-08 15:57:16 -070072 {
73 return;
74 }
75 if (!temperatureCollections && !fanCollections)
76 {
77 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
78 "Thermal",
79 "Temperatures / Voltages");
80 return;
81 }
82 if (temperatureCollections)
83 {
84 allCollections.emplace("Temperatures",
85 *std::move(temperatureCollections));
86 }
87 if (fanCollections)
88 {
89 allCollections.emplace("Fans", *std::move(fanCollections));
90 }
Bruce Lee80ac4022021-06-04 15:41:39 +080091 setSensorsOverride(sensorsAsyncResp, allCollections);
John Edward Broadbent7e860f12021-04-08 15:57:16 -070092 });
93}
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010094
Ed Tanous1abe55e2018-09-05 08:30:59 -070095} // namespace redfish