blob: 52e1ec9d72f321732cbe5c4b704066455bb19466 [file] [log] [blame]
Chicago Duan77b36432021-02-05 15:48:26 +08001#pragma once
2
3#include "app.hpp"
Nan Zhouca9e6be2022-11-08 17:28:35 +00004#include "logging.hpp"
Chicago Duan77b36432021-02-05 15:48:26 +08005#include "query.hpp"
6#include "registries/privilege_registry.hpp"
7#include "utils/chassis_utils.hpp"
8
9#include <memory>
10#include <optional>
11#include <string>
12
13namespace redfish
14{
15
16inline void doPowerSubsystemCollection(
17 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
18 const std::string& chassisId,
19 const std::optional<std::string>& validChassisPath)
20{
21 if (!validChassisPath)
22 {
Chicago Duan77b36432021-02-05 15:48:26 +080023 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
24 return;
25 }
26
George Liu2ea468a2022-10-26 13:52:47 +080027 asyncResp->res.addHeader(
28 boost::beast::http::field::link,
29 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
Chicago Duan77b36432021-02-05 15:48:26 +080030 asyncResp->res.jsonValue["@odata.type"] =
31 "#PowerSubsystem.v1_1_0.PowerSubsystem";
32 asyncResp->res.jsonValue["Name"] = "Power Subsystem";
33 asyncResp->res.jsonValue["Id"] = "PowerSubsystem";
34 asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
35 "redfish", "v1", "Chassis", chassisId, "PowerSubsystem");
36 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
37 asyncResp->res.jsonValue["Status"]["Health"] = "OK";
George Liua7210022022-10-05 15:44:11 +080038 asyncResp->res.jsonValue["PowerSupplies"]["@odata.id"] =
39 crow::utility::urlFromPieces("redfish", "v1", "Chassis", chassisId,
40 "PowerSubsystem", "PowerSupplies");
George Liu2ea468a2022-10-26 13:52:47 +080041}
Chicago Duan77b36432021-02-05 15:48:26 +080042
George Liu2ea468a2022-10-26 13:52:47 +080043inline void handlePowerSubsystemCollectionHead(
44 App& app, const crow::Request& req,
45 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
46 const std::string& chassisId)
47{
48 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
49 {
50 return;
51 }
52
53 auto respHandler = [asyncResp, chassisId](
54 const std::optional<std::string>& validChassisPath) {
55 if (!validChassisPath)
56 {
57 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
58 return;
59 }
60 asyncResp->res.addHeader(
61 boost::beast::http::field::link,
62 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
63 };
64 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
65 std::move(respHandler));
Chicago Duan77b36432021-02-05 15:48:26 +080066}
67
68inline void handlePowerSubsystemCollectionGet(
69 App& app, const crow::Request& req,
70 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
71 const std::string& chassisId)
72{
73 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
74 {
75 return;
76 }
77
78 redfish::chassis_utils::getValidChassisPath(
79 asyncResp, chassisId,
80 std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId));
81}
82
83inline void requestRoutesPowerSubsystem(App& app)
84{
85 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
George Liu2ea468a2022-10-26 13:52:47 +080086 .privileges(redfish::privileges::headPowerSubsystem)
87 .methods(boost::beast::http::verb::head)(
88 std::bind_front(handlePowerSubsystemCollectionHead, std::ref(app)));
89
90 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
Chicago Duan77b36432021-02-05 15:48:26 +080091 .privileges(redfish::privileges::getPowerSubsystem)
92 .methods(boost::beast::http::verb::get)(
93 std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app)));
94}
95
96} // namespace redfish