mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
Run domain startup asynchronously
Sometimes startup is actually a domain restore, which can take a while, so run it all async
This commit is contained in:
parent
252be3b009
commit
ec56a33f7c
@ -42,16 +42,38 @@ def cb_wrapper(callback, asyncjob, *args, **kwargs):
|
|||||||
try:
|
try:
|
||||||
callback(asyncjob, *args, **kwargs)
|
callback(asyncjob, *args, **kwargs)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
asyncjob.set_error(e, "".join(traceback.format_exc()))
|
asyncjob.set_error(str(e), "".join(traceback.format_exc()))
|
||||||
|
|
||||||
|
def _simple_async(callback, args, title, text, parent, errorintro,
|
||||||
|
show_progress):
|
||||||
|
asyncjob = vmmAsyncJob(callback, args, title, text,
|
||||||
|
show_progress=show_progress)
|
||||||
|
error, details = asyncjob.run()
|
||||||
|
if error is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
error = errorintro + ": " + error
|
||||||
|
parent.err.show_err(error, error + "\n\n" + details)
|
||||||
|
|
||||||
# Displays a progress bar while executing the "callback" method.
|
# Displays a progress bar while executing the "callback" method.
|
||||||
class vmmAsyncJob(vmmGObjectUI):
|
class vmmAsyncJob(vmmGObjectUI):
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def simple_async(callback, args, title, text, parent, errorintro):
|
||||||
|
_simple_async(callback, args, title, text, parent, errorintro, True)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def simple_async_noshow(callback, args, parent, errorintro):
|
||||||
|
_simple_async(callback, args, "", "", parent, errorintro, False)
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, callback, args, title, text,
|
def __init__(self, callback, args, title, text,
|
||||||
run_main=True, cancel_back=None, cancel_args=None):
|
run_main=True, show_progress=True,
|
||||||
|
cancel_back=None, cancel_args=None):
|
||||||
vmmGObjectUI.__init__(self, "vmm-progress.glade", "vmm-progress")
|
vmmGObjectUI.__init__(self, "vmm-progress.glade", "vmm-progress")
|
||||||
|
|
||||||
self.run_main = bool(run_main)
|
self.run_main = bool(run_main)
|
||||||
|
self.show_progress = bool(show_progress)
|
||||||
self.cancel_job = cancel_back
|
self.cancel_job = cancel_back
|
||||||
self.cancel_args = cancel_args or []
|
self.cancel_args = cancel_args or []
|
||||||
self.cancel_args = [self] + self.cancel_args
|
self.cancel_args = [self] + self.cancel_args
|
||||||
@ -82,7 +104,9 @@ class vmmAsyncJob(vmmGObjectUI):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
timer = util.safe_timeout_add(100, self.exit_if_necessary)
|
timer = util.safe_timeout_add(100, self.exit_if_necessary)
|
||||||
self.topwin.present()
|
|
||||||
|
if self.show_progress:
|
||||||
|
self.topwin.present()
|
||||||
|
|
||||||
if not self.cancel_job:
|
if not self.cancel_job:
|
||||||
self.topwin.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
self.topwin.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
||||||
|
@ -880,8 +880,8 @@ class vmmEngine(vmmGObject):
|
|||||||
|
|
||||||
progWin = vmmAsyncJob(self._restore_saved_callback,
|
progWin = vmmAsyncJob(self._restore_saved_callback,
|
||||||
[path, conn],
|
[path, conn],
|
||||||
_("Restoring Virtual Machine"),
|
_("Restoring domain"),
|
||||||
_("Restoring Virtual Machine"))
|
_("Restoring domain"))
|
||||||
error, details = progWin.run()
|
error, details = progWin.run()
|
||||||
|
|
||||||
if error is not None:
|
if error is not None:
|
||||||
@ -959,11 +959,24 @@ class vmmEngine(vmmGObject):
|
|||||||
vm = conn.get_vm(uuid)
|
vm = conn.get_vm(uuid)
|
||||||
|
|
||||||
logging.debug("Starting vm '%s'." % vm.get_name())
|
logging.debug("Starting vm '%s'." % vm.get_name())
|
||||||
try:
|
|
||||||
|
def asyncfunc(asyncjob):
|
||||||
|
ignore = asyncjob
|
||||||
vm.startup()
|
vm.startup()
|
||||||
except Exception, e:
|
|
||||||
src.err.show_err(_("Error starting domain: %s" % str(e)),
|
if vm.hasSavedImage():
|
||||||
"".join(traceback.format_exc()))
|
# VM will be restored, which can take some time, so show a
|
||||||
|
# progress dialog.
|
||||||
|
errorintro = _("Error restoring domain")
|
||||||
|
title = _("Restoring domain")
|
||||||
|
text = _("Restoring domain")
|
||||||
|
vmmAsyncJob.simple_async(asyncfunc, [], title, text, src,
|
||||||
|
errorintro)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Regular startup
|
||||||
|
errorintro = _("Error starting domain")
|
||||||
|
vmmAsyncJob.simple_async_noshow(asyncfunc, [], src, errorintro)
|
||||||
|
|
||||||
def _do_shutdown_domain(self, src, uri, uuid):
|
def _do_shutdown_domain(self, src, uri, uuid):
|
||||||
conn = self._lookup_connection(uri)
|
conn = self._lookup_connection(uri)
|
||||||
|
Loading…
Reference in New Issue
Block a user