On 04/29/2009 04:46 PM, David Cantrell wrote:
On 04/29/2009 04:43 PM, David Cantrell wrote:
On 04/29/2009 04:42 PM, David Cantrell wrote:
On 04/29/2009 03:30 PM, Jeremy Katz wrote:
On Wednesday, April 29 2009, David Cantrell said:
Remove minihal.py and use NetworkManager to get a list of device names
I haven't looked too closely at this, but we're using minihal at least
also for list-harddrives-stub I thought
Not in the new storage code. At least grep didn't tell me we were.
And if I read that more closely, I would have caught 'stubs'. Yes, it is
in use for the list-harddrives-stub. Dunno, seems like we could get rid
of it there too.
Or not. I can modify my patch to not remove minihal.py for now. The main
change I wanted to make was to how network.py was building the list of
interfaces that we'll use and write out configuration data for.
network.py was the last .py file that was importing minihal, so I
thought that was a win too. Stupid stubs.
Updated patch that rewrites list-harddrives to not use minihal. Shrug.
--
David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI
>From 969f4650ae83d4ad88e66045f5d9b608855cd0a8 Mon Sep 17 00:00:00 2001
From: David Cantrell <dcantrell@xxxxxxxxxx>
Date: Wed, 22 Apr 2009 00:22:50 -1000
Subject: [PATCH 2/4] 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.
---
command-stubs/list-harddrives-stub | 48 ++++++++++++++++++-----
isys/isys.py | 38 +++++++++++++++++-
minihal.py | 74 ------------------------------------
network.py | 40 +++++++++----------
pychecker-false-positives | 2 -
5 files changed, 93 insertions(+), 109 deletions(-)
delete mode 100644 minihal.py
diff --git a/command-stubs/list-harddrives-stub b/command-stubs/list-harddrives-stub
index ceb6036..a8060b1 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 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
diff --git a/pychecker-false-positives b/pychecker-false-positives
index d72fe5a..5f222f0 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$
--
1.6.2.2
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list