Redfish: Populate DHCPv4Configuration Information
With this commit the get-request on ethernet interface service
gets the DHCPv4Configuration.The following are the properties
that are add as a part of this commit.
- UseDNSServers
- UseNTPServers
- UseDomainName
- DHCPEnabled
Tested By:(On Qemu)
GET https://<ip>/redfish/v1/Managers/bmc/EthernetInterfaces/eth0
Change-Id: Ia1f6dbe2c4f1f2ed33adc54f7fd99b61a36c1058
Signed-off-by: manojkiraneda <manojkiran.eda@gmail.com>
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 71cde15..c98c8f4 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -78,6 +78,7 @@
{
uint32_t speed;
bool auto_neg;
+ bool DHCPEnabled;
std::string hostname;
std::string default_gateway;
std::string mac_address;
@@ -230,6 +231,15 @@
ethData.nameservers = std::move(*nameservers);
}
}
+ else if (propertyPair.first == "DHCPEnabled")
+ {
+ const bool *DHCPEnabled =
+ std::get_if<bool>(&propertyPair.second);
+ if (DHCPEnabled != nullptr)
+ {
+ ethData.DHCPEnabled = *DHCPEnabled;
+ }
+ }
}
}
}
@@ -646,6 +656,50 @@
"xyz.openbmc_project.Network.IP.Protocol.IPv4", address, subnetMask,
gateway);
}
+using GetAllPropertiesType =
+ boost::container::flat_map<std::string, sdbusplus::message::variant<bool>>;
+
+inline void getDHCPConfigData(const std::shared_ptr<AsyncResp> asyncResp)
+{
+ auto getConfig = [asyncResp](const boost::system::error_code error_code,
+ const GetAllPropertiesType &dbus_data) {
+ if (error_code)
+ {
+ BMCWEB_LOG_ERROR << "D-Bus response error: " << error_code;
+ messages::internalError(asyncResp->res);
+ return;
+ }
+ nlohmann::json &DHCPConfigTypeJson =
+ asyncResp->res.jsonValue["DHCPv4Configuration"];
+ for (const auto &property : dbus_data)
+ {
+ auto value =
+ sdbusplus::message::variant_ns::get_if<bool>(&property.second);
+
+ if (value == nullptr)
+ {
+ continue;
+ }
+ if (property.first == "DNSEnabled")
+ {
+ DHCPConfigTypeJson["UseDNSServers"] = *value;
+ }
+ else if (property.first == "HostNameEnabled")
+ {
+ DHCPConfigTypeJson["UseDomainName"] = *value;
+ }
+ else if (property.first == "NTPEnabled")
+ {
+ DHCPConfigTypeJson["UseNTPServers"] = *value;
+ }
+ }
+ };
+ crow::connections::systemBus->async_method_call(
+ std::move(getConfig), "xyz.openbmc_project.Network",
+ "/xyz/openbmc_project/network/config/dhcp",
+ "org.freedesktop.DBus.Properties", "GetAll",
+ "xyz.openbmc_project.Network.DHCPConfiguration");
+}
/**
* Function that retrieves all properties for given Ethernet Interface
@@ -1154,6 +1208,9 @@
}
json_response["SpeedMbps"] = ethData.speed;
json_response["MACAddress"] = ethData.mac_address;
+ json_response["DHCPv4Configuration"]["DHCPEnabled"] =
+ ethData.DHCPEnabled;
+
if (!ethData.hostname.empty())
{
json_response["HostName"] = ethData.hostname;
@@ -1223,6 +1280,7 @@
parseInterfaceData(asyncResp->res.jsonValue, iface_id, ethData,
ipv4Data);
});
+ getDHCPConfigData(asyncResp);
}
void doPatch(crow::Response &res, const crow::Request &req,