diff options
author | Ratan Gupta <ratagupt@in.ibm.com> | 2017-08-13 09:40:14 +0530 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-08-13 11:32:54 +0000 |
commit | 56187e78088b7314e1cf0328ae92690a42a04152 (patch) | |
tree | 6e070a4d6c1c5e9d769e672966ce8cafd622ff41 | |
parent | 1bc8ed300efbf5d49ef01679fa99bb437c40ccaa (diff) | |
download | phosphor-networkd-56187e78088b7314e1cf0328ae92690a42a04152.tar.gz phosphor-networkd-56187e78088b7314e1cf0328ae92690a42a04152.zip |
Move getDHCPValue function to util
Change-Id: Id90e60aec666e5098358f1890fbdead6744e2675
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
-rw-r--r-- | network_manager.cpp | 29 | ||||
-rw-r--r-- | network_manager.hpp | 5 | ||||
-rw-r--r-- | util.cpp | 33 | ||||
-rw-r--r-- | util.hpp | 5 |
4 files changed, 38 insertions, 34 deletions
diff --git a/network_manager.cpp b/network_manager.cpp index 73d76d3..3916dfb 100644 --- a/network_manager.cpp +++ b/network_manager.cpp @@ -1,5 +1,4 @@ #include "config.h" -#include "config_parser.hpp" #include "util.hpp" #include "network_manager.hpp" #include "network_config.hpp" @@ -83,7 +82,7 @@ void Manager::createInterfaces() // normal ethernet inetrface objPath /= intfInfo.first; - auto dhcp = getDHCPValue(intfInfo.first); + auto dhcp = getDHCPValue(confDir, intfInfo.first); auto intf = std::make_shared<phosphor::network::EthernetInterface>( bus, @@ -178,31 +177,5 @@ void Manager::writeToConfigurationFile() } } -bool Manager::getDHCPValue(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 = "00-bmc-"s + intf + ".network"s; - 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 diff --git a/network_manager.hpp b/network_manager.hpp index 4849faf..1890565 100644 --- a/network_manager.hpp +++ b/network_manager.hpp @@ -105,11 +105,6 @@ class Manager : public details::VLANCreateIface /** @brief BMC network reset - resets network configuration for BMC. */ void reset() override; - /** @brief read the DHCP value from the configuration file - * @param[in] intf - Interface name. - */ - bool getDHCPValue(const std::string& intf); - /** @brief Path of Object. */ std::string objectPath; @@ -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 @@ namespace 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 @@ void deleteInterface(const std::string& intf) } } +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 @@ -68,6 +68,11 @@ inline void restartSystemdUnit(const std::string& unit) */ void deleteInterface(const std::string& intf); +/** @brief read the DHCP value from the configuration file + * @param[in] confDir - Network configuration directory. + * @param[in] intf - Interface name. + */ +bool getDHCPValue(const std::string& confDir, const std::string& intf); } //namespace network |