Redfish(Network): Support the PATCH opertration of MACAddress property
TestedBy:
PATCH '{"MACAddress": "x2:xx:xx:xx:xx:xx"}'
Change-Id: I6dc421ea509506a2f3062fc0531778ffa2b00310
Signed-off-by: Ratan Gupta <ratagupt@linux.vnet.ibm.com>
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 2a0b618..1d3cb85 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -964,6 +964,26 @@
std::variant<std::string>(hostname));
}
+ void handleMACAddressPatch(const std::string &ifaceId,
+ const std::string &macAddress,
+ const std::shared_ptr<AsyncResp> &asyncResp)
+ {
+ crow::connections::systemBus->async_method_call(
+ [asyncResp, macAddress](const boost::system::error_code ec) {
+ if (ec)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ asyncResp->res.jsonValue["MACAddress"] = std::move(macAddress);
+ },
+ "xyz.openbmc_project.Network",
+ "/xyz/openbmc_project/network/" + ifaceId,
+ "org.freedesktop.DBus.Properties", "Set",
+ "xyz.openbmc_project.Network.MACAddress", "MACAddress",
+ std::variant<std::string>(macAddress));
+ }
+
void handleIPv4Patch(
const std::string &ifaceId, nlohmann::json &input,
const boost::container::flat_set<IPv4AddressData> &ipv4Data,
@@ -1302,12 +1322,14 @@
std::optional<nlohmann::json> vlan;
std::optional<std::string> hostname;
+ std::optional<std::string> macAddress;
std::optional<nlohmann::json> ipv4Addresses;
std::optional<nlohmann::json> ipv6Addresses;
if (!json_util::readJson(req, res, "VLAN", vlan, "HostName", hostname,
"IPv4Addresses", ipv4Addresses,
- "IPv6Addresses", ipv6Addresses))
+ "IPv6Addresses", ipv6Addresses, "MACAddress",
+ macAddress))
{
return;
}
@@ -1343,7 +1365,7 @@
getEthernetIfaceData(
iface_id,
[this, asyncResp, iface_id, vlanId, vlanEnable,
- hostname = std::move(hostname),
+ hostname = std::move(hostname), macAddress = std::move(macAddress),
ipv4Addresses = std::move(ipv4Addresses),
ipv6Addresses = std::move(ipv6Addresses)](
const bool &success, const EthernetInterfaceData ðData,
@@ -1372,6 +1394,11 @@
handleHostnamePatch(*hostname, asyncResp);
}
+ if (macAddress)
+ {
+ handleMACAddressPatch(iface_id, *macAddress, asyncResp);
+ }
+
if (ipv4Addresses)
{
// TODO(ed) for some reason the capture of ipv4Addresses