[PATCH phosphor-networkd] Adding org.openbmc.NetworkManager dbus interface for network configuation.

OpenBMC Patches openbmc-patches at stwcx.xyz
Thu Jan 21 00:30:34 AEDT 2016


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

---
 netman.py | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 111 insertions(+)
 create mode 100755 netman.py

diff --git a/netman.py b/netman.py
new file mode 100755
index 0000000..bc46fd1
--- /dev/null
+++ b/netman.py
@@ -0,0 +1,111 @@
+#!/usr/bin/env python
+
+import sys
+import subprocess
+import dbus
+import string
+import os
+import fcntl
+import glib
+import gobject
+import dbus.service
+import dbus.mainloop.glib
+
+DBUS_NAME = 'org.openbmc.NetworkManager'
+OBJ_NAME = '/org/openbmc/NetworkManager/Interface'
+
+network_providers = {
+	'networkd' : { 
+		'bus_name' : 'org.freedesktop.network1',
+		'object_name' : '/org/freedesktop/network1/network/default',
+		'interface_name' : 'org.freedesktop.network1.Network',
+		'method' : 'org.freedesktop.network1.Network.SetAddr'
+	},
+	'NetworkManager' : {
+		'bus_name' : 'org.freedesktop.NetworkManager',
+		'object_name' : '/org/freedesktop/NetworkManager',
+		'interface_name' : 'org.freedesktop.NetworkManager',
+		'method' : 'org.freedesktop.NetworkManager' # FIXME: 
+	},	
+}
+
+class IfAddr ():
+    def __init__ (self, family, scope, flags, prefixlen, addr, gw):
+        self.family     = family
+        self.scope      = scope
+        self.flags      = flags
+        self.prefixlen  = prefixlen
+        self.addr       = addr
+        self.gw         = gw
+
+class NetMan (dbus.service.Object):
+    def __init__(self, bus, name):
+        self.bus = bus
+        self.name = name
+        dbus.service.Object.__init__(self,bus,name)
+
+    def setNetworkProvider(self, provider):
+        self.provider = provider
+
+    def _setAddr (self, op, device, ipaddr, netmask, family, flags, scope, gateway):
+        netprov     = network_providers [self.provider]
+        bus_name    = netprov ['bus_name']
+        obj_path    = netprov ['object_name']
+        intf_name   = netprov ['interface_name']
+
+        obj = self.bus.get_object(bus_name, obj_path)
+        intf = dbus.Interface(obj, intf_name)
+        if (op == "add"):
+            return intf.AddAddress (device, ipaddr, netmask, family, flags, scope, gateway)
+
+        if (op == "del"):
+            return intf.DelAddress (device, ipaddr, netmask, family, flags, scope, gateway)
+
+    def _getAddr (self, target, device):
+        netprov     = network_providers [self.provider]
+        bus_name    = netprov ['bus_name']
+        obj_path    = netprov ['object_name']
+
+        if (target == "ip"):
+            intf_name   = 'org.freedesktop.network1.Network'
+
+        if (target == "mac"):
+            intf_name   = 'org.freedesktop.network1.Link'
+
+        obj = self.bus.get_object(bus_name, obj_path)
+        intf = dbus.Interface(obj, intf_name)
+        return intf.GetAddress (device)
+
+
+    @dbus.service.method(DBUS_NAME, "", "")
+    def test(self):
+        print("TEST")
+
+    @dbus.service.method(DBUS_NAME, "ssss", "x")
+    def AddAddress4 (self, device, ipaddr, netmask, gateway):
+        return self._setAddr ("add", device, ipaddr, netmask, 2, 0, 253, gateway)
+
+    @dbus.service.method(DBUS_NAME, "ssss", "x")
+    def DelAddress4 (self, device, ipaddr, netmask, gateway):
+        return self._setAddr ("del", device, ipaddr, netmask, 2, 0, 253, gateway)
+
+    @dbus.service.method(DBUS_NAME, "s", "a(iyyus)s")
+    def GetAddress4 (self, device):
+        return self._getAddr ("ip", device)
+
+    @dbus.service.method(DBUS_NAME, "s", "s")
+    def GetHwAddress (self, device):
+        return self._getAddr ("mac", device)
+
+def main():
+    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+    bus = dbus.SystemBus()
+    name = dbus.service.BusName(DBUS_NAME, bus)
+    obj = NetMan (bus, OBJ_NAME)
+    obj.setNetworkProvider ("networkd")
+    mainloop = gobject.MainLoop()
+    print("Started")
+    mainloop.run()
+
+if __name__ == '__main__':
+    sys.exit(main())
-- 
2.6.4




More information about the openbmc mailing list