blob: 17ee1af6086ea644033c5dc442aad75a779c1b19 [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 Liu2ea468a2022-10-26 13:52:47 +080038}
Chicago Duan77b36432021-02-05 15:48:26 +080039
George Liu2ea468a2022-10-26 13:52:47 +080040inline void handlePowerSubsystemCollectionHead(
41 App& app, const crow::Request& req,
42 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
43 const std::string& chassisId)
44{
45 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
46 {
47 return;
48 }
49
50 auto respHandler = [asyncResp, chassisId](
51 const std::optional<std::string>& validChassisPath) {
52 if (!validChassisPath)
53 {
54 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
55 return;
56 }
57 asyncResp->res.addHeader(
58 boost::beast::http::field::link,
59 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
60 };
61 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
62 std::move(respHandler));
Chicago Duan77b36432021-02-05 15:48:26 +080063}
64
65inline void handlePowerSubsystemCollectionGet(
66 App& app, const crow::Request& req,
67 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
68 const std::string& chassisId)
69{
70 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
71 {
72 return;
73 }
74
75 redfish::chassis_utils::getValidChassisPath(
76 asyncResp, chassisId,
77 std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId));
78}
79
80inline void requestRoutesPowerSubsystem(App& app)
81{
82 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
George Liu2ea468a2022-10-26 13:52:47 +080083 .privileges(redfish::privileges::headPowerSubsystem)
84 .methods(boost::beast::http::verb::head)(
85 std::bind_front(handlePowerSubsystemCollectionHead, std::ref(app)));
86
87 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
Chicago Duan77b36432021-02-05 15:48:26 +080088 .privileges(redfish::privileges::getPowerSubsystem)
89 .methods(boost::beast::http::verb::get)(
90 std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app)));
91}
92
93} // namespace redfish