summaryrefslogtreecommitdiff
path: root/redfish-core/lib/chassis.hpp
diff options
context:
space:
mode:
authorP.K. Lee <p.k.lee@quantatw.com>2020-06-17 14:43:16 +0300
committerP. K. Lee <p.k.lee@quantatw.com>2020-06-23 09:50:44 +0300
commitdd99e04b4d4980e4628bbe998b86180606ed405c (patch)
treefebe74d45f2251e8d573b8cb760acdc4f2a3163a /redfish-core/lib/chassis.hpp
parent9aa46454877beb1c85a17c14d97eb7595ac28861 (diff)
downloadbmcweb-dd99e04b4d4980e4628bbe998b86180606ed405c.tar.xz
Redfish: Add chassis reset
Add chassis reset by using Redfish. Tested: Passed validator. Chassis reset worked. Usage: POST on /redfish/v1/Chassis/chassis/Actions/Chassis.Reset/ { "ResetType": "PowerCycle" } Change-Id: Ia8949e6695e60ee63776ac70e4f8cd85a4b186c3 Signed-off-by: P.K. Lee <p.k.lee@quantatw.com>
Diffstat (limited to 'redfish-core/lib/chassis.hpp')
-rw-r--r--redfish-core/lib/chassis.hpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index 2b098a93fa..d1119cd71e 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -323,6 +323,10 @@ class Chassis : public Node
"/redfish/v1/Chassis/" + chassisId;
asyncResp->res.jsonValue["Name"] = "Chassis Collection";
asyncResp->res.jsonValue["ChassisType"] = "RackMount";
+ asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"] = {
+ {"target", "/redfish/v1/Chassis/" + chassisId +
+ "/Actions/Chassis.Reset"},
+ {"ResetType@Redfish.AllowableValues", {"PowerCycle"}}};
asyncResp->res.jsonValue["PCIeDevices"] = {
{"@odata.id",
"/redfish/v1/Systems/system/PCIeDevices"}};
@@ -517,4 +521,75 @@ class Chassis : public Node
"/xyz/openbmc_project/inventory", 0, interfaces);
}
};
+
+void doChassisPowerCycle(std::shared_ptr<AsyncResp> asyncResp)
+{
+ const char* processName = "xyz.openbmc_project.State.Chassis";
+ const char* objectPath = "/xyz/openbmc_project/state/chassis0";
+ const char* interfaceName = "xyz.openbmc_project.State.Chassis";
+ const char* destProperty = "RequestedPowerTransition";
+ const std::string propertyValue =
+ "xyz.openbmc_project.State.Chassis.Transition.PowerCycle";
+
+ crow::connections::systemBus->async_method_call(
+ [asyncResp](const boost::system::error_code ec) {
+ // Use "Set" method to set the property value.
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec;
+ messages::internalError(asyncResp->res);
+ return;
+ }
+
+ messages::success(asyncResp->res);
+ },
+ processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
+ interfaceName, destProperty, std::variant<std::string>{propertyValue});
+}
+
+/**
+ * ChassisResetAction class supports the POST method for the Reset
+ * action.
+ */
+class ChassisResetAction : public Node
+{
+ public:
+ ChassisResetAction(CrowApp& app) :
+ Node(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/",
+ std::string())
+ {
+ entityPrivileges = {
+ {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
+ }
+
+ private:
+ /**
+ * Function handles POST method request.
+ * Analyzes POST body before sending Reset request data to D-Bus.
+ */
+ void doPost(crow::Response& res, const crow::Request& req,
+ const std::vector<std::string>& params) override
+ {
+ BMCWEB_LOG_DEBUG << "Post Chassis Reset.";
+
+ std::string resetType;
+ auto asyncResp = std::make_shared<AsyncResp>(res);
+
+ if (!json_util::readJson(req, asyncResp->res, "ResetType", resetType))
+ {
+ return;
+ }
+
+ if (resetType != "PowerCycle")
+ {
+ BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
+ << resetType;
+ messages::actionParameterNotSupported(asyncResp->res, resetType,
+ "ResetType");
+
+ return;
+ }
+ doChassisPowerCycle(asyncResp);
+ }
+};
} // namespace redfish