[virt-tools-list] [PATCH] TUI: Drop direct HAL usage, use virt-manager code

Cole Robinson crobinso at redhat.com
Fri Jul 22 22:47:07 UTC 2011


virt-manager already has code for listing CDROMs and host network devices
via libvirt's nodedev APIs (and optionally falling back to HAL if those
aren't available).

Use this in the TUI so we can drop the hard requirement on HAL, which is
deprecated.

side note: on f14, the TUI segfaults if no cdrom media devs are found when
trying to install a new guest. this issue predates this patch and is likely
a problem in newt or the python_newt bindings. I didn't really dig into
it though.
---
 src/virtManagerTui/adddomain.py       |   10 ++++---
 src/virtManagerTui/addnetwork.py      |    2 +-
 src/virtManagerTui/halworker.py       |   44 ---------------------------------
 src/virtManagerTui/libvirtworker.py   |   24 ++++++++++++++++++
 src/virtManagerTui/vmmconfigscreen.py |    5 ---
 5 files changed, 31 insertions(+), 54 deletions(-)
 delete mode 100644 src/virtManagerTui/halworker.py

diff --git a/src/virtManagerTui/adddomain.py b/src/virtManagerTui/adddomain.py
index 1a86651..e33deb7 100644
--- a/src/virtManagerTui/adddomain.py
+++ b/src/virtManagerTui/adddomain.py
@@ -149,7 +149,7 @@ class DomainConfigScreen(VmmTuiConfigScreen):
                 return True
         elif page is SELECT_CDROM_PAGE:
             if self.__install_media.getSelection() != None:
-                if len(self.get_hal().list_installable_volumes()) == 0:
+                if len(self.get_libvirt().list_installable_volumes()) == 0:
                     errors.append("No installable media is available.")
                 else:
                     return True
@@ -385,9 +385,11 @@ class DomainConfigScreen(VmmTuiConfigScreen):
 
     def get_select_cdrom_page(self, screen):
         drives = []
-        media = self.get_hal().list_installable_volumes()
-        for drive in media.keys():
-            drives.append([media[drive], drive, self.__config.is_install_media(drive)])
+        devs = self.get_libvirt().list_installable_volumes()
+        for dev in devs:
+            row = [dev.pretty_label(), dev.get_path(),
+                   self.__config.is_install_media(dev.get_path())]
+            drives.append(row)
         self.__install_media = snack.RadioBar(screen, (drives))
         grid = snack.Grid(1, 1)
         grid.setField(self.__install_media, 0, 0)
diff --git a/src/virtManagerTui/addnetwork.py b/src/virtManagerTui/addnetwork.py
index f56acf7..c6b0bf0 100644
--- a/src/virtManagerTui/addnetwork.py
+++ b/src/virtManagerTui/addnetwork.py
@@ -225,7 +225,7 @@ class AddNetworkConfigScreen(VmmTuiConfigScreen):
         ignore = screen
         devices = []
         devices.append(["NAT to any physical device", "", self.__config.get_physical_device() == ""])
-        for device in self.get_hal().list_network_devices():
+        for device in self.get_libvirt().list_network_devices():
             devices.append(["NAT to physical device %s" % device, device, self.__config.get_physical_device() == device])
         self.__physical_devices = RadioBar(screen, (devices))
         fields = []
diff --git a/src/virtManagerTui/halworker.py b/src/virtManagerTui/halworker.py
deleted file mode 100644
index 1321148..0000000
--- a/src/virtManagerTui/halworker.py
+++ /dev/null
@@ -1,44 +0,0 @@
-# halworker.py - Copyright (C) 2009 Red Hat, Inc.
-# Written by Darryl L. Pierce <dpierce at redhat.com>
-#
-# 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; version 2 of the License.
-#
-# 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, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA  02110-1301, USA.  A copy of the GNU General Public License is
-# also available at http://www.gnu.org/copyleft/gpl.html.
-
-import dbus
-
-class HALWorker:
-    '''Provides utilities for working with HAL to get hardware information.'''
-    def __init__(self):
-        self.__bus = dbus.SystemBus()
-        hobj = self.__bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager")
-        self.__conn = dbus.Interface(hobj, "org.freedesktop.Hal.Manager")
-
-    def list_installable_volumes(self):
-        result = {}
-        for udi in self.__conn.FindDeviceByCapability("volume"):
-            device = self.__bus.get_object("org.freedesktop.Hal", udi)
-            info = dbus.Interface(device, "org.freedesktop.Hal.Device")
-            if info.GetProperty("volume.is_disc"):
-                if info.GetProperty("volume.disc.has_data"):
-                    result[str(info.GetProperty("block.device"))] = info.GetProperty("volume.label")
-        return result
-
-    def list_network_devices(self):
-        result = []
-        for udi in self.__conn.FindDeviceByCapability("net"):
-            device = self.__bus.get_object("org.freedesktop.Hal", udi)
-            info = dbus.Interface(device, "org.freedesktop.Hal.Device")
-            result.append(info.GetProperty("net.interface"))
-        return result
diff --git a/src/virtManagerTui/libvirtworker.py b/src/virtManagerTui/libvirtworker.py
index 540e116..5c18910 100644
--- a/src/virtManagerTui/libvirtworker.py
+++ b/src/virtManagerTui/libvirtworker.py
@@ -122,6 +122,30 @@ class LibvirtWorker:
         '''Returns the capabilities for this libvirt host.'''
         return self.__capabilities
 
+    def list_installable_volumes(self):
+        '''
+        Return a list of host CDROM devices that have media in them
+        XXX: virt-manager code provides other info here: can list all
+             CDROM devices and whether them are empty, or report an error
+             if HAL missing and libvirt is too old
+        '''
+        devs = self.__vmmconn.mediadevs.values()
+        ret = []
+        for dev in devs:
+            if dev.has_media() and dev.media_type == "cdrom":
+                ret.append(dev)
+        return ret
+
+    def list_network_devices(self):
+        '''
+        Return a list of physical network devices on the host
+        '''
+        ret = []
+        for path in self.__vmmconn.list_net_device_paths():
+            net = self.__vmmconn.get_net_device(path)
+            ret.append(net.get_name())
+        return ret
+
     def list_domains(self, defined=True, created=True):
         '''Lists all domains.'''
         self.__vmmconn.tick()
diff --git a/src/virtManagerTui/vmmconfigscreen.py b/src/virtManagerTui/vmmconfigscreen.py
index fd45966..88a8adc 100644
--- a/src/virtManagerTui/vmmconfigscreen.py
+++ b/src/virtManagerTui/vmmconfigscreen.py
@@ -22,7 +22,6 @@ from snack import Label
 from types import StringType
 
 from newt_syrup import configscreen
-from halworker import HALWorker
 from libvirtworker import LibvirtWorker, VirtManagerConfig
 
 BACK_BUTTON   = "back"
@@ -35,13 +34,9 @@ class VmmTuiConfigScreen(configscreen.ConfigScreen):
 
     def __init__(self, title):
         configscreen.ConfigScreen.__init__(self, title)
-        self.__hal = HALWorker()
         self.__libvirt = LibvirtWorker()
         self.__vm_config = VirtManagerConfig()
 
-    def get_hal(self):
-        return self.__hal
-
     def get_libvirt(self):
         return self.__libvirt
 
-- 
1.7.4.4




More information about the virt-tools-list mailing list