virt-manager/virtManager/delete.py

391 lines
13 KiB
Python
Raw Normal View History

2009-03-10 04:17:09 +08:00
#
# Copyright (C) 2009, 2012-2013 Red Hat, Inc.
2009-03-10 04:17:09 +08:00
# Copyright (C) 2009 Cole Robinson <crobinso@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; 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
#
# pylint: disable=E0611
Convert to use GTK3 and GObject Introspection bindings Switch over to use GObject introspection bindings for all python modules related to GObject/GTK3/etc. It is not possible to mix and match old pyggtk/pygobject manual bindings with new introspection based bindings so it must be all changed in one go. Imports like import gtk Change to from gi.repository import Gtk The vmmGObject class is changed to always inherit from GObject.GObject There is no compelling reason to avoid a GObject dep for the virt-manager TUI & it horribly messed up the code. Signal declarations are changed from vmmChooseCD.signal_new(vmmChooseCD, "cdrom-chosen", [object, str]) To __gsignals__ = { "cdrom-chosen": (GObject.SignalFlags.RUN_FIRST, None, [object, str]) } which is required by new GObject bindings Most of the rest of the change is simply dealing with renamed constants / classes. Alot of legacy compat code was removed - ie helpers which check to see if certain GTK2 methods are available are no longer required since we're mandating GTK3 only. The event loop is replaced with LibvirtGLib's event loop. Still todo - Rip out all DBus stuff & make vmmEngine class inherit GtkApplication which provides unique support & DBus method handling - Switch to use LibvirtGConfig & LibvirtGObject for libvirt interaction - Possibly switch to Python 3 too ? - Figure out why GNOME keyring is missing Introspection support My suggestion is that the standalone GIT repo for virt-install only live on as a support branch for legacy platforms. A stable-0.9 branch of virt-manager can be kept for legacy PyGtk2 based virt-manager releases. The virt-manager master branch should exclusively use GObject inspection and ideally Python3 and contain both the virt-manager and virt-install codebases in one since they are intimately related to each other & using separate GIT repos has needlessly complicated life for everyone. crobinso: Some locking fixes Misc cleanups and dropping now-useless code Fix dbus usage Fix graph cell renderer regression Fix a couple tooltip issues
2012-05-14 21:24:56 +08:00
from gi.repository import Gtk
from gi.repository import Gdk
# pylint: enable=E0611
2009-03-10 04:17:09 +08:00
import os
import stat
2009-03-10 04:17:09 +08:00
import traceback
import logging
import virtinst
from virtinst import util
2009-03-10 04:17:09 +08:00
from virtManager.asyncjob import vmmAsyncJob
from virtManager.baseclass import vmmGObjectUI
from virtManager import uiutil
2009-03-10 04:17:09 +08:00
STORAGE_ROW_CONFIRM = 0
STORAGE_ROW_CANT_DELETE = 1
STORAGE_ROW_PATH = 2
STORAGE_ROW_TARGET = 3
STORAGE_ROW_ICON_SHOW = 4
STORAGE_ROW_ICON = 5
STORAGE_ROW_ICON_SIZE = 6
STORAGE_ROW_TOOLTIP = 7
2010-12-09 06:26:19 +08:00
class vmmDeleteDialog(vmmGObjectUI):
def __init__(self):
vmmGObjectUI.__init__(self, "delete.ui", "vmm-delete")
self.vm = None
self.conn = None
2009-03-10 04:17:09 +08:00
self.builder.connect_signals({
2009-03-10 04:17:09 +08:00
"on_vmm_delete_delete_event" : self.close,
"on_delete_cancel_clicked" : self.close,
"on_delete_ok_clicked" : self.finish,
"on_delete_remove_storage_toggled" : self.toggle_remove_storage,
})
self.bind_escape_key_close()
2009-03-10 04:17:09 +08:00
self._init_state()
2009-03-10 04:17:09 +08:00
def _init_state(self):
blue = Gdk.Color.parse("#0072A8")[1]
self.widget("header").modify_bg(Gtk.StateType.NORMAL, blue)
2009-03-10 04:17:09 +08:00
prepare_storage_list(self.widget("delete-storage-list"))
2009-03-10 04:17:09 +08:00
2011-04-14 20:47:42 +08:00
def show(self, vm, parent):
logging.debug("Showing delete wizard")
self.vm = vm
self.conn = vm.conn
2009-03-10 04:17:09 +08:00
self.reset_state()
2011-04-14 20:47:42 +08:00
self.topwin.set_transient_for(parent)
2009-03-10 04:17:09 +08:00
self.topwin.present()
def close(self, ignore1=None, ignore2=None):
logging.debug("Closing delete wizard")
2009-03-10 04:17:09 +08:00
self.topwin.hide()
self.vm = None
self.conn = None
2009-03-10 04:17:09 +08:00
return 1
def _cleanup(self):
self.vm = None
self.conn = None
2009-03-10 04:17:09 +08:00
def reset_state(self):
# Set VM name in title'
title_str = ("<span size='large' color='white'>%s '%s'</span>" %
(_("Delete"), util.xml_escape(self.vm.get_name())))
self.widget("header-label").set_markup(title_str)
2009-03-10 04:17:09 +08:00
self.widget("delete-cancel").grab_focus()
2009-12-15 05:48:35 +08:00
# Show warning message if VM is running
vm_active = self.vm.is_active()
uiutil.set_grid_row_visible(
self.widget("delete-warn-running-vm-box"), vm_active)
2009-03-10 04:17:09 +08:00
# Disable storage removal by default
self.widget("delete-remove-storage").set_active(True)
self.widget("delete-remove-storage").toggled()
2009-03-10 04:17:09 +08:00
populate_storage_list(self.widget("delete-storage-list"),
2009-03-10 04:17:09 +08:00
self.vm, self.conn)
def toggle_remove_storage(self, src):
dodel = src.get_active()
uiutil.set_grid_row_visible(
self.widget("delete-storage-scroll"), dodel)
2009-03-10 04:17:09 +08:00
def get_paths_to_delete(self):
del_list = self.widget("delete-storage-list")
2009-03-10 04:17:09 +08:00
model = del_list.get_model()
paths = []
if self.widget("delete-remove-storage").get_active():
2009-03-10 04:17:09 +08:00
for row in model:
if (not row[STORAGE_ROW_CANT_DELETE] and
row[STORAGE_ROW_CONFIRM]):
paths.append(row[STORAGE_ROW_PATH])
return paths
def _finish_cb(self, error, details):
self.topwin.set_sensitive(True)
self.topwin.get_window().set_cursor(
Gdk.Cursor.new(Gdk.CursorType.TOP_LEFT_ARROW))
if error is not None:
self.err.show_err(error, details=details)
self.conn.schedule_priority_tick(pollvm=True)
self.close()
def finish(self, src_ignore):
2009-03-10 04:17:09 +08:00
devs = self.get_paths_to_delete()
if devs:
title = _("Are you sure you want to delete the storage?")
message = (_("The following paths will be deleted:\n\n%s") %
"\n".join(devs))
ret = self.err.chkbox_helper(
self.config.get_confirm_delstorage,
self.config.set_confirm_delstorage,
text1=title, text2=message)
if not ret:
return
2009-03-10 04:17:09 +08:00
self.topwin.set_sensitive(False)
self.topwin.get_window().set_cursor(
Gdk.Cursor.new(Gdk.CursorType.WATCH))
2009-03-10 04:17:09 +08:00
title = _("Deleting virtual machine '%s'") % self.vm.get_name()
text = title
if devs:
2009-07-15 05:06:50 +08:00
text = title + _(" and selected storage (this may take a while)")
2009-03-10 04:17:09 +08:00
progWin = vmmAsyncJob(self._async_delete, [devs],
self._finish_cb, [],
2011-04-14 20:47:42 +08:00
title, text, self.topwin)
progWin.run()
2009-03-10 04:17:09 +08:00
2010-12-10 22:57:42 +08:00
def _async_delete(self, asyncjob, paths):
2009-03-10 04:17:09 +08:00
storage_errors = []
details = ""
2009-03-10 04:17:09 +08:00
try:
if self.vm.is_active():
logging.debug("Forcing VM '%s' power off.", self.vm.get_name())
self.vm.destroy()
conn = self.conn.get_backend()
meter = asyncjob.get_meter()
2009-03-10 04:17:09 +08:00
for path in paths:
try:
logging.debug("Deleting path: %s", path)
meter.start(text=_("Deleting path '%s'") % path)
self._async_delete_path(conn, path, meter)
2009-03-10 04:17:09 +08:00
except Exception, e:
storage_errors.append((str(e),
"".join(traceback.format_exc())))
meter.end(0)
logging.debug("Removing VM '%s'", self.vm.get_name())
2009-03-10 04:17:09 +08:00
self.vm.delete()
except Exception, e:
error = (_("Error deleting virtual machine '%s': %s") %
(self.vm.get_name(), str(e)))
details = "".join(traceback.format_exc())
2009-03-10 04:17:09 +08:00
storage_errstr = ""
for errinfo in storage_errors:
storage_errstr += "%s\n%s\n" % (errinfo[0], errinfo[1])
if not storage_errstr and not details:
2009-03-10 04:17:09 +08:00
return
# We had extra storage errors. If there was another error message,
# errors to it. Otherwise, build the main error around them.
if details:
details += "\n\n"
details += _("Additionally, there were errors removing"
2009-03-10 04:17:09 +08:00
" certain storage devices: \n")
details += storage_errstr
2009-03-10 04:17:09 +08:00
else:
error = _("Errors encountered while removing certain "
2009-03-10 04:17:09 +08:00
"storage devices.")
details = storage_errstr
if error:
asyncjob.set_error(error, details)
2009-03-10 04:17:09 +08:00
def _async_delete_path(self, conn, path, ignore):
vol = None
try:
vol = conn.storageVolLookupByPath(path)
except:
logging.debug("Path '%s' is not managed. Deleting locally", path)
2009-03-10 04:17:09 +08:00
if vol:
vol.delete(0)
else:
os.unlink(path)
def populate_storage_list(storage_list, vm, conn):
model = storage_list.get_model()
model.clear()
diskdata = [(disk.target, disk.path, disk.read_only, disk.shareable) for
disk in vm.get_disk_devices()]
diskdata.append(("kernel", vm.get_xmlobj().os.kernel, True, False))
diskdata.append(("initrd", vm.get_xmlobj().os.initrd, True, False))
diskdata.append(("dtb", vm.get_xmlobj().os.dtb, True, False))
2009-03-10 04:17:09 +08:00
for target, path, ro, shared in diskdata:
if not path:
continue
2009-03-10 04:17:09 +08:00
# There are a few pieces here
# 1) Can we even delete the storage? If not, make the checkbox
# inconsistent. self.can_delete decides this for us, and if
# we can't delete, gives us a nice message to show the user
# for that row.
#
# 2) If we can delete, do we want to delete this storage by
# default? Reasons not to, are if the storage is marked
# readonly or sharable, or is in use by another VM.
default = False
definfo = None
vol = conn.get_vol_by_path(path)
can_del, delinfo = can_delete(conn, vol, path)
if can_del:
default, definfo = do_we_default(conn, vm.get_name(), vol,
path, ro, shared)
info = None
if not can_del:
info = delinfo
elif not default:
info = definfo
Convert to use GTK3 and GObject Introspection bindings Switch over to use GObject introspection bindings for all python modules related to GObject/GTK3/etc. It is not possible to mix and match old pyggtk/pygobject manual bindings with new introspection based bindings so it must be all changed in one go. Imports like import gtk Change to from gi.repository import Gtk The vmmGObject class is changed to always inherit from GObject.GObject There is no compelling reason to avoid a GObject dep for the virt-manager TUI & it horribly messed up the code. Signal declarations are changed from vmmChooseCD.signal_new(vmmChooseCD, "cdrom-chosen", [object, str]) To __gsignals__ = { "cdrom-chosen": (GObject.SignalFlags.RUN_FIRST, None, [object, str]) } which is required by new GObject bindings Most of the rest of the change is simply dealing with renamed constants / classes. Alot of legacy compat code was removed - ie helpers which check to see if certain GTK2 methods are available are no longer required since we're mandating GTK3 only. The event loop is replaced with LibvirtGLib's event loop. Still todo - Rip out all DBus stuff & make vmmEngine class inherit GtkApplication which provides unique support & DBus method handling - Switch to use LibvirtGConfig & LibvirtGObject for libvirt interaction - Possibly switch to Python 3 too ? - Figure out why GNOME keyring is missing Introspection support My suggestion is that the standalone GIT repo for virt-install only live on as a support branch for legacy platforms. A stable-0.9 branch of virt-manager can be kept for legacy PyGtk2 based virt-manager releases. The virt-manager master branch should exclusively use GObject inspection and ideally Python3 and contain both the virt-manager and virt-install codebases in one since they are intimately related to each other & using separate GIT repos has needlessly complicated life for everyone. crobinso: Some locking fixes Misc cleanups and dropping now-useless code Fix dbus usage Fix graph cell renderer regression Fix a couple tooltip issues
2012-05-14 21:24:56 +08:00
icon = Gtk.STOCK_DIALOG_WARNING
icon_size = Gtk.IconSize.LARGE_TOOLBAR
2009-03-10 04:17:09 +08:00
row = [default, not can_del, path, target,
bool(info), icon, icon_size, info]
model.append(row)
def prepare_storage_list(storage_list):
# Checkbox, deleteable?, storage path, target (hda), icon stock,
# icon size, tooltip
Convert to use GTK3 and GObject Introspection bindings Switch over to use GObject introspection bindings for all python modules related to GObject/GTK3/etc. It is not possible to mix and match old pyggtk/pygobject manual bindings with new introspection based bindings so it must be all changed in one go. Imports like import gtk Change to from gi.repository import Gtk The vmmGObject class is changed to always inherit from GObject.GObject There is no compelling reason to avoid a GObject dep for the virt-manager TUI & it horribly messed up the code. Signal declarations are changed from vmmChooseCD.signal_new(vmmChooseCD, "cdrom-chosen", [object, str]) To __gsignals__ = { "cdrom-chosen": (GObject.SignalFlags.RUN_FIRST, None, [object, str]) } which is required by new GObject bindings Most of the rest of the change is simply dealing with renamed constants / classes. Alot of legacy compat code was removed - ie helpers which check to see if certain GTK2 methods are available are no longer required since we're mandating GTK3 only. The event loop is replaced with LibvirtGLib's event loop. Still todo - Rip out all DBus stuff & make vmmEngine class inherit GtkApplication which provides unique support & DBus method handling - Switch to use LibvirtGConfig & LibvirtGObject for libvirt interaction - Possibly switch to Python 3 too ? - Figure out why GNOME keyring is missing Introspection support My suggestion is that the standalone GIT repo for virt-install only live on as a support branch for legacy platforms. A stable-0.9 branch of virt-manager can be kept for legacy PyGtk2 based virt-manager releases. The virt-manager master branch should exclusively use GObject inspection and ideally Python3 and contain both the virt-manager and virt-install codebases in one since they are intimately related to each other & using separate GIT repos has needlessly complicated life for everyone. crobinso: Some locking fixes Misc cleanups and dropping now-useless code Fix dbus usage Fix graph cell renderer regression Fix a couple tooltip issues
2012-05-14 21:24:56 +08:00
model = Gtk.ListStore(bool, bool, str, str, bool, str, int, str)
2009-03-10 04:17:09 +08:00
storage_list.set_model(model)
storage_list.set_tooltip_column(STORAGE_ROW_TOOLTIP)
2009-03-10 04:17:09 +08:00
Convert to use GTK3 and GObject Introspection bindings Switch over to use GObject introspection bindings for all python modules related to GObject/GTK3/etc. It is not possible to mix and match old pyggtk/pygobject manual bindings with new introspection based bindings so it must be all changed in one go. Imports like import gtk Change to from gi.repository import Gtk The vmmGObject class is changed to always inherit from GObject.GObject There is no compelling reason to avoid a GObject dep for the virt-manager TUI & it horribly messed up the code. Signal declarations are changed from vmmChooseCD.signal_new(vmmChooseCD, "cdrom-chosen", [object, str]) To __gsignals__ = { "cdrom-chosen": (GObject.SignalFlags.RUN_FIRST, None, [object, str]) } which is required by new GObject bindings Most of the rest of the change is simply dealing with renamed constants / classes. Alot of legacy compat code was removed - ie helpers which check to see if certain GTK2 methods are available are no longer required since we're mandating GTK3 only. The event loop is replaced with LibvirtGLib's event loop. Still todo - Rip out all DBus stuff & make vmmEngine class inherit GtkApplication which provides unique support & DBus method handling - Switch to use LibvirtGConfig & LibvirtGObject for libvirt interaction - Possibly switch to Python 3 too ? - Figure out why GNOME keyring is missing Introspection support My suggestion is that the standalone GIT repo for virt-install only live on as a support branch for legacy platforms. A stable-0.9 branch of virt-manager can be kept for legacy PyGtk2 based virt-manager releases. The virt-manager master branch should exclusively use GObject inspection and ideally Python3 and contain both the virt-manager and virt-install codebases in one since they are intimately related to each other & using separate GIT repos has needlessly complicated life for everyone. crobinso: Some locking fixes Misc cleanups and dropping now-useless code Fix dbus usage Fix graph cell renderer regression Fix a couple tooltip issues
2012-05-14 21:24:56 +08:00
confirmCol = Gtk.TreeViewColumn()
pathCol = Gtk.TreeViewColumn(_("Storage Path"))
targetCol = Gtk.TreeViewColumn(_("Target"))
infoCol = Gtk.TreeViewColumn()
2009-03-10 04:17:09 +08:00
storage_list.append_column(confirmCol)
storage_list.append_column(pathCol)
storage_list.append_column(targetCol)
storage_list.append_column(infoCol)
Convert to use GTK3 and GObject Introspection bindings Switch over to use GObject introspection bindings for all python modules related to GObject/GTK3/etc. It is not possible to mix and match old pyggtk/pygobject manual bindings with new introspection based bindings so it must be all changed in one go. Imports like import gtk Change to from gi.repository import Gtk The vmmGObject class is changed to always inherit from GObject.GObject There is no compelling reason to avoid a GObject dep for the virt-manager TUI & it horribly messed up the code. Signal declarations are changed from vmmChooseCD.signal_new(vmmChooseCD, "cdrom-chosen", [object, str]) To __gsignals__ = { "cdrom-chosen": (GObject.SignalFlags.RUN_FIRST, None, [object, str]) } which is required by new GObject bindings Most of the rest of the change is simply dealing with renamed constants / classes. Alot of legacy compat code was removed - ie helpers which check to see if certain GTK2 methods are available are no longer required since we're mandating GTK3 only. The event loop is replaced with LibvirtGLib's event loop. Still todo - Rip out all DBus stuff & make vmmEngine class inherit GtkApplication which provides unique support & DBus method handling - Switch to use LibvirtGConfig & LibvirtGObject for libvirt interaction - Possibly switch to Python 3 too ? - Figure out why GNOME keyring is missing Introspection support My suggestion is that the standalone GIT repo for virt-install only live on as a support branch for legacy platforms. A stable-0.9 branch of virt-manager can be kept for legacy PyGtk2 based virt-manager releases. The virt-manager master branch should exclusively use GObject inspection and ideally Python3 and contain both the virt-manager and virt-install codebases in one since they are intimately related to each other & using separate GIT repos has needlessly complicated life for everyone. crobinso: Some locking fixes Misc cleanups and dropping now-useless code Fix dbus usage Fix graph cell renderer regression Fix a couple tooltip issues
2012-05-14 21:24:56 +08:00
chkbox = Gtk.CellRendererToggle()
2009-03-10 04:17:09 +08:00
chkbox.connect('toggled', storage_item_toggled, storage_list)
confirmCol.pack_start(chkbox, False)
confirmCol.add_attribute(chkbox, 'active', STORAGE_ROW_CONFIRM)
confirmCol.add_attribute(chkbox, 'inconsistent',
STORAGE_ROW_CANT_DELETE)
confirmCol.set_sort_column_id(STORAGE_ROW_CANT_DELETE)
Convert to use GTK3 and GObject Introspection bindings Switch over to use GObject introspection bindings for all python modules related to GObject/GTK3/etc. It is not possible to mix and match old pyggtk/pygobject manual bindings with new introspection based bindings so it must be all changed in one go. Imports like import gtk Change to from gi.repository import Gtk The vmmGObject class is changed to always inherit from GObject.GObject There is no compelling reason to avoid a GObject dep for the virt-manager TUI & it horribly messed up the code. Signal declarations are changed from vmmChooseCD.signal_new(vmmChooseCD, "cdrom-chosen", [object, str]) To __gsignals__ = { "cdrom-chosen": (GObject.SignalFlags.RUN_FIRST, None, [object, str]) } which is required by new GObject bindings Most of the rest of the change is simply dealing with renamed constants / classes. Alot of legacy compat code was removed - ie helpers which check to see if certain GTK2 methods are available are no longer required since we're mandating GTK3 only. The event loop is replaced with LibvirtGLib's event loop. Still todo - Rip out all DBus stuff & make vmmEngine class inherit GtkApplication which provides unique support & DBus method handling - Switch to use LibvirtGConfig & LibvirtGObject for libvirt interaction - Possibly switch to Python 3 too ? - Figure out why GNOME keyring is missing Introspection support My suggestion is that the standalone GIT repo for virt-install only live on as a support branch for legacy platforms. A stable-0.9 branch of virt-manager can be kept for legacy PyGtk2 based virt-manager releases. The virt-manager master branch should exclusively use GObject inspection and ideally Python3 and contain both the virt-manager and virt-install codebases in one since they are intimately related to each other & using separate GIT repos has needlessly complicated life for everyone. crobinso: Some locking fixes Misc cleanups and dropping now-useless code Fix dbus usage Fix graph cell renderer regression Fix a couple tooltip issues
2012-05-14 21:24:56 +08:00
path_txt = Gtk.CellRendererText()
2009-03-10 04:17:09 +08:00
pathCol.pack_start(path_txt, True)
pathCol.add_attribute(path_txt, 'text', STORAGE_ROW_PATH)
pathCol.set_sort_column_id(STORAGE_ROW_PATH)
Convert to use GTK3 and GObject Introspection bindings Switch over to use GObject introspection bindings for all python modules related to GObject/GTK3/etc. It is not possible to mix and match old pyggtk/pygobject manual bindings with new introspection based bindings so it must be all changed in one go. Imports like import gtk Change to from gi.repository import Gtk The vmmGObject class is changed to always inherit from GObject.GObject There is no compelling reason to avoid a GObject dep for the virt-manager TUI & it horribly messed up the code. Signal declarations are changed from vmmChooseCD.signal_new(vmmChooseCD, "cdrom-chosen", [object, str]) To __gsignals__ = { "cdrom-chosen": (GObject.SignalFlags.RUN_FIRST, None, [object, str]) } which is required by new GObject bindings Most of the rest of the change is simply dealing with renamed constants / classes. Alot of legacy compat code was removed - ie helpers which check to see if certain GTK2 methods are available are no longer required since we're mandating GTK3 only. The event loop is replaced with LibvirtGLib's event loop. Still todo - Rip out all DBus stuff & make vmmEngine class inherit GtkApplication which provides unique support & DBus method handling - Switch to use LibvirtGConfig & LibvirtGObject for libvirt interaction - Possibly switch to Python 3 too ? - Figure out why GNOME keyring is missing Introspection support My suggestion is that the standalone GIT repo for virt-install only live on as a support branch for legacy platforms. A stable-0.9 branch of virt-manager can be kept for legacy PyGtk2 based virt-manager releases. The virt-manager master branch should exclusively use GObject inspection and ideally Python3 and contain both the virt-manager and virt-install codebases in one since they are intimately related to each other & using separate GIT repos has needlessly complicated life for everyone. crobinso: Some locking fixes Misc cleanups and dropping now-useless code Fix dbus usage Fix graph cell renderer regression Fix a couple tooltip issues
2012-05-14 21:24:56 +08:00
target_txt = Gtk.CellRendererText()
2009-03-10 04:17:09 +08:00
targetCol.pack_start(target_txt, False)
targetCol.add_attribute(target_txt, 'text', STORAGE_ROW_TARGET)
targetCol.set_sort_column_id(STORAGE_ROW_TARGET)
Convert to use GTK3 and GObject Introspection bindings Switch over to use GObject introspection bindings for all python modules related to GObject/GTK3/etc. It is not possible to mix and match old pyggtk/pygobject manual bindings with new introspection based bindings so it must be all changed in one go. Imports like import gtk Change to from gi.repository import Gtk The vmmGObject class is changed to always inherit from GObject.GObject There is no compelling reason to avoid a GObject dep for the virt-manager TUI & it horribly messed up the code. Signal declarations are changed from vmmChooseCD.signal_new(vmmChooseCD, "cdrom-chosen", [object, str]) To __gsignals__ = { "cdrom-chosen": (GObject.SignalFlags.RUN_FIRST, None, [object, str]) } which is required by new GObject bindings Most of the rest of the change is simply dealing with renamed constants / classes. Alot of legacy compat code was removed - ie helpers which check to see if certain GTK2 methods are available are no longer required since we're mandating GTK3 only. The event loop is replaced with LibvirtGLib's event loop. Still todo - Rip out all DBus stuff & make vmmEngine class inherit GtkApplication which provides unique support & DBus method handling - Switch to use LibvirtGConfig & LibvirtGObject for libvirt interaction - Possibly switch to Python 3 too ? - Figure out why GNOME keyring is missing Introspection support My suggestion is that the standalone GIT repo for virt-install only live on as a support branch for legacy platforms. A stable-0.9 branch of virt-manager can be kept for legacy PyGtk2 based virt-manager releases. The virt-manager master branch should exclusively use GObject inspection and ideally Python3 and contain both the virt-manager and virt-install codebases in one since they are intimately related to each other & using separate GIT repos has needlessly complicated life for everyone. crobinso: Some locking fixes Misc cleanups and dropping now-useless code Fix dbus usage Fix graph cell renderer regression Fix a couple tooltip issues
2012-05-14 21:24:56 +08:00
info_img = Gtk.CellRendererPixbuf()
2009-03-10 04:17:09 +08:00
infoCol.pack_start(info_img, False)
infoCol.add_attribute(info_img, 'visible', STORAGE_ROW_ICON_SHOW)
infoCol.add_attribute(info_img, 'stock-id', STORAGE_ROW_ICON)
infoCol.add_attribute(info_img, 'stock-size', STORAGE_ROW_ICON_SIZE)
infoCol.set_sort_column_id(STORAGE_ROW_ICON)
2009-03-10 04:17:09 +08:00
def storage_item_toggled(src, index, storage_list):
active = src.get_active()
model = storage_list.get_model()
model[index][STORAGE_ROW_CONFIRM] = not active
2009-03-10 04:17:09 +08:00
def can_delete(conn, vol, path):
"""Is the passed path even deleteable"""
ret = True
msg = None
if vol:
# Managed storage
if (vol.get_parent_pool().get_type() ==
virtinst.StoragePool.TYPE_ISCSI):
2009-03-10 04:17:09 +08:00
msg = _("Cannot delete iscsi share.")
else:
if conn.is_remote():
msg = _("Cannot delete unmanaged remote storage.")
elif not os.path.exists(path):
msg = _("Path does not exist.")
elif not os.access(os.path.dirname(path), os.W_OK):
msg = _("No write access to parent directory.")
elif stat.S_ISBLK(os.stat(path)[stat.ST_MODE]):
msg = _("Cannot delete unmanaged block device.")
if msg:
ret = False
return (ret, msg)
2009-03-10 04:17:09 +08:00
def do_we_default(conn, vm_name, vol, path, ro, shared):
""" Returns (do we delete by default?, info string if not)"""
info = ""
def append_str(str1, str2, delim="\n"):
if not str2:
return str1
if str1:
str1 += delim
str1 += str2
return str1
if ro:
info = append_str(info, _("Storage is read-only."))
elif not vol and not os.access(path, os.W_OK):
info = append_str(info, _("No write access to path."))
if shared:
info = append_str(info, _("Storage is marked as shareable."))
try:
names = virtinst.VirtualDisk.path_in_use_by(conn.get_backend(), path)
2009-03-10 04:17:09 +08:00
if len(names) > 1:
namestr = ""
names.remove(vm_name)
for name in names:
namestr = append_str(namestr, name, delim="\n- ")
info = append_str(info, _("Storage is in use by the following "
"virtual machines:\n- %s " % namestr))
except Exception, e:
logging.exception("Failed checking disk conflict: %s", str(e))
2009-03-10 04:17:09 +08:00
return (not info, info)