diff options
author | David Cantrell <dcantrell@redhat.com> | 2008-08-25 16:58:01 -1000 |
---|---|---|
committer | David Cantrell <dcantrell@redhat.com> | 2008-08-25 16:58:01 -1000 |
commit | ccaf2b3c42b1fefb10b1a9986da2e6bb718048fd (patch) | |
tree | 25e7f76bf2ba3909c920eac13b30de715fe98c39 /isys | |
parent | 246b9bd30381153e5dc72a2cbac8f2d534c5ee2b (diff) | |
download | anaconda-ccaf2b3c42b1fefb10b1a9986da2e6bb718048fd.tar.gz anaconda-ccaf2b3c42b1fefb10b1a9986da2e6bb718048fd.tar.xz anaconda-ccaf2b3c42b1fefb10b1a9986da2e6bb718048fd.zip |
Add getDeviceProperties() and rewrite getMacAddress()
Created isys.getDeviceProperties() that returns a D-Bus
properties interface to the caller for the specified network
device. Rewrote getMacAddress() to no longer rely on the
iface_mac2str() function.
Diffstat (limited to 'isys')
-rw-r--r-- | isys/isys.c | 14 | ||||
-rwxr-xr-x | isys/isys.py | 97 |
2 files changed, 48 insertions, 63 deletions
diff --git a/isys/isys.c b/isys/isys.c index eecf1f8c4..21592cde9 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -125,7 +125,6 @@ static PyObject * py_bind_textdomain_codeset(PyObject * o, 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); #ifdef USESELINUX static PyObject * doMatchPathContext(PyObject * s, PyObject * args); static PyObject * doSetFileContext(PyObject * s, PyObject * args); @@ -175,7 +174,6 @@ static PyMethodDef isysModuleMethods[] = { { "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}, #ifdef USESELINUX { "matchPathContext", (PyCFunction) doMatchPathContext, METH_VARARGS, NULL }, { "setFileContext", (PyCFunction) doSetFileContext, METH_VARARGS, NULL }, @@ -952,18 +950,6 @@ static PyObject * getFramebufferInfo(PyObject * s, PyObject * args) { return Py_BuildValue("(iii)", fb.xres, fb.yres, fb.bits_per_pixel); } -static PyObject * doGetMacAddress(PyObject * s, PyObject * args) { - char *dev; - char *ret; - - if (!PyArg_ParseTuple(args, "s", &dev)) - return NULL; - - ret = iface_mac2str(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 c3d56f30d..0a714e364 100755 --- a/isys/isys.py +++ b/isys/isys.py @@ -913,19 +913,8 @@ def isIsoImage(file): def fbinfo(): return _isys.fbinfo() -## 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. -def getMacAddress(dev): - return _isys.getMacAddress(dev) - -## Determine if a network device is a wireless device. -# @param dev The network device to check. -# @return True if dev is a wireless network device, False otherwise. -def isWireless(dev): - if dev == '' or dev is None: - return False - +# Get a D-Bus interface for the specified device's (e.g., eth0) properties +def getDeviceProperties(dev): bus = dbus.SystemBus() nm = bus.get_object(NM_SERVICE, NM_MANAGER_PATH) devlist = nm.get_dbus_method("GetDevices")() @@ -938,53 +927,63 @@ def isWireless(dev): if str(device_interface) != dev: continue - device_type = int(device_props_iface.Get(NM_MANAGER_IFACE, "DeviceType")) + return device_props_iface - # from include/NetworkManager.h in the NM source code - # 0 == NM_DEVICE_TYPE_UNKNOWN - # 1 == NM_DEVICE_TYPE_ETHERNET - # 2 == NM_DEVICE_TYPE_WIFI - # 3 == NM_DEVICE_TYPE_GSM - # 4 == NM_DEVICE_TYPE_CDMA - if device_type == 2: - return True - else: - return False + return None - return False +# Get the MAC address for a network device. +def getMacAddress(dev): + if dev == '' or dev is None: + return False -## Get the IP address for a network device. -# @param dev The network device to check. -# @see netlink_interfaces_ip2str -# @return The IPv4 address for dev, or None on error. -def getIPAddress(dev): + device_props_iface = getDeviceProperties(dev) + if device_props_iface is None: + return None + + device_macaddr = device_props_iface.Get(NM_MANAGER_IFACE, "HwAddress") + return device_macaddr.upper() + +# Determine if a network device is a wireless device. +def isWireless(dev): if dev == '' or dev is None: - return None + return False - bus = dbus.SystemBus() - nm = bus.get_object(NM_SERVICE, NM_MANAGER_PATH) - devlist = nm.get_dbus_method("GetDevices")() + device_props_iface = getDeviceProperties(dev) + if device_props_iface is None: + return None - for path in devlist: - device = bus.get_object(NM_SERVICE, path) - device_props_iface = dbus.Interface(device, DBUS_PROPS_IFACE) + device_type = int(device_props_iface.Get(NM_MANAGER_IFACE, "DeviceType")) - device_interface = device_props_iface.Get(NM_MANAGER_IFACE, "Interface") - if str(device_interface) != dev: - continue + # from include/NetworkManager.h in the NM source code + # 0 == NM_DEVICE_TYPE_UNKNOWN + # 1 == NM_DEVICE_TYPE_ETHERNET + # 2 == NM_DEVICE_TYPE_WIFI + # 3 == NM_DEVICE_TYPE_GSM + # 4 == NM_DEVICE_TYPE_CDMA + if device_type == 2: + return True + else: + return False - # XXX: add support for IPv6 addresses when NM can do that - device_ip4addr = device_props_iface.Get(NM_MANAGER_IFACE, "Ip4Address") +# Get the IP address for a network device. +def getIPAddress(dev): + if dev == '' or dev is None: + return None - try: - tmp = struct.pack('I', device_ip4addr) - address = socket.inet_ntop(socket.AF_INET, tmp) - except ValueError, e: - return None + device_props_iface = getDeviceProperties(dev) + if device_props_iface is None: + return None - return address + # XXX: add support for IPv6 addresses when NM can do that + device_ip4addr = device_props_iface.Get(NM_MANAGER_IFACE, "Ip4Address") - return None + try: + tmp = struct.pack('I', device_ip4addr) + address = socket.inet_ntop(socket.AF_INET, tmp) + except ValueError, e: + return None + + return address ## Get the correct context for a file from loaded policy. # @param fn The filename to query. |