summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormanojkiraneda <manojkiran.eda@gmail.com>2019-02-19 10:39:43 +0300
committerEd Tanous <ed.tanous@intel.com>2019-03-18 19:56:18 +0300
commit2a133282e3a841e317d1fd0215ccb4dbe6e5cb0e (patch)
tree9e143d74167d1e0f65ddcaabab8813e32adeeefc
parentf9fc2dfff6446eccfa19b1e6a06d7cc297a552c6 (diff)
downloadbmcweb-2a133282e3a841e317d1fd0215ccb4dbe6e5cb0e.tar.xz
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>
-rw-r--r--redfish-core/lib/ethernet.hpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 71cde151fe..c98c8f4b12 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -78,6 +78,7 @@ struct EthernetInterfaceData
{
uint32_t speed;
bool auto_neg;
+ bool DHCPEnabled;
std::string hostname;
std::string default_gateway;
std::string mac_address;
@@ -230,6 +231,15 @@ inline void extractEthernetInterfaceData(const std::string &ethiface_id,
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 @@ inline void createIPv4(const std::string &ifaceId, unsigned int ipIdx,
"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 @@ class EthernetInterface : public Node
}
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 @@ class EthernetInterface : public Node
parseInterfaceData(asyncResp->res.jsonValue, iface_id, ethData,
ipv4Data);
});
+ getDHCPConfigData(asyncResp);
}
void doPatch(crow::Response &res, const crow::Request &req,