Make all start/stop/delete operations run async

Applies for domains, nets, pools, volumes, interfaces. Domain pause, unpause
save and restore all run async as well.
This commit is contained in:
Cole Robinson 2011-04-15 15:23:13 -04:00
parent 7e211aa151
commit 450f88cf66
2 changed files with 70 additions and 105 deletions

View File

@ -920,7 +920,6 @@ class vmmEngine(vmmGObject):
newvm.save(file_to_save, meter=meter)
def _do_restore_domain(self, src, uri):
conn = self._lookup_connection(uri)
if conn.is_remote():
@ -936,22 +935,12 @@ class vmmEngine(vmmGObject):
if not path:
return
progWin = vmmAsyncJob(self._restore_saved_callback,
[path, conn],
_("Restoring Virtual Machine"),
_("Restoring virtual machine memory from disk"),
src.topwin)
error, details = progWin.run()
def cb():
newconn = util.dup_conn(conn)
newconn.restore(path)
if error is not None:
error = _("Error restoring domain: %s") % error
src.err.show_err(error,
details=details)
def _restore_saved_callback(self, asyncjob, file_to_load, conn):
ignore = asyncjob
newconn = util.dup_conn(conn)
newconn.restore(file_to_load)
vmmAsyncJob.simple_async_noshow(cb, [], src,
_("Error restoring domain"))
def _do_destroy_domain(self, src, uri, uuid):
conn = self._lookup_connection(uri)
@ -966,10 +955,8 @@ class vmmEngine(vmmGObject):
return
logging.debug("Destroying vm '%s'." % vm.get_name())
try:
vm.destroy()
except Exception, e:
src.err.show_err(_("Error shutting down domain: %s" % str(e)))
vmmAsyncJob.simple_async_noshow(vm.destroy, [], src,
_("Error shutting down domain"))
def _do_suspend_domain(self, src, uri, uuid):
conn = self._lookup_connection(uri)
@ -982,20 +969,16 @@ class vmmEngine(vmmGObject):
return
logging.debug("Pausing vm '%s'." % vm.get_name())
try:
vm.suspend()
except Exception, e:
src.err.show_err(_("Error pausing domain: %s" % str(e)))
vmmAsyncJob.simple_async_noshow(vm.suspend, [], src,
_("Error pausing domain"))
def _do_resume_domain(self, src, uri, uuid):
conn = self._lookup_connection(uri)
vm = conn.get_vm(uuid)
logging.debug("Unpausing vm '%s'." % vm.get_name())
try:
vm.resume()
except Exception, e:
src.err.show_err(_("Error unpausing domain: %s" % str(e)))
vmmAsyncJob.simple_async_noshow(vm.resume, [], src,
_("Error unpausing domain"))
def _do_run_domain(self, src, uri, uuid):
conn = self._lookup_connection(uri)
@ -1029,10 +1012,8 @@ class vmmEngine(vmmGObject):
return
logging.debug("Shutting down vm '%s'." % vm.get_name())
try:
vm.shutdown()
except Exception, e:
src.err.show_err(_("Error shutting down domain: %s" % str(e)))
vmmAsyncJob.simple_async_noshow(vm.shutdown, [], src,
_("Error shutting down domain"))
def _do_reboot_domain(self, src, uri, uuid):
conn = self._lookup_connection(uri)
@ -1045,28 +1026,32 @@ class vmmEngine(vmmGObject):
return
logging.debug("Rebooting vm '%s'." % vm.get_name())
no_support = False
reboot_err = None
try:
vm.reboot()
except Exception, reboot_err:
no_support = virtinst.support.is_error_nosupport(reboot_err)
def reboot_cb():
no_support = False
reboot_err = None
try:
vm.reboot()
except Exception, reboot_err:
no_support = virtinst.support.is_error_nosupport(reboot_err)
if not no_support:
src.err.show_err(_("Error rebooting domain: %s" %
str(reboot_err)))
if not no_support:
return
# Reboot isn't supported. Let's try to emulate it
logging.debug("Hypervisor doesn't support reboot, let's fake it")
try:
vm.manual_reboot()
except:
logging.exception("Could not fake a reboot")
# Raise the original error message
src.err.show_err(_("Error rebooting domain: %s" %
str(reboot_err)))
if not no_support:
return
# Reboot isn't supported. Let's try to emulate it
logging.debug("Hypervisor doesn't support reboot, let's fake it")
try:
vm.manual_reboot()
except:
logging.exception("Could not fake a reboot")
# Raise the original error message
src.err.show_err(_("Error rebooting domain: %s" %
str(reboot_err)))
vmmAsyncJob.simple_async_noshow(reboot_cb, [], src, "")
vmmGObject.type_register(vmmEngine)

View File

@ -28,6 +28,7 @@ from virtinst import Interface
from virtManager import uihelpers
from virtManager import util
from virtManager.asyncjob import vmmAsyncJob
from virtManager.connection import vmmConnection
from virtManager.createnet import vmmCreateNetwork
from virtManager.createpool import vmmCreatePool
@ -432,10 +433,8 @@ class vmmHost(vmmGObjectUI):
return
logging.debug("Deleting network '%s'" % net.get_name())
try:
net.delete()
except Exception, e:
self.err.show_err(_("Error deleting network: %s") % str(e))
vmmAsyncJob.simple_async_noshow(net.delete, [], self,
_("Error deleting network '%s'") % net.get_name())
def start_network(self, src_ignore):
net = self.current_network()
@ -443,10 +442,8 @@ class vmmHost(vmmGObjectUI):
return
logging.debug("Starting network '%s'" % net.get_name())
try:
net.start()
except Exception, e:
self.err.show_err(_("Error starting network: %s") % str(e))
vmmAsyncJob.simple_async_noshow(net.start, [], self,
_("Error starting network '%s'") % net.get_name())
def stop_network(self, src_ignore):
net = self.current_network()
@ -454,10 +451,8 @@ class vmmHost(vmmGObjectUI):
return
logging.debug("Stopping network '%s'" % net.get_name())
try:
net.stop()
except Exception, e:
self.err.show_err(_("Error stopping network: %s") % str(e))
vmmAsyncJob.simple_async_noshow(net.stop, [], self,
_("Error stopping network '%s'") % net.get_name())
def add_network(self, src_ignore):
logging.debug("Launching 'Add Network'")
@ -475,7 +470,8 @@ class vmmHost(vmmGObjectUI):
logging.debug("Applying changes for network '%s'" % net.get_name())
try:
net.set_autostart(self.window.get_widget("net-autostart").get_active())
auto = self.window.get_widget("net-autostart").get_active()
net.set_autostart(auto)
except Exception, e:
self.err.show_err(_("Error setting net autostart: %s") % str(e))
return
@ -483,8 +479,8 @@ class vmmHost(vmmGObjectUI):
def net_autostart_changed(self, src_ignore):
auto = self.window.get_widget("net-autostart").get_active()
self.window.get_widget("net-autostart").set_label(auto and \
_("On Boot") or \
self.window.get_widget("net-autostart").set_label(auto and
_("On Boot") or
_("Never"))
self.window.get_widget("net-apply").set_sensitive(True)
@ -626,11 +622,8 @@ class vmmHost(vmmGObjectUI):
return
logging.debug("Stopping pool '%s'" % pool.get_name())
try:
pool.stop()
except Exception, e:
self.err.show_err(_("Error starting pool '%s': %s") %
(pool.get_name(), str(e)))
vmmAsyncJob.simple_async_noshow(pool.stop, [], self,
_("Error stopping pool '%s'") % pool.get_name())
def start_pool(self, src_ignore):
pool = self.current_pool()
@ -638,11 +631,8 @@ class vmmHost(vmmGObjectUI):
return
logging.debug("Starting pool '%s'" % pool.get_name())
try:
pool.start()
except Exception, e:
self.err.show_err(_("Error starting pool '%s': %s") %
(pool.get_name(), str(e)))
vmmAsyncJob.simple_async_noshow(pool.start, [], self,
_("Error starting pool '%s'") % pool.get_name())
def delete_pool(self, src_ignore):
pool = self.current_pool()
@ -655,23 +645,21 @@ class vmmHost(vmmGObjectUI):
return
logging.debug("Deleting pool '%s'" % pool.get_name())
try:
pool.delete()
except Exception, e:
self.err.show_err(_("Error deleting pool: %s") % str(e))
vmmAsyncJob.simple_async_noshow(pool.delete, [], self,
_("Error deleting pool '%s'") % pool.get_name())
def pool_refresh(self, src_ignore):
pool = self.current_pool()
if pool is None:
return
logging.debug("Refresh pool '%s'" % pool.get_name())
try:
def cb():
pool.refresh()
self.refresh_current_pool()
except Exception, e:
self.err.show_err(_("Error refreshing pool '%s': %s") %
(pool.get_name(), str(e)))
logging.debug("Refresh pool '%s'" % pool.get_name())
vmmAsyncJob.simple_async_noshow(cb, [], self,
_("Error refreshing pool '%s'") % pool.get_name())
def delete_vol(self, src_ignore):
vol = self.current_vol()
@ -683,14 +671,14 @@ class vmmHost(vmmGObjectUI):
if not result:
return
logging.debug("Deleting volume '%s'" % vol.get_name())
try:
def cb():
vol.delete()
self.refresh_current_pool()
except Exception, e:
self.err.show_err(_("Error deleting volume: %s") % str(e))
return
self.populate_storage_volumes()
self.populate_storage_volumes()
logging.debug("Deleting volume '%s'" % vol.get_name())
vmmAsyncJob.simple_async_noshow(cb, [], self,
_("Error refreshing volume '%s'") % vol.get_name())
def add_pool(self, src_ignore):
logging.debug("Launching 'Add Pool' wizard")
@ -913,11 +901,8 @@ class vmmHost(vmmGObjectUI):
return
logging.debug("Stopping interface '%s'" % interface.get_name())
try:
interface.stop()
except Exception, e:
self.err.show_err(_("Error stopping interface '%s': %s") %
(interface.get_name(), str(e)))
vmmAsyncJob.simple_async_noshow(interface.stop, [], self,
_("Error stopping interface '%s'") % interface.get_name())
def start_interface(self, src_ignore):
interface = self.current_interface()
@ -931,11 +916,8 @@ class vmmHost(vmmGObjectUI):
return
logging.debug("Starting interface '%s'" % interface.get_name())
try:
interface.start()
except Exception, e:
self.err.show_err(_("Error starting interface '%s': %s") %
(interface.get_name(), str(e)))
vmmAsyncJob.simple_async_noshow(interface.start, [], self,
_("Error starting interface '%s'") % interface.get_name())
def delete_interface(self, src_ignore):
interface = self.current_interface()
@ -949,10 +931,8 @@ class vmmHost(vmmGObjectUI):
return
logging.debug("Deleting interface '%s'" % interface.get_name())
try:
interface.delete()
except Exception, e:
self.err.show_err(_("Error deleting interface: %s") % str(e))
vmmAsyncJob.simple_async_noshow(interface.delete, [], self,
_("Error deleting interface '%s'") % interface.get_name())
def add_interface(self, src_ignore):
logging.debug("Launching 'Add Interface' wizard")