Redfish(Network): Implemented PATCH of StaticNameServers array
Testing:
PATCH -D patch.txt -d '{"StaticNameServers": ["3.3.3.3"]}'
PATCH -D patch.txt -d '{"StaticNameServers": ["3.3.3.3","6.6.6.6"]}'
PATCH -D patch.txt -d '{"StaticNameServers": []}'
Signed-off-by: RAJESWARAN THILLAIGOVINDAN <rajeswgo@in.ibm.com>
Change-Id: I3ffb7f5b704437b31ddfeb6a74eae3e6a582164a
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 8ba3f1c..a6ba562 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -220,7 +220,7 @@
ethData.speed = *speed;
}
}
- else if (propertyPair.first == "NameServers")
+ else if (propertyPair.first == "Nameservers")
{
const std::vector<std::string> *nameservers =
sdbusplus::message::variant_ns::get_if<
@@ -1160,6 +1160,31 @@
}
}
+ void handleStaticNameServersPatch(
+ const std::string &ifaceId,
+ const std::vector<std::string> &updatedStaticNameServers,
+ const std::shared_ptr<AsyncResp> &asyncResp)
+ {
+ crow::connections::systemBus->async_method_call(
+ [asyncResp,
+ updatedStaticNameServers](const boost::system::error_code ec) {
+ if (ec)
+ {
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ asyncResp->res.jsonValue["NameServers"] =
+ updatedStaticNameServers;
+ asyncResp->res.jsonValue["StaticNameServers"] =
+ updatedStaticNameServers;
+ },
+ "xyz.openbmc_project.Network",
+ "/xyz/openbmc_project/network/" + ifaceId,
+ "org.freedesktop.DBus.Properties", "Set",
+ "xyz.openbmc_project.Network.EthernetInterface", "Nameservers",
+ std::variant<std::vector<std::string>>{updatedStaticNameServers});
+ }
+
void parseInterfaceData(
nlohmann::json &json_response, const std::string &iface_id,
const EthernetInterfaceData ðData,
@@ -1199,6 +1224,7 @@
iface_id + "/VLANs"}};
json_response["NameServers"] = ethData.nameservers;
+ json_response["StaticNameServers"] = ethData.nameservers;
if (ipv4Data.size() > 0)
{
@@ -1270,10 +1296,12 @@
std::optional<std::string> macAddress;
std::optional<nlohmann::json> ipv4Addresses;
std::optional<nlohmann::json> ipv6Addresses;
+ std::optional<std::vector<std::string>> staticNameServers;
if (!json_util::readJson(
req, res, "HostName", hostname, "IPv4Addresses", ipv4Addresses,
- "IPv6Addresses", ipv6Addresses, "MACAddress", macAddress))
+ "IPv6Addresses", ipv6Addresses, "MACAddress", macAddress,
+ "StaticNameServers", staticNameServers))
{
return;
}
@@ -1285,7 +1313,8 @@
[this, asyncResp, iface_id, hostname = std::move(hostname),
macAddress = std::move(macAddress),
ipv4Addresses = std::move(ipv4Addresses),
- ipv6Addresses = std::move(ipv6Addresses)](
+ ipv6Addresses = std::move(ipv6Addresses),
+ staticNameServers = std::move(staticNameServers)](
const bool &success, const EthernetInterfaceData ðData,
const boost::container::flat_set<IPv4AddressData> &ipv4Data) {
if (!success)
@@ -1329,6 +1358,12 @@
messages::propertyNotWritable(asyncResp->res,
"IPv6Addresses");
}
+
+ if (staticNameServers)
+ {
+ handleStaticNameServersPatch(iface_id, *staticNameServers,
+ asyncResp);
+ }
});
}
};