blob: c3b898c27843690bed71754adaa81dfc5687ea6f [file] [log] [blame]
Chicago Duan77b36432021-02-05 15:48:26 +08001#pragma once
2
3#include "app.hpp"
4#include "query.hpp"
5#include "registries/privilege_registry.hpp"
6#include "utils/chassis_utils.hpp"
7
8#include <memory>
9#include <optional>
10#include <string>
11
12namespace redfish
13{
14
15inline void doPowerSubsystemCollection(
16 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
17 const std::string& chassisId,
18 const std::optional<std::string>& validChassisPath)
19{
20 if (!validChassisPath)
21 {
22 BMCWEB_LOG_ERROR << "Not a valid chassis ID" << chassisId;
23 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
24 return;
25 }
26
27 asyncResp->res.jsonValue["@odata.type"] =
28 "#PowerSubsystem.v1_1_0.PowerSubsystem";
29 asyncResp->res.jsonValue["Name"] = "Power Subsystem";
30 asyncResp->res.jsonValue["Id"] = "PowerSubsystem";
31 asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
32 "redfish", "v1", "Chassis", chassisId, "PowerSubsystem");
33 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
34 asyncResp->res.jsonValue["Status"]["Health"] = "OK";
35
36 asyncResp->res.addHeader(
37 boost::beast::http::field::link,
38 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby");
39}
40
41inline void handlePowerSubsystemCollectionGet(
42 App& app, const crow::Request& req,
43 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
44 const std::string& chassisId)
45{
46 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
47 {
48 return;
49 }
50
51 redfish::chassis_utils::getValidChassisPath(
52 asyncResp, chassisId,
53 std::bind_front(doPowerSubsystemCollection, asyncResp, chassisId));
54}
55
56inline void requestRoutesPowerSubsystem(App& app)
57{
58 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/")
59 .privileges(redfish::privileges::getPowerSubsystem)
60 .methods(boost::beast::http::verb::get)(
61 std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app)));
62}
63
64} // namespace redfish