blob: 90559efa2b815e92a66bd9bd2a12281b46b6c43d [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 {
23 BMCWEB_LOG_ERROR << "Not a valid chassis ID" << chassisId;
24 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
25 return;
26 }
27
28 asyncResp->res.jsonValue["@odata.type"] =
29 "#PowerSubsystem.v1_1_0.PowerSubsystem";
30 asyncResp->res.jsonValue["Name"] = "Power Subsystem";
31 asyncResp->res.jsonValue["Id"] = "PowerSubsystem";
32 asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
33 "redfish", "v1", "Chassis", chassisId, "PowerSubsystem");
34 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
35 asyncResp->res.jsonValue["Status"]["Health"] = "OK";
36
37 asyncResp->res.addHeader(
38 boost::beast::http::field::link,
39 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
40}
41
42inline void handlePowerSubsystemCollectionGet(
43 App& app, const crow::Request& req,
44 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
45 const std::string& chassisId)
46{
47 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
48 {
49 return;
50 }
51
52 redfish::chassis_utils::getValidChassisPath(
53 asyncResp, chassisId,
54 std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId));
55}
56
57inline void requestRoutesPowerSubsystem(App& app)
58{
59 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
60 .privileges(redfish::privileges::getPowerSubsystem)
61 .methods(boost::beast::http::verb::get)(
62 std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app)));
63}
64
65} // namespace redfish