summaryrefslogtreecommitdiff
path: root/redfish-core/lib/hypervisor_system.hpp
diff options
context:
space:
mode:
authorAndrew Geissler <geissonator@yahoo.com>2021-02-09 00:13:03 +0300
committerAndrew Geissler <geissonator@yahoo.com>2021-02-25 01:11:32 +0300
commit4fbaf64a931675f57382eef9cf1c6cd88c75ad1e (patch)
tree8374354e4772cbcf2f3bd3246e5de669980592ec /redfish-core/lib/hypervisor_system.hpp
parentcc0bb6f29171b8afb09bd663767ba36793110d5d (diff)
downloadbmcweb-4fbaf64a931675f57382eef9cf1c6cd88c75ad1e.tar.xz
hypervisor: add support to turn on
If the customer has requested the hypervisor stop at its Standby state vs. booting all the way to Running, then a mechanism is needed to request the hypervisor boot to Running. A common use case for IBM is the system user has requested the hypervisor stop at Standby so some manual debug can be performed and then they want to move the hypervisor into the Running state so they can boot their operating system. Asking the hypervisor to stop at Standby is done via the BootSourceOverrideEnabled and BootSourceOverrideTarget properties under the redfish/v1/Systems/system. Utilize the ComputerSystem.Reset action for this. Similar to how redfish/v1/Systems/system/Actions/ComputerSystem.Reset is utilized for the overall system, implement a limited subset of it for the hypervisor object. Tested: - Verified when phosphor-hypervisor-state-manager package is not installed that Redfish API returns same info it does currently - Verified when phosphor-hypervisor-state-manager was installed that the hypervisor state was returned correctly, the Actions field was filled in, and a post to the Action with ResetType set to "On" was correctly propagated to RequestedHostTransition - Verified that an invalid ResetType (i.e. "Off") returned the appropriate "invalid parameter" error message to the Redfish API - Verified no new errors logged by Redfish validator on system with this hypervisor package installed - Verify resource not found when hypervisor not enabled curl -k -H "X-Auth-Token: $TOKEN" -X POST https://${BMC_IP}/redfish/v1/Systems/hypervisor/Actions/ComputerSystem.Reset -d '{"ResetType": "On"}' { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The requested resource of type Actions named Reset was not found.", "MessageArgs": [ "Actions", "Reset" ], "MessageId": "Base.1.8.1.ResourceNotFound", "MessageSeverity": "Critical", "Resolution": "Provide a valid resource identifier and resubmit the request." } ], "code": "Base.1.8.1.ResourceNotFound", "message": "The requested resource of type Actions named Reset was not found." } } - Verify ResourceNotFound returned when hypervisor not enabled curl -k -H "X-Auth-Token: $TOKEN" -X GET https://${BMC_IP}/redfish/v1/Systems/hypervisor/ResetActionInfo { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The requested resource of type hypervisor named ResetActionInfo was not found.", "MessageArgs": [ "hypervisor", "ResetActionInfo" ], "MessageId": "Base.1.8.1.ResourceNotFound", "MessageSeverity": "Critical", "Resolution": "Provide a valid resource identifier and resubmit the request." } ], "code": "Base.1.8.1.ResourceNotFound", "message": "The requested resource of type hypervisor named ResetActionInfo was not found." } } - Verify input parameters validated curl -k -H "X-Auth-Token: $TOKEN" -X POST https://${BMC_IP}/redfish/v1/Systems/hypervisor/Actions/ComputerSystem.Reset -d '{"ResetTypeInvalid": "On"}' { "ResetTypeInvalid@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The property ResetTypeInvalid is not in the list of valid properties for the resource.", "MessageArgs": [ "ResetTypeInvalid" ], "MessageId": "Base.1.8.1.PropertyUnknown", "MessageSeverity": "Warning", "Resolution": "Remove the unknown property from the request body and resubmit the request if the operation failed." } ] } curl -k -H "X-Auth-Token: $TOKEN" -X POST https://${BMC_IP}/redfish/v1/Systems/hypervisor/Actions/ComputerSystem.Reset -d '{"ResetType": "OnInvalid"}' { "ResetType@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The value OnInvalid for the property ResetType is not in the list of acceptable values.", "MessageArgs": [ "OnInvalid", "ResetType" ], "MessageId": "Base.1.8.1.PropertyValueNotInList", "MessageSeverity": "Warning", "Resolution": "Choose a value from the enumeration list that the implementation can support and resubmit the request if the operation failed." } ] } Change-Id: Ia7b4e78b7b0d907cc06eb3f20d51ff87b7dde564 Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Diffstat (limited to 'redfish-core/lib/hypervisor_system.hpp')
-rw-r--r--redfish-core/lib/hypervisor_system.hpp219
1 files changed, 219 insertions, 0 deletions
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index 4ec88fd51f..3367a14612 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -94,6 +94,61 @@ inline void getHypervisorState(const std::shared_ptr<AsyncResp>& aResp)
}
/**
+ * @brief Populate Actions if any are valid for hypervisor object
+ *
+ * The hypervisor state object is optional so this function will only set the
+ * Action if the object is found
+ *
+ * @param[in] aResp Shared pointer for completing asynchronous calls.
+ *
+ * @return None.
+ */
+inline void getHypervisorActions(const std::shared_ptr<AsyncResp>& aResp)
+{
+ BMCWEB_LOG_DEBUG << "Get hypervisor actions.";
+ crow::connections::systemBus->async_method_call(
+ [aResp](
+ const boost::system::error_code ec,
+ const std::vector<std::pair<std::string, std::vector<std::string>>>&
+ objInfo) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
+ // This is an optional D-Bus object so just return if
+ // error occurs
+ return;
+ }
+
+ if (objInfo.size() == 0)
+ {
+ // As noted above, this is an optional interface so just return
+ // if there is no instance found
+ return;
+ }
+
+ if (objInfo.size() > 1)
+ {
+ // More then one hypervisor object is not supported and is an
+ // error
+ messages::internalError(aResp->res);
+ return;
+ }
+
+ // Object present so system support limited ComputerSystem Action
+ aResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"] = {
+ {"target",
+ "/redfish/v1/Systems/hypervisor/Actions/ComputerSystem.Reset"},
+ {"@Redfish.ActionInfo",
+ "/redfish/v1/Systems/hypervisor/ResetActionInfo"}};
+ },
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetObject",
+ "/xyz/openbmc_project/state/hypervisor0",
+ std::array<const char*, 1>{"xyz.openbmc_project.State.Host"});
+}
+
+/**
* Hypervisor Systems derived class for delivering Computer Systems Schema.
*/
class HypervisorSystem : public Node
@@ -142,6 +197,7 @@ class HypervisorSystem : public Node
{"@odata.id", "/redfish/v1/Systems/hypervisor/"
"EthernetInterfaces"}};
getHypervisorState(asyncResp);
+ getHypervisorActions(asyncResp);
// TODO: Add "SystemType" : "hypervisor"
},
"xyz.openbmc_project.Settings",
@@ -954,4 +1010,167 @@ class HypervisorInterface : public Node
res.result(boost::beast::http::status::accepted);
}
};
+
+/**
+ * HypervisorResetActionInfo derived class for delivering Computer Systems
+ * ResetType AllowableValues using ResetInfo schema.
+ */
+class HypervisorResetActionInfo : public Node
+{
+ public:
+ /*
+ * Default Constructor
+ */
+ HypervisorResetActionInfo(App& app) :
+ Node(app, "/redfish/v1/Systems/hypervisor/ResetActionInfo/")
+ {
+ entityPrivileges = {
+ {boost::beast::http::verb::get, {{"Login"}}},
+ {boost::beast::http::verb::head, {{"Login"}}},
+ {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
+ {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
+ {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
+ {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
+ }
+
+ private:
+ /**
+ * Functions triggers appropriate requests on DBus
+ */
+ void doGet(crow::Response& res, const crow::Request&,
+ const std::vector<std::string>&) override
+ {
+ std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
+
+ // Only return action info if hypervisor D-Bus object present
+ crow::connections::systemBus->async_method_call(
+ [asyncResp](const boost::system::error_code ec,
+ const std::vector<std::pair<
+ std::string, std::vector<std::string>>>& objInfo) {
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
+
+ // No hypervisor objects found by mapper
+ if (ec.value() == boost::system::errc::io_error)
+ {
+ messages::resourceNotFound(asyncResp->res, "hypervisor",
+ "ResetActionInfo");
+ return;
+ }
+
+ messages::internalError(asyncResp->res);
+ return;
+ }
+
+ // One and only one hypervisor instance supported
+ if (objInfo.size() != 1)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+
+ // The hypervisor object only support the ability to turn On
+ // The system object Action should be utilized for other
+ // operations
+ asyncResp->res.jsonValue = {
+ {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"},
+ {"@odata.id",
+ "/redfish/v1/Systems/hypervisor/ResetActionInfo"},
+ {"Name", "Reset Action Info"},
+ {"Id", "ResetActionInfo"},
+ {"Parameters",
+ {{{"Name", "ResetType"},
+ {"Required", true},
+ {"DataType", "String"},
+ {"AllowableValues", {"On"}}}}}};
+ },
+ "xyz.openbmc_project.ObjectMapper",
+ "/xyz/openbmc_project/object_mapper",
+ "xyz.openbmc_project.ObjectMapper", "GetObject",
+ "/xyz/openbmc_project/state/hypervisor0",
+ std::array<const char*, 1>{"xyz.openbmc_project.State.Host"});
+ }
+};
+
+/**
+ * HypervisorActionsReset class supports the POST method for Reset action.
+ * The class sends data directly to D-Bus.
+ */
+class HypervisorActionsReset : public Node
+{
+ public:
+ HypervisorActionsReset(App& app) :
+ Node(app,
+ "/redfish/v1/Systems/hypervisor/Actions/ComputerSystem.Reset/")
+ {
+ entityPrivileges = {
+ {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
+ }
+
+ private:
+ /**
+ * Function handles POST method request.
+ * Analyzes POST body message before sends Reset request data to D-Bus.
+ */
+ void doPost(crow::Response& res, const crow::Request& req,
+ const std::vector<std::string>&) override
+ {
+ std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
+
+ std::optional<std::string> resetType;
+ if (!json_util::readJson(req, res, "ResetType", resetType))
+ {
+ // readJson adds appropriate error to response
+ return;
+ }
+
+ if (!resetType)
+ {
+ messages::actionParameterMissing(
+ asyncResp->res, "ComputerSystem.Reset", "ResetType");
+ return;
+ }
+
+ // Hypervisor object only support On operation
+ if (resetType != "On")
+ {
+ messages::propertyValueNotInList(asyncResp->res, *resetType,
+ "ResetType");
+ return;
+ }
+
+ std::string command = "xyz.openbmc_project.State.Host.Transition.On";
+
+ crow::connections::systemBus->async_method_call(
+ [asyncResp, resetType](const boost::system::error_code ec) {
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
+ if (ec.value() == boost::asio::error::invalid_argument)
+ {
+ messages::actionParameterNotSupported(
+ asyncResp->res, *resetType, "Reset");
+ return;
+ }
+
+ if (ec.value() == boost::asio::error::host_unreachable)
+ {
+ messages::resourceNotFound(asyncResp->res, "Actions",
+ "Reset");
+ return;
+ }
+
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ messages::success(asyncResp->res);
+ },
+ "xyz.openbmc_project.State.Hypervisor",
+ "/xyz/openbmc_project/state/hypervisor0",
+ "org.freedesktop.DBus.Properties", "Set",
+ "xyz.openbmc_project.State.Host", "RequestedHostTransition",
+ std::variant<std::string>{std::move(command)});
+ }
+};
} // namespace redfish