summaryrefslogtreecommitdiff
path: root/redfish-core/lib/ethernet.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/ethernet.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/ethernet.hpp')
-rw-r--r--redfish-core/lib/ethernet.hpp129
1 files changed, 66 insertions, 63 deletions
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index f7cffcc645..2647672c89 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -696,7 +696,7 @@ inline bool ipv4VerifyIpAndGetBitcount(const std::string& ip,
* @return None
*/
inline void deleteIPv4(const std::string& ifaceId, const std::string& ipHash,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec) {
@@ -723,7 +723,7 @@ inline void deleteIPv4(const std::string& ifaceId, const std::string& ipHash,
*/
inline void createIPv4(const std::string& ifaceId, uint8_t prefixLength,
const std::string& gateway, const std::string& address,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec) {
@@ -752,11 +752,11 @@ inline void createIPv4(const std::string& ifaceId, uint8_t prefixLength,
*
* @return None
*/
-inline void deleteAndCreateIPv4(const std::string& ifaceId,
- const std::string& id, uint8_t prefixLength,
- const std::string& gateway,
- const std::string& address,
- const std::shared_ptr<AsyncResp>& asyncResp)
+inline void
+ deleteAndCreateIPv4(const std::string& ifaceId, const std::string& id,
+ uint8_t prefixLength, const std::string& gateway,
+ const std::string& address,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[asyncResp, ifaceId, address, prefixLength,
@@ -793,7 +793,7 @@ inline void deleteAndCreateIPv4(const std::string& ifaceId,
* @return None
*/
inline void deleteIPv6(const std::string& ifaceId, const std::string& ipHash,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec) {
@@ -819,10 +819,10 @@ inline void deleteIPv6(const std::string& ifaceId, const std::string& ipHash,
*
* @return None
*/
-inline void deleteAndCreateIPv6(const std::string& ifaceId,
- const std::string& id, uint8_t prefixLength,
- const std::string& address,
- const std::shared_ptr<AsyncResp>& asyncResp)
+inline void
+ deleteAndCreateIPv6(const std::string& ifaceId, const std::string& id,
+ uint8_t prefixLength, const std::string& address,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[asyncResp, ifaceId, address,
@@ -861,7 +861,7 @@ inline void deleteAndCreateIPv6(const std::string& ifaceId,
*/
inline void createIPv6(const std::string& ifaceId, uint8_t prefixLength,
const std::string& address,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
auto createIpHandler = [asyncResp](const boost::system::error_code ec) {
if (ec)
@@ -1007,17 +1007,18 @@ class EthernetCollection : 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
{
- res.jsonValue["@odata.type"] =
+ asyncResp->res.jsonValue["@odata.type"] =
"#EthernetInterfaceCollection.EthernetInterfaceCollection";
- res.jsonValue["@odata.id"] =
+ asyncResp->res.jsonValue["@odata.id"] =
"/redfish/v1/Managers/bmc/EthernetInterfaces";
- res.jsonValue["Name"] = "Ethernet Network Interface Collection";
- res.jsonValue["Description"] =
+ asyncResp->res.jsonValue["Name"] =
+ "Ethernet Network Interface Collection";
+ asyncResp->res.jsonValue["Description"] =
"Collection of EthernetInterfaces for this Manager";
- std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
+
// Get eth interface list, and call the below callback for JSON
// preparation
getEthernetIfaceList(
@@ -1077,8 +1078,9 @@ class EthernetInterface : public Node
}
private:
- 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)
{
// SHOULD handle host names of up to 255 characters(RFC 1123)
if (hostname.length() > 255)
@@ -1101,9 +1103,9 @@ class EthernetInterface : public Node
std::variant<std::string>(hostname));
}
- void handleDomainnamePatch(const std::string& ifaceId,
- const std::string& domainname,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ void handleDomainnamePatch(
+ const std::string& ifaceId, const std::string& domainname,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
std::vector<std::string> vectorDomainname = {domainname};
crow::connections::systemBus->async_method_call(
@@ -1121,7 +1123,7 @@ class EthernetInterface : public Node
}
void handleFqdnPatch(const std::string& ifaceId, const std::string& fqdn,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
// Total length of FQDN must not exceed 255 characters(RFC 1035)
if (fqdn.length() > 255)
@@ -1179,9 +1181,9 @@ class EthernetInterface : public Node
return std::regex_match(domainname, pattern);
}
- void handleMACAddressPatch(const std::string& ifaceId,
- const std::string& macAddress,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ void handleMACAddressPatch(
+ const std::string& ifaceId, const std::string& macAddress,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[asyncResp, macAddress](const boost::system::error_code ec) {
@@ -1201,7 +1203,7 @@ class EthernetInterface : public Node
void setDHCPEnabled(const std::string& ifaceId,
const std::string& propertyName, const bool v4Value,
const bool v6Value,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
const std::string dhcp = getDhcpEnabledEnumeration(v4Value, v6Value);
crow::connections::systemBus->async_method_call(
@@ -1223,7 +1225,7 @@ class EthernetInterface : public Node
void setEthernetInterfaceBoolProperty(
const std::string& ifaceId, const std::string& propertyName,
- const bool& value, const std::shared_ptr<AsyncResp>& asyncResp)
+ const bool& value, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec) {
@@ -1242,7 +1244,7 @@ class EthernetInterface : public Node
}
void setDHCPv4Config(const std::string& propertyName, const bool& value,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
BMCWEB_LOG_DEBUG << propertyName << " = " << value;
crow::connections::systemBus->async_method_call(
@@ -1265,7 +1267,7 @@ class EthernetInterface : public Node
const EthernetInterfaceData& ethData,
const DHCPParameters& v4dhcpParms,
const DHCPParameters& v6dhcpParms,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
bool ipv4Active = translateDHCPEnabledToBool(ethData.DHCPEnabled, true);
bool ipv6Active =
@@ -1400,7 +1402,7 @@ class EthernetInterface : public Node
void handleIPv4StaticPatch(
const std::string& ifaceId, nlohmann::json& input,
const boost::container::flat_set<IPv4AddressData>& ipv4Data,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
if ((!input.is_array()) || input.empty())
{
@@ -1583,7 +1585,7 @@ class EthernetInterface : public Node
void handleStaticNameServersPatch(
const std::string& ifaceId,
const std::vector<std::string>& updatedStaticNameServers,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec) {
@@ -1604,7 +1606,7 @@ class EthernetInterface : public Node
void handleIPv6StaticAddressesPatch(
const std::string& ifaceId, const nlohmann::json& input,
const boost::container::flat_set<IPv6AddressData>& ipv6Data,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
if (!input.is_array() || input.empty())
{
@@ -1725,8 +1727,8 @@ class EthernetInterface : public Node
}
void parseInterfaceData(
- const std::shared_ptr<AsyncResp>& asyncResp, const std::string& ifaceId,
- const EthernetInterfaceData& ethData,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& ifaceId, const EthernetInterfaceData& ethData,
const boost::container::flat_set<IPv4AddressData>& ipv4Data,
const boost::container::flat_set<IPv6AddressData>& ipv6Data)
{
@@ -1868,10 +1870,10 @@ class EthernetInterface : 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);
@@ -1904,10 +1906,11 @@ class EthernetInterface : 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);
@@ -1930,7 +1933,7 @@ class EthernetInterface : public Node
DHCPParameters v6dhcpParms;
if (!json_util::readJson(
- req, res, "HostName", hostname, "FQDN", fqdn,
+ req, asyncResp->res, "HostName", hostname, "FQDN", fqdn,
"IPv4StaticAddresses", ipv4StaticAddresses, "MACAddress",
macAddress, "StaticNameServers", staticNameServers,
"IPv6DefaultGateway", ipv6DefaultGateway, "IPv6StaticAddresses",
@@ -1941,7 +1944,7 @@ class EthernetInterface : public Node
}
if (dhcpv4)
{
- if (!json_util::readJson(*dhcpv4, res, "DHCPEnabled",
+ if (!json_util::readJson(*dhcpv4, asyncResp->res, "DHCPEnabled",
v4dhcpParms.dhcpv4Enabled, "UseDNSServers",
v4dhcpParms.useDNSServers, "UseNTPServers",
v4dhcpParms.useNTPServers, "UseDomainName",
@@ -1953,7 +1956,7 @@ class EthernetInterface : public Node
if (dhcpv6)
{
- if (!json_util::readJson(*dhcpv6, res, "OperatingMode",
+ if (!json_util::readJson(*dhcpv6, asyncResp->res, "OperatingMode",
v6dhcpParms.dhcpv6OperatingMode,
"UseDNSServers", v6dhcpParms.useDNSServers,
"UseNTPServers", v6dhcpParms.useNTPServers,
@@ -2108,26 +2111,25 @@ class VlanNetworkInterface : 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);
// TODO(Pawel) this shall be parameterized call (two params) to get
// EthernetInterfaces for any Manager, not only hardcoded 'openbmc'.
// Check if there is required param, truly entering this shall be
// impossible.
if (params.size() != 2)
{
- messages::internalError(res);
- res.end();
+ messages::internalError(asyncResp->res);
return;
}
const std::string& parentIfaceId = params[0];
const std::string& ifaceId = params[1];
- res.jsonValue["@odata.type"] =
+ asyncResp->res.jsonValue["@odata.type"] =
"#VLanNetworkInterface.v1_1_0.VLanNetworkInterface";
- res.jsonValue["Name"] = "VLAN Network Interface";
+ asyncResp->res.jsonValue["Name"] = "VLAN Network Interface";
if (!verifyNames(parentIfaceId, ifaceId))
{
@@ -2159,10 +2161,11 @@ class VlanNetworkInterface : 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() != 2)
{
messages::internalError(asyncResp->res);
@@ -2182,8 +2185,8 @@ class VlanNetworkInterface : public Node
bool vlanEnable = false;
uint32_t vlanId = 0;
- if (!json_util::readJson(req, res, "VLANEnable", vlanEnable, "VLANId",
- vlanId))
+ if (!json_util::readJson(req, asyncResp->res, "VLANEnable", vlanEnable,
+ "VLANId", vlanId))
{
return;
}
@@ -2238,10 +2241,10 @@ class VlanNetworkInterface : public Node
});
}
- void doDelete(crow::Response& res, const crow::Request&,
+ void doDelete(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() != 2)
{
messages::internalError(asyncResp->res);
@@ -2317,10 +2320,10 @@ class VlanNetworkInterfaceCollection : 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)
{
// This means there is a problem with the router
@@ -2380,10 +2383,10 @@ class VlanNetworkInterfaceCollection : public Node
});
}
- 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>& params) override
{
- std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
if (params.size() != 1)
{
messages::internalError(asyncResp->res);
@@ -2391,8 +2394,8 @@ class VlanNetworkInterfaceCollection : public Node
}
bool vlanEnable = false;
uint32_t vlanId = 0;
- if (!json_util::readJson(req, res, "VLANId", vlanId, "VLANEnable",
- vlanEnable))
+ if (!json_util::readJson(req, asyncResp->res, "VLANId", vlanId,
+ "VLANEnable", vlanEnable))
{
return;
}