summaryrefslogtreecommitdiff
path: root/redfish-core/lib/hypervisor_system.hpp
diff options
context:
space:
mode:
authorzhanghch05 <zhanghch05@inspur.com>2021-04-01 06:18:24 +0300
committerzhanghch05 <zhanghch05@inspur.com>2021-04-08 04:01:21 +0300
commit8d1b46d7f8d39db2ba048f9e9007106ca3a28c9b (patch)
tree821fcb9b383fdf3db22db77e154cd7f57606d402 /redfish-core/lib/hypervisor_system.hpp
parentdab0604af234bdd5010407031a01343d6c242edf (diff)
downloadbmcweb-8d1b46d7f8d39db2ba048f9e9007106ca3a28c9b.tar.xz
Using AsyncResp everywhere
Get the core using AsyncResp everywhere, and not have each individual handler creating its own object.We can call app.handle() without fear of the response getting ended after the first tree is done populating. Don't use res.end() anymore. Tested: 1. Validator passed. Signed-off-by: zhanghaicheng <zhanghch05@inspur.com> Change-Id: I867367ce4a0caf8c4b3f4e07e06c11feed0782e8
Diffstat (limited to 'redfish-core/lib/hypervisor_system.hpp')
-rw-r--r--redfish-core/lib/hypervisor_system.hpp89
1 files changed, 45 insertions, 44 deletions
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index e320e360df..4a3a205edc 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -24,7 +24,7 @@ namespace redfish
*
* @return None.
*/
-inline void getHypervisorState(const std::shared_ptr<AsyncResp>& aResp)
+inline void getHypervisorState(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
BMCWEB_LOG_DEBUG << "Get hypervisor state information.";
crow::connections::systemBus->async_method_call(
@@ -103,7 +103,8 @@ inline void getHypervisorState(const std::shared_ptr<AsyncResp>& aResp)
*
* @return None.
*/
-inline void getHypervisorActions(const std::shared_ptr<AsyncResp>& aResp)
+inline void
+ getHypervisorActions(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
BMCWEB_LOG_DEBUG << "Get hypervisor actions.";
crow::connections::systemBus->async_method_call(
@@ -169,10 +170,9 @@ class HypervisorSystem : public Node
/**
* Functions triggers appropriate requests on DBus
*/
- void doGet(crow::Response& res, const crow::Request&,
- const std::vector<std::string>&) override
+ void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const crow::Request&, const std::vector<std::string>&) override
{
- std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec,
const std::variant<std::string>& /*hostName*/) {
@@ -227,10 +227,9 @@ class HypervisorInterfaceCollection : public Node
/**
* Functions triggers appropriate requests on DBus
*/
- void doGet(crow::Response& res, const crow::Request&,
- const std::vector<std::string>&) override
+ void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const crow::Request&, const std::vector<std::string>&) override
{
- std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
const std::array<const char*, 1> interfaces = {
"xyz.openbmc_project.Network.EthernetInterface"};
@@ -474,9 +473,10 @@ void getHypervisorIfaceData(const std::string& ethIfaceId,
*
* @return None.
*/
-inline void setHypervisorIPv4Address(const std::shared_ptr<AsyncResp>& aResp,
- const std::string& ethIfaceId,
- const std::string& ipv4Address)
+inline void
+ setHypervisorIPv4Address(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ const std::string& ethIfaceId,
+ const std::string& ipv4Address)
{
BMCWEB_LOG_DEBUG << "Setting the Hypervisor IPaddress : " << ipv4Address
<< " on Iface: " << ethIfaceId;
@@ -505,9 +505,9 @@ inline void setHypervisorIPv4Address(const std::shared_ptr<AsyncResp>& aResp,
*
* @return None.
*/
-inline void setHypervisorIPv4Subnet(const std::shared_ptr<AsyncResp>& aResp,
- const std::string& ethIfaceId,
- const uint8_t subnet)
+inline void
+ setHypervisorIPv4Subnet(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ const std::string& ethIfaceId, const uint8_t subnet)
{
BMCWEB_LOG_DEBUG << "Setting the Hypervisor subnet : " << subnet
<< " on Iface: " << ethIfaceId;
@@ -537,8 +537,9 @@ inline void setHypervisorIPv4Subnet(const std::shared_ptr<AsyncResp>& aResp,
*
* @return None.
*/
-inline void setHypervisorIPv4Gateway(const std::shared_ptr<AsyncResp>& aResp,
- const std::string& gateway)
+inline void
+ setHypervisorIPv4Gateway(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ const std::string& gateway)
{
BMCWEB_LOG_DEBUG
<< "Setting the DefaultGateway to the last configured gateway";
@@ -570,11 +571,10 @@ inline void setHypervisorIPv4Gateway(const std::shared_ptr<AsyncResp>& aResp,
*
* @return None
*/
-inline void createHypervisorIPv4(const std::string& ifaceId,
- uint8_t prefixLength,
- const std::string& gateway,
- const std::string& address,
- const std::shared_ptr<AsyncResp>& asyncResp)
+inline void
+ createHypervisorIPv4(const std::string& ifaceId, uint8_t prefixLength,
+ const std::string& gateway, const std::string& address,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
setHypervisorIPv4Address(asyncResp, ifaceId, address);
setHypervisorIPv4Gateway(asyncResp, gateway);
@@ -589,8 +589,9 @@ inline void createHypervisorIPv4(const std::string& ifaceId,
*
* @return None
*/
-inline void deleteHypervisorIPv4(const std::string& ifaceId,
- const std::shared_ptr<AsyncResp>& asyncResp)
+inline void
+ deleteHypervisorIPv4(const std::string& ifaceId,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
std::string address = "0.0.0.0";
std::string gateway = "0.0.0.0";
@@ -662,7 +663,7 @@ class HypervisorInterface : public Node
void handleHypervisorIPv4StaticPatch(
const std::string& ifaceId, const nlohmann::json& input,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
if ((!input.is_array()) || input.empty())
{
@@ -784,8 +785,9 @@ class HypervisorInterface : public Node
return std::regex_match(hostName, pattern);
}
- void handleHostnamePatch(const std::string& hostName,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ void
+ handleHostnamePatch(const std::string& hostName,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
if (!isHostnameValid(hostName))
{
@@ -809,9 +811,9 @@ class HypervisorInterface : public Node
std::variant<std::string>(hostName));
}
- void setIPv4InterfaceEnabled(const std::string& ifaceId,
- const bool& isActive,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ void setIPv4InterfaceEnabled(
+ const std::string& ifaceId, const bool& isActive,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec) {
@@ -831,7 +833,7 @@ class HypervisorInterface : public Node
}
void setDHCPEnabled(const std::string& ifaceId, const bool& ipv4DHCPEnabled,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
const std::string dhcp =
getDhcpEnabledEnumeration(ipv4DHCPEnabled, false);
@@ -885,10 +887,10 @@ class HypervisorInterface : public Node
/**
* Functions triggers appropriate requests on DBus
*/
- void doGet(crow::Response& res, const crow::Request&,
+ void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const crow::Request&,
const std::vector<std::string>& params) override
{
- std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
if (params.size() != 1)
{
messages::internalError(asyncResp->res);
@@ -917,10 +919,11 @@ class HypervisorInterface : public Node
});
}
- void doPatch(crow::Response& res, const crow::Request& req,
+ void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const crow::Request& req,
const std::vector<std::string>& params) override
{
- std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
+
if (params.size() != 1)
{
messages::internalError(asyncResp->res);
@@ -934,7 +937,7 @@ class HypervisorInterface : public Node
std::optional<nlohmann::json> dhcpv4;
std::optional<bool> ipv4DHCPEnabled;
- if (!json_util::readJson(req, res, "HostName", hostName,
+ if (!json_util::readJson(req, asyncResp->res, "HostName", hostName,
"IPv4StaticAddresses", ipv4StaticAddresses,
"IPv4Addresses", ipv4Addresses, "DHCPv4",
dhcpv4))
@@ -949,7 +952,7 @@ class HypervisorInterface : public Node
if (dhcpv4)
{
- if (!json_util::readJson(*dhcpv4, res, "DHCPEnabled",
+ if (!json_util::readJson(*dhcpv4, asyncResp->res, "DHCPEnabled",
ipv4DHCPEnabled))
{
return;
@@ -1030,7 +1033,7 @@ class HypervisorInterface : public Node
// updated settings from the user.
setIPv4InterfaceEnabled(ifaceId, false, asyncResp);
});
- res.result(boost::beast::http::status::accepted);
+ asyncResp->res.result(boost::beast::http::status::accepted);
}
};
@@ -1060,11 +1063,9 @@ class HypervisorResetActionInfo : public Node
/**
* Functions triggers appropriate requests on DBus
*/
- void doGet(crow::Response& res, const crow::Request&,
- const std::vector<std::string>&) override
+ void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ 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,
@@ -1136,13 +1137,13 @@ class HypervisorActionsReset : public Node
* 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,
+ void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ 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))
+ if (!json_util::readJson(req, asyncResp->res, "ResetType", resetType))
{
// readJson adds appropriate error to response
return;