Use the unpacking mechanisms for hostname
The ethernet interface previous hardcoded error handling patterns for
the interfaces shown. This commit moves it to the generic ReadJson
mechanisms for error handling
Change-Id: I710188c808ee62c5797059d7ee8f9876bf872a11
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 9aa4f77..e861fb8 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -581,25 +581,6 @@
}
/**
- * @brief Sets given HostName of the machine through D-Bus
- *
- * @param[in] newHostname New name that HostName will be changed to
- * @param[in] callback Function that will be called after the operation
- *
- * @return None.
- */
-template <typename CallbackFunc>
-void setHostName(const std::string &newHostname, CallbackFunc &&callback)
-{
- crow::connections::systemBus->async_method_call(
- callback, "xyz.openbmc_project.Network",
- "/xyz/openbmc_project/network/config",
- "org.freedesktop.DBus.Properties", "Set",
- "xyz.openbmc_project.Network.SystemConfiguration", "HostName",
- sdbusplus::message::variant<std::string>(newHostname));
-}
-
-/**
* @brief Deletes given IPv4
*
* @param[in] ifaceId Id of interface whose IP should be deleted
@@ -905,30 +886,22 @@
}
private:
- void handleHostnamePatch(const nlohmann::json &input,
+ void handleHostnamePatch(const std::string &hostname,
const std::shared_ptr<AsyncResp> asyncResp)
{
- const std::string *newHostname = input.get_ptr<const std::string *>();
- if (newHostname == nullptr)
- {
- messages::propertyValueTypeError(asyncResp->res, input.dump(),
- "HostName");
- return;
- }
-
- // Change hostname
- setHostName(*newHostname,
- [asyncResp, newHostname{std::string(*newHostname)}](
- const boost::system::error_code ec) {
- if (ec)
- {
- messages::internalError(asyncResp->res);
- }
- else
- {
- asyncResp->res.jsonValue["HostName"] = newHostname;
- }
- });
+ asyncResp->res.jsonValue["HostName"] = hostname;
+ crow::connections::systemBus->async_method_call(
+ [asyncResp](const boost::system::error_code ec) {
+ if (ec)
+ {
+ messages::internalError(asyncResp->res);
+ }
+ },
+ "xyz.openbmc_project.Network",
+ "/xyz/openbmc_project/network/config",
+ "org.freedesktop.DBus.Properties", "Set",
+ "xyz.openbmc_project.Network.SystemConfiguration", "HostName",
+ sdbusplus::message::variant<std::string>(hostname));
}
void handleIPv4Patch(
@@ -1298,7 +1271,7 @@
const std::string &iface_id = params[0];
std::optional<nlohmann::json> vlan;
- std::optional<nlohmann::json> hostname;
+ std::optional<std::string> hostname;
std::optional<nlohmann::json> ipv4Addresses;
std::optional<nlohmann::json> ipv6Addresses;