Have migration use typical progress dialog.

This commit is contained in:
Cole Robinson 2009-04-03 16:06:46 -04:00
parent 3b6c2ffe1f
commit 368dcfe05a
2 changed files with 60 additions and 33 deletions

View File

@ -1347,10 +1347,18 @@ class vmmDomain(gobject.GObject):
self._disk_io = self._sample_disk_io_dummy self._disk_io = self._sample_disk_io_dummy
def migrate(self, dictcon): def migrate(self, destcon):
flags = 0 flags = 0
if self.lastStatus == libvirt.VIR_DOMAIN_RUNNING: if self.lastStatus == libvirt.VIR_DOMAIN_RUNNING:
flags = libvirt.VIR_MIGRATE_LIVE flags = libvirt.VIR_MIGRATE_LIVE
self.vm.migrate(self.connection.vmm, flags, None, dictcon.get_short_hostname(), 0)
if self.get_connection().get_driver().lower() == "xen":
# FIXME: these required? need to test this
uri = destcon.get_short_hostname()
conn = self.get_connection().vmm
else:
conn = destcon.vmm
uri = None
self.vm.migrate(conn, flags, None, uri, 0)
gobject.type_register(vmmDomain) gobject.type_register(vmmDomain)

View File

@ -29,6 +29,8 @@ import traceback
from virtManager.about import vmmAbout from virtManager.about import vmmAbout
from virtManager.connect import vmmConnect from virtManager.connect import vmmConnect
from virtManager.connection import vmmConnection from virtManager.connection import vmmConnection
from virtManager.createmeter import vmmCreateMeter
from virtManager.domain import vmmDomain
from virtManager.preferences import vmmPreferences from virtManager.preferences import vmmPreferences
from virtManager.manager import vmmManager from virtManager.manager import vmmManager
from virtManager.details import vmmDetails from virtManager.details import vmmDetails
@ -490,7 +492,7 @@ class vmmEngine(gobject.GObject):
except Exception, e: except Exception, e:
self.err.show_err(_("Error starting domain: %s" % str(e)), self.err.show_err(_("Error starting domain: %s" % str(e)),
"".join(traceback.format_exc())) "".join(traceback.format_exc()))
def shutdown_domain(self, src, uri, uuid): def shutdown_domain(self, src, uri, uuid):
con = self.get_connection(uri, False) con = self.get_connection(uri, False)
vm = con.get_vm(uuid) vm = con.get_vm(uuid)
@ -538,37 +540,54 @@ class vmmEngine(gobject.GObject):
conn = self.get_connection(uri, False) conn = self.get_connection(uri, False)
vm = conn.get_vm(uuid) vm = conn.get_vm(uuid)
destconn = self.get_connection(desturi, False) destconn = self.get_connection(desturi, False)
resp = self.err.yes_no(_("Are you sure you want to migrate %s from %s to %s?") % \ resp = self.err.yes_no(_("Are you sure you want to migrate %s from "
(vm.get_name(), conn.get_hostname(), destconn.get_hostname())) "%s to %s?") %
if resp: (vm.get_name(), conn.get_hostname(),
migrate_progress = None destconn.get_hostname()))
try: if not resp:
# show progress dialog return
migrate_progress = self.get_migrate_progress(vm.get_name(), conn.get_short_hostname(), destconn.get_short_hostname())
migrate_progress.show() progWin = vmmAsyncJob(self.config, self._async_migrate, [vm, destconn],
while gtk.events_pending(): title=_("Migrating VM '%s'" % vm.get_name()),
gtk.main_iteration() text=(_("Migrating VM '%s' from %s to %s. "
# call virDomainMigrate "This may take awhile.") %
vm.migrate(destconn) (vm.get_name(), conn.get_hostname(),
# close progress dialog destconn.get_hostname())))
migrate_progress.destroy() progWin.run()
except Exception, e: error, details = progWin.get_error()
migrate_progress.destroy()
self.err.show_err(_("Error migrating domain: %s") % str(e), if error:
"".join(traceback.format_exc())) self.err.show_err(error, details)
self.windowManager.conn_refresh_resources(conn)
self.windowManager.conn_refresh_resources(destconn) self.windowManager.conn_refresh_resources(vm.get_connection())
self.windowManager.conn_refresh_resources(destconn)
def _async_migrate(self, origvm, origdconn, asyncjob):
errinfo = None
try:
try:
ignore = vmmCreateMeter(asyncjob)
srcconn = util.dup_conn(self.config, origvm.get_connection(),
return_conn_class=True)
dstconn = util.dup_conn(self.config, origdconn,
return_conn_class=True)
vminst = srcconn.vmm.lookupByName(origvm.get_name())
vm = vmmDomain(self.config, srcconn, vminst, vminst.UUID())
logging.debug("Migrating vm=%s from %s to %s", vm.get_name(),
srcconn.get_uri(), dstconn.get_uri())
#vm.migrate(dstconn)
import time
time.sleep(5)
except Exception, e:
errinfo = (str(e), ("Unable to migrate guest:\n %s" %
"".join(traceback.format_exc())))
finally:
if errinfo:
asyncjob.set_error(errinfo[0], errinfo[1])
def get_migrate_progress(self, vmname, hostname, desthostname):
migrate_progress = None
migrate_progress = gtk.MessageDialog(None, \
gtk.DIALOG_DESTROY_WITH_PARENT, \
gtk.MESSAGE_INFO, \
gtk.BUTTONS_NONE, \
_("%s will be migrated from %s to %s." % \
(vmname, hostname, desthostname)))
migrate_progress.set_title(" ")
return migrate_progress
def populate_migrate_menu(self, menu, migrate_func, vm): def populate_migrate_menu(self, menu, migrate_func, vm):
conns = self.get_available_migrate_hostnames(vm) conns = self.get_available_migrate_hostnames(vm)