From d1ea8d56e2dfc4d6a84dcc021569544033ab0b6c Mon Sep 17 00:00:00 2001 From: "Hugh O. Brock" Date: Wed, 23 Aug 2006 17:12:16 -0400 Subject: [PATCH] Pull cdrom path from HAL -- allow installs from CD as well as iso --- src/virt-manager.glade | 82 ++++++++++++++++++++++++++------------- src/virtManager/create.py | 53 ++++++++++++++++++++++--- 2 files changed, 102 insertions(+), 33 deletions(-) diff --git a/src/virt-manager.glade b/src/virt-manager.glade index 0f1785d4..df522b06 100644 --- a/src/virt-manager.glade +++ b/src/virt-manager.glade @@ -6335,34 +6335,6 @@ TB - - - True - Please insert disc 1 of the installation media for the desired operating system now. - False - False - GTK_JUSTIFY_LEFT - True - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 1 - 3 - 4 - 5 - fill - - - - True @@ -6419,6 +6391,60 @@ TB + + + + True + False + 0 + + + + True + _Path to install media: + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 5 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + False + True + + + + 0 + True + True + + + + + 1 + 3 + 4 + 5 + fill + + diff --git a/src/virtManager/create.py b/src/virtManager/create.py index d9a69211..081646ae 100644 --- a/src/virtManager/create.py +++ b/src/virtManager/create.py @@ -27,6 +27,7 @@ import subprocess import urlgrabber.grabber as grabber import tempfile import logging +import dbus from rhpl.exception import installExceptionHandler from rhpl.translate import _, N_, textdomain, utf8 @@ -57,6 +58,12 @@ class vmmCreate(gobject.GObject): self.window = gtk.glade.XML(config.get_glade_file(), "vmm-create") self.topwin = self.window.get_widget("vmm-create") self.topwin.hide() + # Get a connection to the SYSTEM bus + self.bus = dbus.SystemBus() + # Get a handle to the HAL service + hal_object = self.bus.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/Manager') + self.hal_iface = dbus.Interface(hal_object, 'org.freedesktop.Hal.Manager') + self.window.signal_autoconnect({ "on_create_pages_switch_page" : self.page_changed, "on_create_cancel_clicked" : self.close, @@ -80,6 +87,8 @@ class vmmCreate(gobject.GObject): "on_create_memory_max_value_changed" : self.set_max_memory, "on_create_memory_startup_value_changed" : self.set_startup_memory, "on_create_vcpus_changed" : self.set_vcpus, + "on_cd_focus_out_event" : self.choose_media_location, + "on_cd_path_changed" : self.choose_media_location, }) self.set_initial_state() @@ -122,6 +131,14 @@ class vmmCreate(gobject.GObject): self.window.get_widget("page5-title").modify_bg(gtk.STATE_NORMAL,black) self.window.get_widget("page6-title").modify_bg(gtk.STATE_NORMAL,black) + # set up the list for the cd-path widget + self.opt_media_list = self.window.get_widget("cd-path") + model = gtk.ListStore(str) + self.opt_media_list.set_model(model) + text = gtk.CellRendererText() + self.opt_media_list.pack_start(text, True) + self.opt_media_list.add_attribute(text, 'text', 0) + self.reset_state() def reset_state(self): @@ -185,6 +202,13 @@ class vmmCreate(gobject.GObject): elif page_number == 3: #set up the fv install media page + model = self.opt_media_list.get_model() + model.clear() + #make sure the model has one empty item + model.append() + devs = self._get_optical_devices() + for dev in devs: + model.append([dev]) if self.install_media_address != None: self.window.get_widget("fv-iso-location").set_text(self.install_media_address) else: @@ -305,10 +329,6 @@ class vmmCreate(gobject.GObject): # first things first, are we trying to create a fully virt guest? if self.virt_method == VM_FULLY_VIRT: guest = xeninst.FullVirtGuest() - #XXX use HAL to get the local path for an install image - if self.install_fv_media_type == VM_INSTALL_FROM_CD: - self._validation_error_box(_("Installs from local CD are not yet supported")) - return try: guest.cdrom = self.install_media_address except ValueError, e: @@ -413,10 +433,18 @@ class vmmCreate(gobject.GObject): if button.name == "media-iso-image": self.install_fv_media_type = VM_INSTALL_FROM_ISO self.window.get_widget("fv-iso-location-box").set_sensitive(True) + self.opt_media_list.set_sensitive(False) elif button.name == "media-physical": self.install_fv_media_type = VM_INSTALL_FROM_CD self.window.get_widget("fv-iso-location-box").set_sensitive(False) + self.opt_media_list.set_sensitive(True) + self.opt_media_list.set_active(0) + def choose_media_location(self, src): + model = self.opt_media_list.get_model() + logging.debug("User chose: " + model.get_value(self.opt_media_list.get_active_iter(), 0)) + self.install_media_address = model.get_value(self.opt_media_list.get_active_iter(), 0) + def browse_iso_location(self, ignore1=None, ignore2=None): self.install_media_address = self._browse_file(_("Locate ISO Image")) if self.install_media_address != None: @@ -522,7 +550,7 @@ class vmmCreate(gobject.GObject): self._validation_error_box(_("Hardware Support Required"), \ _("Your hardware does not appear to support full virtualization. Only paravirtualized guests will be available on this hardware.")) return False - + elif page_num == 3: # the fully virt media page if self.install_fv_media_type == VM_INSTALL_FROM_ISO and \ (self.install_media_address == None or len(self.install_media_address) == 0): @@ -635,3 +663,18 @@ class vmmCreate(gobject.GObject): ret = subprocess.call(cmd) os.rmdir(nfsmntdir) + def _get_optical_devices(self): + # get a list of optical devices with data discs in, for FV installs + optical_device_list = [] + for d in self.hal_iface.FindDeviceByCapability("volume"): + dev = self.bus.get_object("org.freedesktop.Hal", d) + if dev.GetPropertyBoolean("volume.is_disc") and \ + dev.GetPropertyBoolean("volume.disc.has_data") and \ + dev.GetPropertyBoolean("volume.is_mounted"): + print " " + dev.GetProperty("volume.mount_point") + optical_device_list.append(dev.GetProperty("volume.mount_point")) + else: + print " Device " + d + " is not an optical disc with data." + return optical_device_list + +