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. --- isys/isys.py | 38 ++++++++++++++++++++++++++++- minihal.py | 74 ---------------------------------------------------------- network.py | 40 +++++++++++++++---------------- 3 files changed, 55 insertions(+), 97 deletions(-) delete mode 100644 minihal.py diff --git a/isys/isys.py b/isys/isys.py index 88bfaf1..492a7e8 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 8ab93d4..0000000 --- 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@xxxxxxxxxx> -# - -"""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 e9ba2bc..3f4b0ee 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 -- 1.6.2.2 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list