blob: 24baa89e93dff8162696da037b06a25d1fc5e04b [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Chicago Duan77b36432021-02-05 15:48:26 +08003#pragma once
4
5#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08006#include "async_resp.hpp"
7#include "error_messages.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -07008#include "generated/enums/resource.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08009#include "http_request.hpp"
Chicago Duan77b36432021-02-05 15:48:26 +080010#include "query.hpp"
11#include "registries/privilege_registry.hpp"
12#include "utils/chassis_utils.hpp"
13
Ed Tanousd7857202025-01-28 15:32:26 -080014#include <boost/beast/http/field.hpp>
15#include <boost/beast/http/verb.hpp>
Ed Tanousef4c65b2023-04-24 15:28:50 -070016#include <boost/url/format.hpp>
17
Ed Tanousd7857202025-01-28 15:32:26 -080018#include <functional>
Chicago Duan77b36432021-02-05 15:48:26 +080019#include <memory>
20#include <optional>
21#include <string>
Ed Tanousd7857202025-01-28 15:32:26 -080022#include <utility>
Chicago Duan77b36432021-02-05 15:48:26 +080023
24namespace redfish
25{
26
27inline void doPowerSubsystemCollection(
28 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
29 const std::string& chassisId,
30 const std::optional<std::string>& validChassisPath)
31{
32 if (!validChassisPath)
33 {
Chicago Duan77b36432021-02-05 15:48:26 +080034 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
35 return;
36 }
37
George Liu2ea468a2022-10-26 13:52:47 +080038 asyncResp->res.addHeader(
39 boost::beast::http::field::link,
40 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
Chicago Duan77b36432021-02-05 15:48:26 +080041 asyncResp->res.jsonValue["@odata.type"] =
42 "#PowerSubsystem.v1_1_0.PowerSubsystem";
43 asyncResp->res.jsonValue["Name"] = "Power Subsystem";
44 asyncResp->res.jsonValue["Id"] = "PowerSubsystem";
Ed Tanousef4c65b2023-04-24 15:28:50 -070045 asyncResp->res.jsonValue["@odata.id"] =
46 boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem", chassisId);
Ed Tanous539d8c62024-06-19 14:38:27 -070047 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
48 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
George Liua7210022022-10-05 15:44:11 +080049 asyncResp->res.jsonValue["PowerSupplies"]["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -070050 boost::urls::format(
51 "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies", chassisId);
George Liu2ea468a2022-10-26 13:52:47 +080052}
Chicago Duan77b36432021-02-05 15:48:26 +080053
George Liu2ea468a2022-10-26 13:52:47 +080054inline void handlePowerSubsystemCollectionHead(
55 App& app, const crow::Request& req,
56 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
57 const std::string& chassisId)
58{
59 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
60 {
61 return;
62 }
63
64 auto respHandler = [asyncResp, chassisId](
65 const std::optional<std::string>& validChassisPath) {
66 if (!validChassisPath)
67 {
68 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
69 return;
70 }
71 asyncResp->res.addHeader(
72 boost::beast::http::field::link,
73 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
74 };
75 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
76 std::move(respHandler));
Chicago Duan77b36432021-02-05 15:48:26 +080077}
78
79inline void handlePowerSubsystemCollectionGet(
80 App& app, const crow::Request& req,
81 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
82 const std::string& chassisId)
83{
84 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
85 {
86 return;
87 }
88
89 redfish::chassis_utils::getValidChassisPath(
90 asyncResp, chassisId,
91 std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId));
92}
93
94inline void requestRoutesPowerSubsystem(App& app)
95{
96 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
George Liu2ea468a2022-10-26 13:52:47 +080097 .privileges(redfish::privileges::headPowerSubsystem)
98 .methods(boost::beast::http::verb::head)(
99 std::bind_front(handlePowerSubsystemCollectionHead, std::ref(app)));
100
101 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
Chicago Duan77b36432021-02-05 15:48:26 +0800102 .privileges(redfish::privileges::getPowerSubsystem)
103 .methods(boost::beast::http::verb::get)(
104 std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app)));
105}
106
107} // namespace redfish