blob: ff7d52cd2280f4210c5897560826bbb3ea02e3b5 [file] [log] [blame]
Chicago Duan77b36432021-02-05 15:48:26 +08001#pragma once
2
3#include "app.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -07004#include "generated/enums/resource.hpp"
Nan Zhouca9e6be2022-11-08 17:28:35 +00005#include "logging.hpp"
Chicago Duan77b36432021-02-05 15:48:26 +08006#include "query.hpp"
7#include "registries/privilege_registry.hpp"
8#include "utils/chassis_utils.hpp"
9
Ed Tanousef4c65b2023-04-24 15:28:50 -070010#include <boost/url/format.hpp>
11
Chicago Duan77b36432021-02-05 15:48:26 +080012#include <memory>
13#include <optional>
14#include <string>
15
16namespace redfish
17{
18
19inline void doPowerSubsystemCollection(
20 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
21 const std::string& chassisId,
22 const std::optional<std::string>& validChassisPath)
23{
24 if (!validChassisPath)
25 {
Chicago Duan77b36432021-02-05 15:48:26 +080026 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
27 return;
28 }
29
George Liu2ea468a2022-10-26 13:52:47 +080030 asyncResp->res.addHeader(
31 boost::beast::http::field::link,
32 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
Chicago Duan77b36432021-02-05 15:48:26 +080033 asyncResp->res.jsonValue["@odata.type"] =
34 "#PowerSubsystem.v1_1_0.PowerSubsystem";
35 asyncResp->res.jsonValue["Name"] = "Power Subsystem";
36 asyncResp->res.jsonValue["Id"] = "PowerSubsystem";
Ed Tanousef4c65b2023-04-24 15:28:50 -070037 asyncResp->res.jsonValue["@odata.id"] =
38 boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem", chassisId);
Ed Tanous539d8c62024-06-19 14:38:27 -070039 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
40 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
George Liua7210022022-10-05 15:44:11 +080041 asyncResp->res.jsonValue["PowerSupplies"]["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -070042 boost::urls::format(
43 "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies", chassisId);
George Liu2ea468a2022-10-26 13:52:47 +080044}
Chicago Duan77b36432021-02-05 15:48:26 +080045
George Liu2ea468a2022-10-26 13:52:47 +080046inline void handlePowerSubsystemCollectionHead(
47 App& app, const crow::Request& req,
48 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
49 const std::string& chassisId)
50{
51 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
52 {
53 return;
54 }
55
56 auto respHandler = [asyncResp, chassisId](
57 const std::optional<std::string>& validChassisPath) {
58 if (!validChassisPath)
59 {
60 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
61 return;
62 }
63 asyncResp->res.addHeader(
64 boost::beast::http::field::link,
65 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
66 };
67 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
68 std::move(respHandler));
Chicago Duan77b36432021-02-05 15:48:26 +080069}
70
71inline void handlePowerSubsystemCollectionGet(
72 App& app, const crow::Request& req,
73 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
74 const std::string& chassisId)
75{
76 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
77 {
78 return;
79 }
80
81 redfish::chassis_utils::getValidChassisPath(
82 asyncResp, chassisId,
83 std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId));
84}
85
86inline void requestRoutesPowerSubsystem(App& app)
87{
88 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
George Liu2ea468a2022-10-26 13:52:47 +080089 .privileges(redfish::privileges::headPowerSubsystem)
90 .methods(boost::beast::http::verb::head)(
91 std::bind_front(handlePowerSubsystemCollectionHead, std::ref(app)));
92
93 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
Chicago Duan77b36432021-02-05 15:48:26 +080094 .privileges(redfish::privileges::getPowerSubsystem)
95 .methods(boost::beast::http::verb::get)(
96 std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app)));
97}
98
99} // namespace redfish