diff options
author | David Cantrell <dcantrell@redhat.com> | 2008-08-25 16:30:48 -1000 |
---|---|---|
committer | David Cantrell <dcantrell@redhat.com> | 2008-08-25 16:30:48 -1000 |
commit | bf30dd85aac92dce3f0d398aa320ebf88a76be6d (patch) | |
tree | 476ff74c1bc6887f9b85f3e2817d023473c33bb8 /isys | |
parent | e33f9cf2200614784447559e3b4255c1805fbf28 (diff) | |
download | anaconda-bf30dd85aac92dce3f0d398aa320ebf88a76be6d.tar.gz anaconda-bf30dd85aac92dce3f0d398aa320ebf88a76be6d.tar.xz anaconda-bf30dd85aac92dce3f0d398aa320ebf88a76be6d.zip |
Rewrite isys.getIPAddress() to use D-Bus and NetworkManager.
Removed the doGetIPAddress() function from isys.c and have the
Python getIPAddress() function talk to NetworkManager to get
the IP address and return it to the caller.
Diffstat (limited to 'isys')
-rw-r--r-- | isys/isys.c | 27 | ||||
-rwxr-xr-x | isys/isys.py | 51 |
2 files changed, 36 insertions, 42 deletions
diff --git a/isys/isys.c b/isys/isys.c index 7b09779dc..45d45941c 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -123,12 +123,10 @@ static PyObject * doisIsoImage(PyObject * s, PyObject * args); static PyObject * getFramebufferInfo(PyObject * s, PyObject * args); static PyObject * printObject(PyObject * s, PyObject * args); static PyObject * py_bind_textdomain_codeset(PyObject * o, PyObject * args); -static PyObject * getLinkStatus(PyObject * s, PyObject * args); static PyObject * py_getDasdPorts(PyObject * s, PyObject * args); static PyObject * py_isUsableDasd(PyObject * s, PyObject * args); static PyObject * py_isLdlDasd(PyObject * s, PyObject * args); static PyObject * doGetMacAddress(PyObject * s, PyObject * args); -static PyObject * doGetIPAddress(PyObject * s, PyObject * args); #ifdef USESELINUX static PyObject * doMatchPathContext(PyObject * s, PyObject * args); static PyObject * doSetFileContext(PyObject * s, PyObject * args); @@ -176,12 +174,10 @@ static PyMethodDef isysModuleMethods[] = { { "fbinfo", (PyCFunction) getFramebufferInfo, METH_VARARGS, NULL}, { "printObject", (PyCFunction) printObject, METH_VARARGS, NULL}, { "bind_textdomain_codeset", (PyCFunction) py_bind_textdomain_codeset, METH_VARARGS, NULL}, - { "getLinkStatus", (PyCFunction) getLinkStatus, METH_VARARGS, NULL }, { "getDasdPorts", (PyCFunction) py_getDasdPorts, METH_VARARGS, NULL}, { "isUsableDasd", (PyCFunction) py_isUsableDasd, METH_VARARGS, NULL}, { "isLdlDasd", (PyCFunction) py_isLdlDasd, METH_VARARGS, NULL}, { "getMacAddress", (PyCFunction) doGetMacAddress, METH_VARARGS, NULL}, - { "getIPAddress", (PyCFunction) doGetIPAddress, METH_VARARGS, NULL}, #ifdef USESELINUX { "matchPathContext", (PyCFunction) doMatchPathContext, METH_VARARGS, NULL }, { "setFileContext", (PyCFunction) doSetFileContext, METH_VARARGS, NULL }, @@ -959,18 +955,6 @@ static PyObject * getFramebufferInfo(PyObject * s, PyObject * args) { return Py_BuildValue("(iii)", fb.xres, fb.yres, fb.bits_per_pixel); } -static PyObject * getLinkStatus(PyObject * s, PyObject * args) { - char *dev; - int ret; - - if (!PyArg_ParseTuple(args, "s", &dev)) - return NULL; - - ret = get_link_status(dev); - /* returns 1 for link, 0 for no link, -1 for unknown */ - return Py_BuildValue("i", ret); -} - static PyObject * doGetMacAddress(PyObject * s, PyObject * args) { char *dev; char *ret; @@ -995,17 +979,6 @@ static PyObject * isWireless(PyObject * s, PyObject * args) { return Py_BuildValue("i", ret); } -static PyObject * doGetIPAddress(PyObject * s, PyObject * args) { - char *dev = NULL; - char *ret = NULL; - - if (!PyArg_ParseTuple(args, "s", &dev)) - return NULL; - - ret = iface_ip2str(dev); - - return Py_BuildValue("s", ret); -} #ifdef USESELINUX static PyObject * doMatchPathContext(PyObject * s, PyObject * args) { char *fn, *buf = NULL; diff --git a/isys/isys.py b/isys/isys.py index 02d96d501..bbfeec951 100755 --- a/isys/isys.py +++ b/isys/isys.py @@ -38,11 +38,20 @@ import struct import block import minihal import rhpl +import dbus import logging log = logging.getLogger("anaconda") import warnings +NM_SERVICE = "org.freedesktop.NetworkManager" +NM_MANAGER_PATH = "/org/freedesktop/NetworkManager" +NM_MANAGER_IFACE = "org.freedesktop.NetworkManager" +DBUS_PROPS_IFACE = "org.freedesktop.DBus.Properties" +NM_ACTIVE_CONNECTION_IFACE = "org.freedesktop.NetworkManager.Connection.Active" +NM_CONNECTION_IFACE = "org.freedesktop.NetworkManagerSettings.Connection" +NM_DEVICE_IFACE = "org.freedesktop.NetworkManager.Device" + mountCount = {} raidCount = {} @@ -904,20 +913,6 @@ def isIsoImage(file): def fbinfo(): return _isys.fbinfo() -## Determine whether a network device has a link present or not. -# @param dev The network device to check. -# @return True if there is a link, False if not or if dev is in an unknown -# state. -def getLinkStatus(dev): - if dev == '' or dev is None: - return False - - # getLinkStatus returns 1 for link, 0 for no link, -1 for unknown state - if _isys.getLinkStatus(dev) == 1: - return True - else: - return False - ## Get the MAC address for a network device. # @param dev The network device to check. # @return The MAC address for dev as a string, or None on error. @@ -935,7 +930,33 @@ def isWireless(dev): # @see netlink_interfaces_ip2str # @return The IPv4 address for dev, or None on error. def getIPAddress(dev): - return _isys.getIPAddress(dev) + if dev == '' or dev is None: + return None + + bus = dbus.SystemBus() + nm = bus.get_object(NM_SERVICE, NM_MANAGER_PATH) + devlist = nm.get_dbus_method("GetDevices")() + + for path in devlist: + device = bus.get_object(NM_SERVICE, path) + device_props_iface = dbus.Interface(device, DBUS_PROPS_IFACE) + + device_interface = device_props_iface.Get(NM_MANAGER_IFACE, "Interface") + if str(device_interface) != dev: + continue + + # XXX: add support for IPv6 addresses when NM can do that + device_ip4addr = device_props_iface.Get(NM_MANAGER_IFACE, "Ip4Address") + + try: + tmp = struct.pack('I', device_ip4addr) + address = socket.inet_ntop(socket.AF_INET, tmp) + except ValueError, e: + return None + + return address + + return None ## Get the correct context for a file from loaded policy. # @param fn The filename to query. |