TUI: Drop direct HAL usage, use virt-manager code

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.
This commit is contained in:
Cole Robinson 2011-07-22 18:47:07 -04:00
parent fe73a32a0a
commit eec72ee5b1
5 changed files with 31 additions and 54 deletions

View File

@ -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)

View File

@ -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 = []

View File

@ -1,44 +0,0 @@
# halworker.py - Copyright (C) 2009 Red Hat, Inc.
# Written by Darryl L. Pierce <dpierce@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

View File

@ -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()

View File

@ -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