blob: c792fc83a7ea2d155e057094fb9f493b33ea1843 [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 Tanous539d8c62024-06-19 14:38:27 -07006#include "generated/enums/resource.hpp"
Nan Zhouca9e6be2022-11-08 17:28:35 +00007#include "logging.hpp"
Chicago Duan77b36432021-02-05 15:48:26 +08008#include "query.hpp"
9#include "registries/privilege_registry.hpp"
10#include "utils/chassis_utils.hpp"
11
Ed Tanousef4c65b2023-04-24 15:28:50 -070012#include <boost/url/format.hpp>
13
Chicago Duan77b36432021-02-05 15:48:26 +080014#include <memory>
15#include <optional>
16#include <string>
17
18namespace redfish
19{
20
21inline void doPowerSubsystemCollection(
22 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
23 const std::string& chassisId,
24 const std::optional<std::string>& validChassisPath)
25{
26 if (!validChassisPath)
27 {
Chicago Duan77b36432021-02-05 15:48:26 +080028 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
29 return;
30 }
31
George Liu2ea468a2022-10-26 13:52:47 +080032 asyncResp->res.addHeader(
33 boost::beast::http::field::link,
34 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
Chicago Duan77b36432021-02-05 15:48:26 +080035 asyncResp->res.jsonValue["@odata.type"] =
36 "#PowerSubsystem.v1_1_0.PowerSubsystem";
37 asyncResp->res.jsonValue["Name"] = "Power Subsystem";
38 asyncResp->res.jsonValue["Id"] = "PowerSubsystem";
Ed Tanousef4c65b2023-04-24 15:28:50 -070039 asyncResp->res.jsonValue["@odata.id"] =
40 boost::urls::format("/redfish/v1/Chassis/{}/PowerSubsystem", chassisId);
Ed Tanous539d8c62024-06-19 14:38:27 -070041 asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled;
42 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
George Liua7210022022-10-05 15:44:11 +080043 asyncResp->res.jsonValue["PowerSupplies"]["@odata.id"] =
Ed Tanousef4c65b2023-04-24 15:28:50 -070044 boost::urls::format(
45 "/redfish/v1/Chassis/{}/PowerSubsystem/PowerSupplies", chassisId);
George Liu2ea468a2022-10-26 13:52:47 +080046}
Chicago Duan77b36432021-02-05 15:48:26 +080047
George Liu2ea468a2022-10-26 13:52:47 +080048inline void handlePowerSubsystemCollectionHead(
49 App& app, const crow::Request& req,
50 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
51 const std::string& chassisId)
52{
53 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
54 {
55 return;
56 }
57
58 auto respHandler = [asyncResp, chassisId](
59 const std::optional<std::string>& validChassisPath) {
60 if (!validChassisPath)
61 {
62 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
63 return;
64 }
65 asyncResp->res.addHeader(
66 boost::beast::http::field::link,
67 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
68 };
69 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
70 std::move(respHandler));
Chicago Duan77b36432021-02-05 15:48:26 +080071}
72
73inline void handlePowerSubsystemCollectionGet(
74 App& app, const crow::Request& req,
75 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
76 const std::string& chassisId)
77{
78 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
79 {
80 return;
81 }
82
83 redfish::chassis_utils::getValidChassisPath(
84 asyncResp, chassisId,
85 std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId));
86}
87
88inline void requestRoutesPowerSubsystem(App& app)
89{
90 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
George Liu2ea468a2022-10-26 13:52:47 +080091 .privileges(redfish::privileges::headPowerSubsystem)
92 .methods(boost::beast::http::verb::head)(
93 std::bind_front(handlePowerSubsystemCollectionHead, std::ref(app)));
94
95 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
Chicago Duan77b36432021-02-05 15:48:26 +080096 .privileges(redfish::privileges::getPowerSubsystem)
97 .methods(boost::beast::http::verb::get)(
98 std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app)));
99}
100
101} // namespace redfish