blob: cc548e17d00809cc4fce42b41dd86c41cd8379ea [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
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "app.hpp"
19#include "query.hpp"
20#include "registries/privilege_registry.hpp"
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010021#include "sensors.hpp"
22
Ed Tanous1abe55e2018-09-05 08:30:59 -070023namespace redfish
24{
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010025
John Edward Broadbent7e860f12021-04-08 15:57:16 -070026inline void requestRoutesThermal(App& app)
Ed Tanous1abe55e2018-09-05 08:30:59 -070027{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070028 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
Ed Tanoused398212021-06-09 17:05:54 -070029 .privileges(redfish::privileges::getThermal)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070030 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -070031 [&app](const crow::Request& req,
32 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
33 const std::string& chassisName) {
Carson Labrado3ba00072022-06-06 19:40:56 +000034 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -070035 {
36 return;
37 }
Ed Tanous45ca1b82022-03-25 13:07:27 -070038
Ed Tanous002d39b2022-05-31 08:59:27 -070039 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
40 asyncResp, chassisName, sensors::dbus::thermalPaths,
41 sensors::node::thermal);
zhanghch058d1b46d2021-04-01 11:18:24 +080042
Ed Tanous002d39b2022-05-31 08:59:27 -070043 // TODO Need to get Chassis Redundancy information.
44 getChassisData(sensorAsyncResp);
45 });
Krzysztof Grobelny1b1be672021-05-07 10:13:15 +000046
John Edward Broadbent7e860f12021-04-08 15:57:16 -070047 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
Ed Tanoused398212021-06-09 17:05:54 -070048 .privileges(redfish::privileges::patchThermal)
John Edward Broadbent7e860f12021-04-08 15:57:16 -070049 .methods(boost::beast::http::verb::patch)(
Ed Tanous45ca1b82022-03-25 13:07:27 -070050 [&app](const crow::Request& req,
51 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
52 const std::string& chassisName) {
Carson Labrado3ba00072022-06-06 19:40:56 +000053 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -070054 {
55 return;
56 }
Ed Tanous45ca1b82022-03-25 13:07:27 -070057
Ed Tanous002d39b2022-05-31 08:59:27 -070058 std::optional<std::vector<nlohmann::json>> temperatureCollections;
59 std::optional<std::vector<nlohmann::json>> fanCollections;
60 std::unordered_map<std::string, std::vector<nlohmann::json>>
61 allCollections;
Ed Tanous2474adf2018-09-05 16:31:16 -070062
Ed Tanous002d39b2022-05-31 08:59:27 -070063 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
64 asyncResp, chassisName, sensors::dbus::thermalPaths,
65 sensors::node::thermal);
zhanghch058d1b46d2021-04-01 11:18:24 +080066
Ed Tanous002d39b2022-05-31 08:59:27 -070067 if (!json_util::readJsonPatch(req, sensorsAsyncResp->asyncResp->res,
68 "Temperatures", temperatureCollections,
69 "Fans", fanCollections))
70 {
71 return;
72 }
73 if (!temperatureCollections && !fanCollections)
74 {
75 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
76 "Thermal", "Temperatures / Voltages");
77 return;
78 }
79 if (temperatureCollections)
80 {
81 allCollections.emplace("Temperatures",
82 *std::move(temperatureCollections));
83 }
84 if (fanCollections)
85 {
86 allCollections.emplace("Fans", *std::move(fanCollections));
87 }
88 setSensorsOverride(sensorsAsyncResp, allCollections);
89 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -070090}
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010091
Ed Tanous1abe55e2018-09-05 08:30:59 -070092} // namespace redfish