summaryrefslogtreecommitdiff
path: root/redfish-core/lib/systems.hpp
diff options
context:
space:
mode:
authorGeorge Liu <liuxiwei@inspur.com>2020-04-10 12:18:11 +0300
committerGeorge Liu <liuxiwei@inspur.com>2020-04-24 12:28:00 +0300
commitc6a620f2e01ce5f1551ecc4455624654282d79c7 (patch)
treed4d5e2a65a64874806ffae6c6b390243265684cf /redfish-core/lib/systems.hpp
parent3946028d2d3143109bb562841efce3e094c70c0b (diff)
downloadbmcweb-c6a620f2e01ce5f1551ecc4455624654282d79c7.tar.xz
Map policy restore D-Bus interface to Redfish
Tested: curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Systems/system { "@odata.id": "/redfish/v1/Systems/system", "@odata.type": "#ComputerSystem.v1_6_0.ComputerSystem", ... ... "PowerRestorePolicy": "AlwaysOff", ... ... } curl -k -H "X-Auth-Token: $token" -X PATCH -d '{"PowerRestorePolicy":"AlwaysOn"}' https://${bmc}/redfish/v1/Systems/system curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Systems/system { "@odata.id": "/redfish/v1/Systems/system", "@odata.type": "#ComputerSystem.v1_6_0.ComputerSystem", ... ... "PowerRestorePolicy": "AlwaysOn", ... ... } curl -k -H "X-Auth-Token: $token" -X PATCH -d '{"PowerRestorePolicy":"TestPolicy"}' https://${bmc}/redfish/v1/Systems/system { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_0_0.Message", "Message": "The request failed due to an internal service error. The service is still operational.", "MessageArgs": [], "MessageId": "Base.1.4.0.InternalError", "Resolution": "Resubmit the request. If the problem persists, consider resetting the service.", "Severity": "Critical" } ], "code": "Base.1.4.0.InternalError", "message": "The request failed due to an internal service error. The service is still operational." } } Passed the validator: VERBO - ServiceRoot -> Systems.Systems -> Members.ComputerSystem#0, ComputerSystem.v1_10_0, ComputerSystem VERBO - @odata.id PASS VERBO - @odata.type PASS VERBO - Actions complex VERBO - Bios PASS VERBO - Boot complex VERBO - Description PASS VERBO - Id PASS VERBO - Links complex VERBO - LogServices PASS VERBO - Memory PASS VERBO - MemorySummary complex VERBO - Name PASS VERBO - PowerRestorePolicy PASS ... ... Signed-off-by: George Liu <liuxiwei@inspur.com> Change-Id: I75155c5cb930d6c4d9d5aad39f3315506db28e38
Diffstat (limited to 'redfish-core/lib/systems.hpp')
-rw-r--r--redfish-core/lib/systems.hpp113
1 files changed, 112 insertions, 1 deletions
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 0aa0d6459d..a6928ca714 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -915,6 +915,62 @@ static void getBootProperties(std::shared_ptr<AsyncResp> aResp)
}
/**
+ * @brief Retrieves power restore policy over DBUS.
+ *
+ * @param[in] aResp Shared pointer for generating response message.
+ *
+ * @return None.
+ */
+void getPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp)
+{
+ BMCWEB_LOG_DEBUG << "Get power restore policy";
+
+ crow::connections::systemBus->async_method_call(
+ [aResp](const boost::system::error_code ec,
+ sdbusplus::message::variant<std::string> &policy) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
+ return;
+ }
+
+ const boost::container::flat_map<std::string, std::string>
+ policyMaps = {
+ {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
+ "AlwaysOn",
+ "AlwaysOn"},
+ {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
+ "AlwaysOff",
+ "AlwaysOff"},
+ {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
+ "LastState",
+ "LastState"}};
+
+ const std::string *policyPtr = std::get_if<std::string>(&policy);
+
+ if (!policyPtr)
+ {
+ messages::internalError(aResp->res);
+ return;
+ }
+
+ auto policyMapsIt = policyMaps.find(*policyPtr);
+ if (policyMapsIt == policyMaps.end())
+ {
+ messages::internalError(aResp->res);
+ return;
+ }
+
+ aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second;
+ },
+ "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/control/host0/power_restore_policy",
+ "org.freedesktop.DBus.Properties", "Get",
+ "xyz.openbmc_project.Control.Power.RestorePolicy",
+ "PowerRestorePolicy");
+}
+
+/**
* @brief Sets boot properties into DBUS object(s).
*
* @param[in] aResp Shared pointer for generating response message.
@@ -1082,6 +1138,53 @@ static void setBootProperties(std::shared_ptr<AsyncResp> aResp,
"xyz.openbmc_project.Object.Enable", "Enabled");
}
+/**
+ * @brief Sets power restore policy properties.
+ *
+ * @param[in] aResp Shared pointer for generating response message.
+ * @param[in] policy power restore policy properties from request.
+ *
+ * @return None.
+ */
+static void setPowerRestorePolicy(std::shared_ptr<AsyncResp> aResp,
+ std::optional<std::string> policy)
+{
+ BMCWEB_LOG_DEBUG << "Set power restore policy.";
+
+ const boost::container::flat_map<std::string, std::string> policyMaps = {
+ {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
+ "AlwaysOn"},
+ {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
+ "AlwaysOff"},
+ {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy."
+ "LastState"}};
+
+ std::string powerRestorPolicy;
+
+ auto policyMapsIt = policyMaps.find(*policy);
+ if (policyMapsIt == policyMaps.end())
+ {
+ messages::internalError(aResp->res);
+ return;
+ }
+
+ powerRestorPolicy = policyMapsIt->second;
+
+ crow::connections::systemBus->async_method_call(
+ [aResp](const boost::system::error_code ec) {
+ if (ec)
+ {
+ messages::internalError(aResp->res);
+ return;
+ }
+ },
+ "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/control/host0/power_restore_policy",
+ "org.freedesktop.DBus.Properties", "Set",
+ "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy",
+ std::variant<std::string>(powerRestorPolicy));
+}
+
#ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE
/**
* @brief Retrieves provisioning status
@@ -1667,6 +1770,7 @@ class Systems : public Node
getBootProperties(asyncResp);
getPCIeDeviceList(asyncResp, "PCIeDevices");
getHostWatchdogTimer(asyncResp);
+ getPowerRestorePolicy(asyncResp);
#ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE
getProvisioningStatus(asyncResp);
#endif
@@ -1678,10 +1782,12 @@ class Systems : public Node
std::optional<std::string> indicatorLed;
std::optional<nlohmann::json> bootProps;
std::optional<nlohmann::json> wdtTimerProps;
+ std::optional<std::string> powerRestorePolicy;
auto asyncResp = std::make_shared<AsyncResp>(res);
if (!json_util::readJson(req, res, "IndicatorLED", indicatorLed, "Boot",
- bootProps, "WatchdogTimer", wdtTimerProps))
+ bootProps, "WatchdogTimer", wdtTimerProps,
+ "PowerRestorePolicy", powerRestorePolicy))
{
return;
}
@@ -1722,6 +1828,11 @@ class Systems : public Node
{
setIndicatorLedState(asyncResp, std::move(*indicatorLed));
}
+
+ if (powerRestorePolicy)
+ {
+ setPowerRestorePolicy(asyncResp, std::move(*powerRestorePolicy));
+ }
}
};
} // namespace redfish