[PATCH phosphor-networkd] Added DBus method GetAddressType to identify if the interface is configured with static IP address or configured by DHCP.

OpenBMC Patches openbmc-patches at stwcx.xyz
Sat Apr 30 03:40:42 AEST 2016


From: Hariharasubramanian R <hramasub at in.ibm.com>

---
 netman.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/netman.py b/netman.py
index 377833d..e2b89ca 100755
--- a/netman.py
+++ b/netman.py
@@ -192,6 +192,32 @@ class NetMan (dbus.service.Object):
         rc = call(["systemctl", "restart", "systemd-networkd.service"])
         return rc
 
+    @dbus.service.method(DBUS_NAME, "s", "s")
+    def GetAddressType (self, device):
+        if not self._isvaliddev (device) : raise ValueError, "Invalid Device"
+
+        confFile = "/etc/systemd/network/00-bmc-" + device + ".network"
+        if not os.path.exists(confFile): 
+            print "Config file (%s) not found !" % confFile
+            netprov     = network_providers [self.provider]
+            bus_name    = netprov ['bus_name']
+            obj_name    = netprov ['ip_object_name']
+            o = self.bus.get_object(bus_name, obj_name, introspect=False)
+            i = dbus.Interface(o, 'org.freedesktop.DBus.Properties')
+            f = i.Get (netprov ['ip_if_name'], "SourcePath")
+            print "Using default networkd config file (%s)" % f
+            confFile = f
+
+        with open(confFile, "r") as f:
+            for line in f:
+                config = line.split ("=")
+                if (len (config) < 2) : continue
+                if config [0].upper() == "DHCP":
+                    v = config[1].strip().upper()
+                    if (v=="YES" or v=="IPV4" or v=="IPV6"):
+                        return "DHCP"
+        return "STATIC"
+
     #family, prefixlen, ip, defgw
     @dbus.service.method(DBUS_NAME, "s", "iyss")
     def GetAddress4 (self, device):
-- 
2.8.1




More information about the openbmc mailing list