2014-01-21 00:09:13 +08:00
|
|
|
# Copyright (C) 2006, 2013, 2014 Red Hat, Inc.
|
2007-09-22 04:28:31 +08:00
|
|
|
# Copyright (C) 2006 Hugh O. Brock <hbrock@redhat.com>
|
|
|
|
#
|
2018-04-04 21:35:41 +08:00
|
|
|
# This work is licensed under the GNU GPLv2 or later.
|
2018-03-21 03:00:02 +08:00
|
|
|
# See the COPYING file in the top-level directory.
|
2011-04-12 06:35:21 +08:00
|
|
|
|
2014-01-27 07:15:50 +08:00
|
|
|
import logging
|
|
|
|
|
2018-03-21 00:18:35 +08:00
|
|
|
from virtinst import DeviceDisk
|
2017-09-19 22:18:49 +08:00
|
|
|
|
2014-09-13 04:10:45 +08:00
|
|
|
from .baseclass import vmmGObjectUI
|
|
|
|
from .mediacombo import vmmMediaCombo
|
|
|
|
from .storagebrowse import vmmStorageBrowser
|
|
|
|
from .addstorage import vmmAddStorage
|
2007-09-22 04:28:31 +08:00
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2010-12-09 06:26:19 +08:00
|
|
|
class vmmChooseCD(vmmGObjectUI):
|
2012-05-14 21:24:56 +08:00
|
|
|
__gsignals__ = {
|
2018-03-15 20:10:09 +08:00
|
|
|
"cdrom-chosen": (vmmGObjectUI.RUN_FIRST, None, [object, str])
|
2012-05-14 21:24:56 +08:00
|
|
|
}
|
|
|
|
|
2011-07-23 00:17:19 +08:00
|
|
|
def __init__(self, vm, disk):
|
2013-09-23 04:10:16 +08:00
|
|
|
vmmGObjectUI.__init__(self, "choosecd.ui", "vmm-choose-cd")
|
2009-06-18 22:40:37 +08:00
|
|
|
|
2011-07-23 00:17:19 +08:00
|
|
|
self.vm = vm
|
2011-07-23 04:43:26 +08:00
|
|
|
self.conn = self.vm.conn
|
2009-06-18 22:40:37 +08:00
|
|
|
self.storage_browser = None
|
2014-01-15 06:18:02 +08:00
|
|
|
|
2018-05-22 03:42:50 +08:00
|
|
|
# This is also overwritten from details.py when targeting a new disk
|
2014-01-15 06:18:02 +08:00
|
|
|
self.disk = disk
|
2011-07-23 00:17:19 +08:00
|
|
|
self.media_type = disk.device
|
2007-09-22 04:28:31 +08:00
|
|
|
|
2014-01-29 02:51:59 +08:00
|
|
|
self.mediacombo = vmmMediaCombo(self.conn, self.builder, self.topwin,
|
|
|
|
self.media_type)
|
|
|
|
self.widget("media-combo-align").add(self.mediacombo.top_box)
|
|
|
|
|
2013-02-17 02:31:46 +08:00
|
|
|
self.builder.connect_signals({
|
2014-01-29 02:51:59 +08:00
|
|
|
"on_vmm_choose_cd_delete_event": self.close,
|
|
|
|
|
2007-09-22 04:28:31 +08:00
|
|
|
"on_media_toggled": self.media_toggled,
|
|
|
|
"on_fv_iso_location_browse_clicked": self.browse_fv_iso_location,
|
2014-01-29 02:51:59 +08:00
|
|
|
|
2007-09-22 04:28:31 +08:00
|
|
|
"on_ok_clicked": self.ok,
|
2011-03-21 23:01:39 +08:00
|
|
|
"on_cancel_clicked": self.close,
|
2011-04-12 06:35:21 +08:00
|
|
|
})
|
2007-09-22 04:28:31 +08:00
|
|
|
|
2008-09-09 19:35:20 +08:00
|
|
|
self.reset_state()
|
2007-09-22 04:28:31 +08:00
|
|
|
|
2010-11-30 03:06:43 +08:00
|
|
|
def close(self, ignore1=None, ignore2=None):
|
2012-02-01 07:16:54 +08:00
|
|
|
logging.debug("Closing media chooser")
|
2010-12-09 06:26:19 +08:00
|
|
|
self.topwin.hide()
|
2011-04-12 06:35:21 +08:00
|
|
|
if self.storage_browser:
|
|
|
|
self.storage_browser.close()
|
|
|
|
|
2007-09-22 04:28:31 +08:00
|
|
|
return 1
|
|
|
|
|
2011-04-14 20:47:42 +08:00
|
|
|
def show(self, parent):
|
2012-02-01 07:16:54 +08:00
|
|
|
logging.debug("Showing media chooser")
|
2008-09-09 19:35:20 +08:00
|
|
|
self.reset_state()
|
2011-04-14 20:47:42 +08:00
|
|
|
self.topwin.set_transient_for(parent)
|
2012-01-25 23:38:42 +08:00
|
|
|
self.topwin.present()
|
2015-04-08 01:56:48 +08:00
|
|
|
self.conn.schedule_priority_tick(pollnodedev=True)
|
2007-09-22 04:28:31 +08:00
|
|
|
|
2011-07-24 09:16:54 +08:00
|
|
|
def _cleanup(self):
|
|
|
|
self.vm = None
|
|
|
|
self.conn = None
|
|
|
|
self.disk = None
|
2011-04-12 06:35:21 +08:00
|
|
|
|
2011-07-24 09:16:54 +08:00
|
|
|
if self.storage_browser:
|
|
|
|
self.storage_browser.cleanup()
|
|
|
|
self.storage_browser = None
|
2014-01-29 02:51:59 +08:00
|
|
|
if self.mediacombo:
|
|
|
|
self.mediacombo.cleanup()
|
|
|
|
self.mediacombo = None
|
|
|
|
|
|
|
|
def _init_ui(self):
|
2015-04-08 01:56:48 +08:00
|
|
|
if self.media_type == vmmMediaCombo.MEDIA_FLOPPY:
|
2014-01-29 02:51:59 +08:00
|
|
|
self.widget("physical-media").set_label(_("Floppy D_rive"))
|
|
|
|
self.widget("iso-image").set_label(_("Floppy _Image"))
|
2011-04-12 06:35:21 +08:00
|
|
|
|
2008-09-09 19:35:20 +08:00
|
|
|
def reset_state(self):
|
2014-01-29 02:51:59 +08:00
|
|
|
self.mediacombo.reset_state()
|
2014-03-19 23:05:54 +08:00
|
|
|
|
|
|
|
enable_phys = not self.vm.stable_defaults()
|
|
|
|
self.widget("physical-media").set_sensitive(enable_phys)
|
|
|
|
self.widget("physical-media").set_tooltip_text("" if enable_phys else
|
|
|
|
_("Physical CDROM passthrough not supported with this hypervisor"))
|
|
|
|
|
|
|
|
use_cdrom = (self.mediacombo.has_media()) and enable_phys
|
2009-12-01 01:51:25 +08:00
|
|
|
|
2014-01-29 02:51:59 +08:00
|
|
|
self.widget("physical-media").set_active(use_cdrom)
|
|
|
|
self.widget("iso-image").set_active(not use_cdrom)
|
2008-09-09 19:35:20 +08:00
|
|
|
|
2010-11-30 03:06:43 +08:00
|
|
|
def ok(self, ignore1=None, ignore2=None):
|
2011-07-15 01:13:13 +08:00
|
|
|
if self.widget("iso-image").get_active():
|
|
|
|
path = self.widget("iso-path").get_text()
|
2007-09-22 04:28:31 +08:00
|
|
|
else:
|
2014-01-29 02:51:59 +08:00
|
|
|
path = self.mediacombo.get_path()
|
2012-11-08 21:15:02 +08:00
|
|
|
if path == "" or path is None:
|
2009-07-03 00:43:08 +08:00
|
|
|
return self.err.val_err(_("Invalid Media Path"),
|
2008-03-15 01:18:44 +08:00
|
|
|
_("A media path must be specified."))
|
2007-11-29 06:58:19 +08:00
|
|
|
|
2018-03-21 00:18:35 +08:00
|
|
|
names = DeviceDisk.path_in_use_by(self.disk.conn, path)
|
2014-01-15 06:11:51 +08:00
|
|
|
if names:
|
|
|
|
res = self.err.yes_no(
|
|
|
|
_('Disk "%s" is already in use by other guests %s') %
|
2017-09-19 22:18:49 +08:00
|
|
|
(path, names),
|
2014-01-15 06:11:51 +08:00
|
|
|
_("Do you really want to use the disk?"))
|
|
|
|
if not res:
|
|
|
|
return False
|
|
|
|
|
2014-02-11 07:08:59 +08:00
|
|
|
vmmAddStorage.check_path_search(self, self.conn, path)
|
2009-12-02 01:35:04 +08:00
|
|
|
|
2017-09-19 22:18:49 +08:00
|
|
|
try:
|
|
|
|
self.disk.path = path
|
|
|
|
except Exception as e:
|
|
|
|
return self.err.val_err(_("Invalid Media Path"), e)
|
|
|
|
|
2011-07-23 00:17:19 +08:00
|
|
|
self.emit("cdrom-chosen", self.disk, path)
|
2011-03-21 23:01:39 +08:00
|
|
|
self.close()
|
2007-09-22 04:28:31 +08:00
|
|
|
|
|
|
|
def media_toggled(self, ignore1=None, ignore2=None):
|
2014-01-29 02:51:59 +08:00
|
|
|
is_phys = bool(self.widget("physical-media").get_active())
|
|
|
|
self.mediacombo.combo.set_sensitive(is_phys)
|
|
|
|
self.widget("iso-path").set_sensitive(not is_phys)
|
|
|
|
self.widget("iso-file-chooser").set_sensitive(not is_phys)
|
2007-09-22 04:28:31 +08:00
|
|
|
|
|
|
|
def browse_fv_iso_location(self, ignore1=None, ignore2=None):
|
2009-11-11 03:30:51 +08:00
|
|
|
self._browse_file()
|
2007-09-22 04:28:31 +08:00
|
|
|
|
2010-12-10 00:22:35 +08:00
|
|
|
def set_storage_path(self, src_ignore, path):
|
2011-07-15 01:13:13 +08:00
|
|
|
self.widget("iso-path").set_text(path)
|
2009-06-18 22:40:37 +08:00
|
|
|
|
2009-11-11 03:30:51 +08:00
|
|
|
def _browse_file(self):
|
2012-11-08 21:15:02 +08:00
|
|
|
if self.storage_browser is None:
|
2010-12-09 06:26:19 +08:00
|
|
|
self.storage_browser = vmmStorageBrowser(self.conn)
|
2014-12-10 07:37:00 +08:00
|
|
|
self.storage_browser.set_finish_cb(self.set_storage_path)
|
2009-11-11 03:30:51 +08:00
|
|
|
|
2015-04-09 06:29:48 +08:00
|
|
|
self.storage_browser.set_stable_defaults(self.vm.stable_defaults())
|
2011-07-23 00:22:09 +08:00
|
|
|
|
2015-04-08 01:56:48 +08:00
|
|
|
if self.media_type == vmmMediaCombo.MEDIA_FLOPPY:
|
2011-07-23 07:12:48 +08:00
|
|
|
self.storage_browser.set_browse_reason(
|
|
|
|
self.config.CONFIG_DIR_FLOPPY_MEDIA)
|
|
|
|
else:
|
|
|
|
self.storage_browser.set_browse_reason(
|
|
|
|
self.config.CONFIG_DIR_ISO_MEDIA)
|
2015-04-09 06:29:48 +08:00
|
|
|
self.storage_browser.show(self.topwin)
|