diff options
author | David Cantrell <dcantrell@redhat.com> | 2009-04-22 00:22:50 -1000 |
---|---|---|
committer | David Cantrell <dcantrell@redhat.com> | 2009-05-04 15:14:05 -1000 |
commit | 2d0cec6dbd804b3f02a6dd7ab6b390955ea3f660 (patch) | |
tree | 37ae68fa41a3d20918c0ee63655c34eb331018fc | |
parent | e77eaf1276e015b3d7a0d15c52e9f20ba7a4deae (diff) | |
download | anaconda-2d0cec6dbd804b3f02a6dd7ab6b390955ea3f660.tar.gz anaconda-2d0cec6dbd804b3f02a6dd7ab6b390955ea3f660.tar.xz anaconda-2d0cec6dbd804b3f02a6dd7ab6b390955ea3f660.zip |
Collect network interfaces from NetworkManager (#493995)
Remove minihal.py and use NetworkManager to get a list of device names
and their hardware addresses. Still have to talk to hal via D-Bus to
build a description string, but the hal path is given to us by
NetworkManager, so we are sure we are only building a list of interfaces
that NetworkManager knows about and can communicate with.
Also rewrite command-stubs/list-harddrives to not use minihal.
-rwxr-xr-x | command-stubs/list-harddrives-stub | 48 | ||||
-rwxr-xr-x | isys/isys.py | 38 | ||||
-rw-r--r-- | minihal.py | 74 | ||||
-rw-r--r-- | network.py | 40 | ||||
-rw-r--r-- | pychecker-false-positives | 2 |
5 files changed, 93 insertions, 109 deletions
diff --git a/command-stubs/list-harddrives-stub b/command-stubs/list-harddrives-stub index ceb60368d..a8060b15b 100755 --- a/command-stubs/list-harddrives-stub +++ b/command-stubs/list-harddrives-stub @@ -18,20 +18,48 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +import dbus import sys -sys.path.append('/usr/lib/anaconda') +HAL_INTERFACE = "org.freedesktop.Hal" +HAL_MANAGER_PATH = "/org/freedesktop/Hal/Manager" +HAL_MANAGER_INTERFACE = "org.freedesktop.Hal.Manager" +HAL_DEVICE_INTERFACE = "org.freedesktop.Hal.Device" -import minihal +def main(argv): + lst = set() -lst = [] + try: + bus = dbus.SystemBus() + hal = dbus.Interface(bus.get_object(HAL_INTERFACE, + HAL_MANAGER_PATH), + HAL_MANAGER_INTERFACE) + except: + sys.exit(1) -for drive in minihal.get_devices_by_type("volume"): - if not drive.has_key("device") or not drive.has_key("volume.size"): - continue + for udi in hal.FindDeviceByCapability("volume"): + try: + haldev = dbus.Interface(bus.get_object(HAL_INTERFACE, udi), + HAL_DEVICE_INTERFACE) + props = haldev.GetAllProperties() + except dbus.exceptions.DBusException: + continue - lst.append("%s %s" % (drive["device"], drive["volume_size"]/(1024*1024))) + if not props.has_key('volume.size'): + continue -lst.sort() -for entry in lst: - print lst + size = str(props['volume.size'] / (1024 * 1024)) + if props.has_key('block.device'): + devnode = props['block.device'].encode('utf-8') + elif props.has_key('linux.device_file'): + devnode = props['linux.device_file'].encode('utf-8') + + lst.add("%s %s" % (devnode, size,)) + + lst = list(lst) + lst.sort() + for entry in lst: + print entry + +if __name__ == "__main__": + main(sys.argv) diff --git a/isys/isys.py b/isys/isys.py index 0a3fe62c5..0ea19f260 100755 --- a/isys/isys.py +++ b/isys/isys.py @@ -36,7 +36,6 @@ import resource import re import struct import block -import minihal import rhpl import dbus @@ -47,7 +46,6 @@ 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" @@ -58,6 +56,12 @@ NM_STATE_CONNECTING = 2 NM_STATE_CONNECTED = 3 NM_STATE_DISCONNECTED = 4 +HAL_SERVICE = "org.freedesktop.Hal" +HAL_PATH = "/org/freedesktop/Hal" +HAL_DEVICE_IFACE = "org.freedesktop.Hal.Device" + +DBUS_PROPS_IFACE = "org.freedesktop.DBus.Properties" + mountCount = {} MIN_RAM = _isys.MIN_RAM @@ -579,6 +583,36 @@ def getMacAddress(dev): device_macaddr = device_props_iface.Get(NM_MANAGER_IFACE, "HwAddress") return device_macaddr.upper() +# Get a description string for a network device (e.g., eth0) +def getNetDevDesc(dev): + desc = "Network Interface" + + if dev == '' or dev is None: + return desc + + 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(HAL_SERVICE, path) + device_iface = dbus.Interface(device, HAL_DEVICE_IFACE) + device_props = device_iface.get_dbus_method("GetAllProperties")() + + if dev == device_props['net.interface']: + if device_props.has_key('info.product'): + if device_props.has_key('info.vendor'): + desc = "%s %s" % (device_props['info.product'], + device_props['info.vendor'],) + else: + desc = device_props['info.product'] + else: + desc = device_props['info.udi'] + + return desc + + return desc + # Determine if a network device is a wireless device. def isWireless(dev): if dev == '' or dev is None: diff --git a/minihal.py b/minihal.py deleted file mode 100644 index 8ab93d4bf..000000000 --- a/minihal.py +++ /dev/null @@ -1,74 +0,0 @@ -# -# minihal.py: Simple wrapper around HAL -# -# Copyright (C) 2007 Red Hat, Inc. All rights reserved. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# Author(s): Bill Nottingham <notting@redhat.com> -# - -"""Simple wrapper around HAL""" - -import dbus - -def get_device(udi): - """Retrieve all properties of a particular device (by UDI)""" - try: - bus = dbus.SystemBus() - haldev = dbus.Interface(bus.get_object("org.freedesktop.Hal", udi), "org.freedesktop.Hal.Device") - props = haldev.GetAllProperties() - except dbus.exceptions.DBusException: - return None - - if props.has_key('block.device'): - props['device'] = props['block.device'].encode("utf-8") - elif props.has_key('linux.device_file'): - props['device'] = props['linux.device_file'].encode("utf-8") - elif props.has_key('net.interface'): - props['device'] = props['net.interface'].encode("utf-8") - else: - props['device'] = None - - props['description'] = '' - if props.has_key('info.product'): - if props.has_key('info.vendor'): - props['description'] = '%s %s' % (props['info.vendor'],props['info.product']) - else: - props['description'] = props['info.product'] - else: - props['description'] = props['info.udi'] - if props.has_key('net.originating_device'): - pdev = get_device(props['net.originating_device']) - props['description'] = pdev['description'] - - # mmc block devices don't show up as disks (#481431) - if props.has_key('storage.drive_type') and props['storage.drive_type'] == "sd_mmc": - props['storage.drive_type'] = "disk" - - return props - -def get_devices_by_type(type): - """Retrieve all devices of a particular type""" - ret = [] - try: - bus = dbus.SystemBus() - hal = dbus.Interface(bus.get_object("org.freedesktop.Hal","/org/freedesktop/Hal/Manager"),"org.freedesktop.Hal.Manager") - except: - return ret - for udi in hal.FindDeviceByCapability(type): - dev = get_device(udi) - if dev: - ret.append(dev) - return ret diff --git a/network.py b/network.py index e9ba2bc8c..3f4b0eec4 100644 --- a/network.py +++ b/network.py @@ -31,7 +31,6 @@ import socket import struct import os import time -import minihal import rhpl import dbus from flags import flags @@ -384,26 +383,25 @@ class Network: if flags.cmdline.has_key('ksdevice'): ksdevice = flags.cmdline['ksdevice'] - # XXX: this should use NetworkManager - for device in minihal.get_devices_by_type("net"): - if device.has_key('net.arp_proto_hw_id'): - if device['net.arp_proto_hw_id'] == 1: - dev = device['device'] - if not self.netdevices.has_key(dev): - self.netdevices[dev] = NetworkDevice(dev); - self.netdevices[dev].set(('HWADDR', device['net.address'])) - self.netdevices[dev].set(('DESC', device['description'])) - - if not ksdevice: - continue - - if ksdevice == 'link' and isys.getLinkStatus(dev): - self.ksdevice = dev - elif ksdevice == dev: - self.ksdevice = dev - elif ksdevice.find(':') != -1: - if ksdevice.lower() == device['net.address'].lower(): - self.ksdevice = dev + for dev in isys.getDeviceProperties().keys(): + if not self.netdevices.has_key(dev): + self.netdevices[dev] = NetworkDevice(dev) + + hwaddr = isys.getMacAddress(dev) + + self.netdevices[dev].set(('HWADDR', hwaddr)) + self.netdevices[dev].set(('DESC', isys.getNetDevDesc(dev))) + + if not ksdevice: + continue + + if ksdevice == 'link' and isys.getLinkStatus(dev): + self.ksdevice = dev + elif ksdevice == dev: + self.ksdevice = dev + elif ksdevice.find(':') != -1: + if ksdevice.upper() == hwaddr: + self.ksdevice = dev return self.netdevices diff --git a/pychecker-false-positives b/pychecker-false-positives index d72fe5a6a..5f222f0c5 100644 --- a/pychecker-false-positives +++ b/pychecker-false-positives @@ -10,8 +10,6 @@ setattr ^partitions.py:[0-9]*: Object \(bestprep\) has no attribute \(getPreExisting\)$ ^partitions.py:[0-9]*: Object \(bestreq\) has no attribute \(format\)$ ^iscsi.py:[0-9]*: Invalid arguments to \(addTarget\), got 0, expected between 1 and 7$ -^minihal.py:[0-9]*: Object \(haldev\) has no attribute \(GetAllProperties\)$ -^minihal.py:[0-9]*: Object \(hal\) has no attribute \(FindDeviceByCapability\)$ ^(.*isys/isys.py|network.py):[0-9]*: Object \(.*_iface\) has no attribute \(Get.*\)$ ^network.py:[0-9]*: Object \(.*props\) has no attribute \(Get\)$ ^kickstart.py:[0-9]*: No global \(fileSystemTypeGet.*\) found$ |