blob: d54fd1838919b8c40a270790167a0e8ad3db862f [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
Ed Tanousef4c65b2023-04-24 15:28:50 -07009#include <boost/url/format.hpp>
10
Chicago Duan77b36432021-02-05 15:48:26 +080011#include <memory>
12#include <optional>
13#include <string>
14
15namespace redfish
16{
17
18inline void doPowerSubsystemCollection(
19 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
20 const std::string& chassisId,
21 const std::optional<std::string>& validChassisPath)
22{
23 if (!validChassisPath)
24 {
Chicago Duan77b36432021-02-05 15:48:26 +080025 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
26 return;
27 }
28
George Liu2ea468a2022-10-26 13:52:47 +080029 asyncResp->res.addHeader(
30 boost::beast::http::field::link,
31 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
Chicago Duan77b36432021-02-05 15:48:26 +080032 asyncResp->res.jsonValue["@odata.type"] =
33 "#PowerSubsystem.v1_1_0.PowerSubsystem";
34 asyncResp->res.jsonValue["Name"] = "Power Subsystem";
35 asyncResp->res.jsonValue["Id"] = "PowerSubsystem";
Ed Tanousef4c65b2023-04-24 15:28:50 -070036 asyncResp->res.jsonValue["@odata.id"] =
37 boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem", chassisId);
Chicago Duan77b36432021-02-05 15:48:26 +080038 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
39 asyncResp->res.jsonValue["Status"]["Health"] = "OK";
George Liua7210022022-10-05 15:44:11 +080040 asyncResp->res.jsonValue["PowerSupplies"]["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -070041 boost::urls::format(
42 "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies", chassisId);
George Liu2ea468a2022-10-26 13:52:47 +080043}
Chicago Duan77b36432021-02-05 15:48:26 +080044
George Liu2ea468a2022-10-26 13:52:47 +080045inline void handlePowerSubsystemCollectionHead(
46 App& app, const crow::Request& req,
47 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
48 const std::string& chassisId)
49{
50 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
51 {
52 return;
53 }
54
55 auto respHandler = [asyncResp, chassisId](
56 const std::optional<std::string>& validChassisPath) {
57 if (!validChassisPath)
58 {
59 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
60 return;
61 }
62 asyncResp->res.addHeader(
63 boost::beast::http::field::link,
64 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
65 };
66 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
67 std::move(respHandler));
Chicago Duan77b36432021-02-05 15:48:26 +080068}
69
70inline void handlePowerSubsystemCollectionGet(
71 App& app, const crow::Request& req,
72 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
73 const std::string& chassisId)
74{
75 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
76 {
77 return;
78 }
79
80 redfish::chassis_utils::getValidChassisPath(
81 asyncResp, chassisId,
82 std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId));
83}
84
85inline void requestRoutesPowerSubsystem(App& app)
86{
87 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
George Liu2ea468a2022-10-26 13:52:47 +080088 .privileges(redfish::privileges::headPowerSubsystem)
89 .methods(boost::beast::http::verb::head)(
90 std::bind_front(handlePowerSubsystemCollectionHead, std::ref(app)));
91
92 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
Chicago Duan77b36432021-02-05 15:48:26 +080093 .privileges(redfish::privileges::getPowerSubsystem)
94 .methods(boost::beast::http::verb::get)(
95 std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app)));
96}
97
98} // namespace redfish