blob: 7a5586f652523e0a582cccdbf3b224c60fa19a55 [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"
Ed Tanous5b904292024-04-16 11:10:17 -070022#include "utils/json_utils.hpp"
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010023
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) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040035 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
36 {
37 return;
38 }
Ed Tanous45ca1b82022-03-25 13:07:27 -070039
Patrick Williamsbd79bce2024-08-16 15:22:20 -040040 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
41 asyncResp, chassisName, sensors::dbus::thermalPaths,
42 sensors::node::thermal);
zhanghch058d1b46d2021-04-01 11:18:24 +080043
Patrick Williamsbd79bce2024-08-16 15:22:20 -040044 // 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) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040054 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
55 {
56 return;
57 }
Ed Tanous45ca1b82022-03-25 13:07:27 -070058
Patrick Williamsbd79bce2024-08-16 15:22:20 -040059 std::optional<std::vector<nlohmann::json::object_t>>
60 temperatureCollections;
61 std::optional<std::vector<nlohmann::json::object_t>>
62 fanCollections;
63 std::unordered_map<std::string,
64 std::vector<nlohmann::json::object_t>>
65 allCollections;
Ed Tanous2474adf2018-09-05 16:31:16 -070066
Patrick Williamsbd79bce2024-08-16 15:22:20 -040067 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
68 asyncResp, chassisName, sensors::dbus::thermalPaths,
69 sensors::node::thermal);
zhanghch058d1b46d2021-04-01 11:18:24 +080070
Patrick Williamsbd79bce2024-08-16 15:22:20 -040071 if (!json_util::readJsonPatch(
72 req, sensorsAsyncResp->asyncResp->res, "Temperatures",
73 temperatureCollections, "Fans", fanCollections))
74 {
75 return;
76 }
77 if (!temperatureCollections && !fanCollections)
78 {
79 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
80 "Thermal",
81 "Temperatures / Voltages");
82 return;
83 }
84 if (temperatureCollections)
85 {
86 allCollections.emplace("Temperatures",
87 *std::move(temperatureCollections));
88 }
89 if (fanCollections)
90 {
91 allCollections.emplace("Fans", *std::move(fanCollections));
92 }
93 setSensorsOverride(sensorsAsyncResp, allCollections);
94 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -070095}
Lewanczyk, Dawid08777fb2018-03-22 23:33:49 +010096
Ed Tanous1abe55e2018-09-05 08:30:59 -070097} // namespace redfish