Move getDHCPValue function to util
Change-Id: Id90e60aec666e5098358f1890fbdead6744e2675
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/util.cpp b/util.cpp
index d96fe97..e5394ba 100644
--- a/util.cpp
+++ b/util.cpp
@@ -1,5 +1,6 @@
+#include "config_parser.hpp"
#include "util.hpp"
-
+#include "types.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
#include <phosphor-logging/log.hpp>
@@ -14,6 +15,7 @@
#include <list>
#include <string>
#include <algorithm>
+#include <experimental/filesystem>
namespace phosphor
{
@@ -25,6 +27,7 @@
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
+namespace fs = std::experimental::filesystem;
uint8_t toV6Cidr(const std::string& subnetMask)
{
@@ -339,5 +342,33 @@
}
}
+bool getDHCPValue(const std::string& confDir, const std::string& intf)
+{
+ bool dhcp = false;
+ // Get the interface mode value from systemd conf
+ //using namespace std::string_literals;
+ fs::path confPath = confDir;
+ std::string fileName = systemd::config::networkFilePrefix + intf +
+ systemd::config::networkFileSuffix;
+ confPath /= fileName;
+
+ try
+ {
+ config::Parser parser(confPath.string());
+ auto values = parser.getValues("Network", "DHCP");
+ // There will be only single value for DHCP key.
+ if (values[0] == "true")
+ {
+ dhcp = true;
+ }
+ }
+ catch (InternalFailure& e)
+ {
+ log<level::INFO>("Exception occured during getting of DHCP value");
+ }
+ return dhcp;
+}
+
+
}//namespace network
}//namespace phosphor