408
462
path = util.browse_local(src.window.get_widget("vmm-details"),
409
463
_("Save Virtual Machine"),
410
self.config.get_default_save_dir(con),
411
dialog_type=gtk.FILE_CHOOSER_ACTION_SAVE)
414
progWin = vmmAsyncJob(self.config, self._save_callback,
416
_("Saving Virtual Machine"))
419
if self._save_callback_info != []:
420
self.err.show_err(_("Error saving domain: %s") %
421
self._save_callback_info[0],
422
self._save_callback_info[1])
423
self._save_callback_info = []
425
def _save_callback(self, vm, file_to_save, ignore1=None):
465
dialog_type=gtk.FILE_CHOOSER_ACTION_SAVE,
466
browse_reason=self.config.CONFIG_DIR_SAVE)
471
progWin = vmmAsyncJob(self.config, self._save_callback, [vm, path],
472
_("Saving Virtual Machine"))
474
error, details = progWin.get_error()
476
if error is not None:
477
self.err.show_err(_("Error saving domain: %s") % error, details)
479
def _save_callback(self, vm, file_to_save, asyncjob):
427
481
vm.save(file_to_save)
428
482
except Exception, e:
429
self._save_callback_info = [str(e), \
430
"".join(traceback.format_exc())]
483
asyncjob.set_error(str(e), "".join(traceback.format_exc()))
432
485
def destroy_domain(self, src, uri, uuid):
433
con = self.get_connection(uri, False)
434
vm = con.get_vm(uuid)
486
conn = self._lookup_connection(uri)
487
vm = conn.get_vm(uuid)
435
488
status = vm.status()
436
490
if status in [ libvirt.VIR_DOMAIN_SHUTDOWN,
437
491
libvirt.VIR_DOMAIN_SHUTOFF ]:
438
logging.warning("Destroy requested, but machine is shutdown / shutoff")
440
resp = self.err.yes_no(text1=_("About to poweroff virtual machine %s" % vm.get_name()), text2=_("This will immediately poweroff the VM without shutting down the OS and may cause data loss. Are you sure?"))
442
logging.debug("Destroying vm '%s'." % vm.get_name())
446
self.err.show_err(_("Error shutting down domain: %s" % str(e)), "".join(traceback.format_exc()))
492
logging.warning("Destroy requested, but machine is "
496
resp = self.err.yes_no(text1=_("About to poweroff virtual "
497
"machine %s" % vm.get_name()),
498
text2=_("This will immediately poweroff the VM "
499
"without shutting down the OS and may "
500
"cause data loss. Are you sure?"))
504
logging.debug("Destroying vm '%s'." % vm.get_name())
508
self.err.show_err(_("Error shutting down domain: %s" % str(e)),
509
"".join(traceback.format_exc()))
448
511
def suspend_domain(self, src, uri, uuid):
449
con = self.get_connection(uri, False)
450
vm = con.get_vm(uuid)
512
conn = self._lookup_connection(uri)
513
vm = conn.get_vm(uuid)
451
514
status = vm.status()
452
if status in [ libvirt.VIR_DOMAIN_SHUTDOWN, \
453
libvirt.VIR_DOMAIN_SHUTOFF, \
516
if status in [ libvirt.VIR_DOMAIN_SHUTDOWN,
517
libvirt.VIR_DOMAIN_SHUTOFF,
454
518
libvirt.VIR_DOMAIN_CRASHED ]:
455
logging.warning("Pause requested, but machine is shutdown / shutoff")
519
logging.warning("Pause requested, but machine is shutdown/shutoff")
456
522
elif status in [ libvirt.VIR_DOMAIN_PAUSED ]:
457
523
logging.warning("Pause requested, but machine is already paused")
459
logging.debug("Pausing vm '%s'." % vm.get_name())
463
self.err.show_err(_("Error pausing domain: %s" % str(e)),
464
"".join(traceback.format_exc()))
526
logging.debug("Pausing vm '%s'." % vm.get_name())
530
self.err.show_err(_("Error pausing domain: %s" % str(e)),
531
"".join(traceback.format_exc()))
466
533
def resume_domain(self, src, uri, uuid):
467
con = self.get_connection(uri, False)
468
vm = con.get_vm(uuid)
534
conn = self._lookup_connection(uri)
535
vm = conn.get_vm(uuid)
469
536
status = vm.status()
470
if status in [ libvirt.VIR_DOMAIN_SHUTDOWN, \
471
libvirt.VIR_DOMAIN_SHUTOFF, \
538
if status in [ libvirt.VIR_DOMAIN_SHUTDOWN,
539
libvirt.VIR_DOMAIN_SHUTOFF,
472
540
libvirt.VIR_DOMAIN_CRASHED ]:
473
logging.warning("Resume requested, but machine is shutdown / shutoff")
474
elif status in [ libvirt.VIR_DOMAIN_PAUSED ]:
475
logging.debug("Unpausing vm '%s'." % vm.get_name())
479
self.err.show_err(_("Error unpausing domain: %s" % str(e)),
480
"".join(traceback.format_exc()))
482
logging.warning("Resume requested, but machine is already running")
541
logging.warning("Resume requested, but machine is "
545
elif status not in [ libvirt.VIR_DOMAIN_PAUSED ]:
546
logging.warning("Unpause requested, but machine is not paused.")
549
logging.debug("Unpausing vm '%s'." % vm.get_name())
553
self.err.show_err(_("Error unpausing domain: %s" % str(e)),
554
"".join(traceback.format_exc()))
484
556
def run_domain(self, src, uri, uuid):
485
con = self.get_connection(uri, False)
486
vm = con.get_vm(uuid)
557
conn = self._lookup_connection(uri)
558
vm = conn.get_vm(uuid)
487
559
status = vm.status()
488
561
if status != libvirt.VIR_DOMAIN_SHUTOFF:
489
562
logging.warning("Run requested, but domain isn't shutoff.")
491
logging.debug("Starting vm '%s'." % vm.get_name())
495
self.err.show_err(_("Error starting domain: %s" % str(e)),
496
"".join(traceback.format_exc()))
565
logging.debug("Starting vm '%s'." % vm.get_name())
569
self.err.show_err(_("Error starting domain: %s" % str(e)),
570
"".join(traceback.format_exc()))
498
572
def shutdown_domain(self, src, uri, uuid):
499
con = self.get_connection(uri, False)
500
vm = con.get_vm(uuid)
573
conn = self._lookup_connection(uri)
574
vm = conn.get_vm(uuid)
501
575
status = vm.status()
502
if not(status in [ libvirt.VIR_DOMAIN_SHUTDOWN, \
503
libvirt.VIR_DOMAIN_SHUTOFF, \
504
libvirt.VIR_DOMAIN_CRASHED ]):
505
logging.debug("Shutting down vm '%s'." % vm.get_name())
509
self.err.show_err(_("Error shutting down domain: %s" % str(e)),
510
"".join(traceback.format_exc()))
512
logging.warning("Shut down requested, but the virtual machine is already shutting down / powered off")
577
if status in [ libvirt.VIR_DOMAIN_SHUTDOWN,
578
libvirt.VIR_DOMAIN_SHUTOFF,
579
libvirt.VIR_DOMAIN_CRASHED ]:
580
logging.warning("Shut down requested, but the virtual machine is "
581
"already shutting down / powered off")
584
logging.debug("Shutting down vm '%s'." % vm.get_name())
588
self.err.show_err(_("Error shutting down domain: %s" % str(e)),
589
"".join(traceback.format_exc()))
514
591
def reboot_domain(self, src, uri, uuid):
515
con = self.get_connection(uri, False)
516
vm = con.get_vm(uuid)
592
conn = self._lookup_connection(uri)
593
vm = conn.get_vm(uuid)
517
594
status = vm.status()
518
if not(status in [ libvirt.VIR_DOMAIN_SHUTDOWN, \
519
libvirt.VIR_DOMAIN_SHUTOFF, \
520
libvirt.VIR_DOMAIN_CRASHED ]):
521
logging.debug("Rebooting vm '%s'." % vm.get_name())
525
self.err.show_err(_("Error shutting down domain: %s" % str(e)),
526
"".join(traceback.format_exc()))
528
logging.warning("Reboot requested, but machine is already shutting down / shutoff")
530
def migrate_domain(self, uri, uuid, desthost):
532
for key in self.connections.keys():
533
if self.get_connection(key).get_hostname() == desthost:
538
logging.debug("Could not find dest uri for migrate hostname: %s"
596
if status in [ libvirt.VIR_DOMAIN_SHUTDOWN,
597
libvirt.VIR_DOMAIN_SHUTOFF,
598
libvirt.VIR_DOMAIN_CRASHED ]:
599
logging.warning("Reboot requested, but machine is already "
600
"shutting down / shutoff")
542
conn = self.get_connection(uri, False)
603
logging.debug("Rebooting vm '%s'." % vm.get_name())
607
self.err.show_err(_("Error shutting down domain: %s" % str(e)),
608
"".join(traceback.format_exc()))
610
def migrate_domain(self, uri, uuid, desturi):
611
conn = self._lookup_connection(uri)
543
612
vm = conn.get_vm(uuid)
544
destconn = self.get_connection(desturi, False)
545
resp = self.err.yes_no(_("Are you sure you want to migrate %s from %s to %s?") % \
546
(vm.get_name(), conn.get_hostname(), destconn.get_hostname()))
548
migrate_progress = None
613
destconn = self._lookup_connection(desturi)
615
resp = self.err.yes_no(_("Are you sure you want to migrate %s from "
617
(vm.get_name(), conn.get_hostname(),
618
destconn.get_hostname()))
622
progWin = vmmAsyncJob(self.config, self._async_migrate, [vm, destconn],
623
title=_("Migrating VM '%s'" % vm.get_name()),
624
text=(_("Migrating VM '%s' from %s to %s. "
625
"This may take awhile.") %
626
(vm.get_name(), conn.get_hostname(),
627
destconn.get_hostname())))
629
error, details = progWin.get_error()
632
self.err.show_err(error, details)
634
self.windowManager.conn_refresh_resources(vm.get_connection())
635
self.windowManager.conn_refresh_resources(destconn)
637
def _async_migrate(self, origvm, origdconn, asyncjob):
550
# show progress dialog
551
migrate_progress = self.get_migrate_progress(vm.get_name(), conn.get_short_hostname(), destconn.get_short_hostname())
552
migrate_progress.show()
553
while gtk.events_pending():
555
# call virDomainMigrate
557
# close progress dialog
558
migrate_progress.destroy()
641
ignore = vmmCreateMeter(asyncjob)
643
srcconn = util.dup_conn(self.config, origvm.get_connection(),
644
return_conn_class=True)
645
dstconn = util.dup_conn(self.config, origdconn,
646
return_conn_class=True)
648
vminst = srcconn.vmm.lookupByName(origvm.get_name())
649
vm = vmmDomain(self.config, srcconn, vminst, vminst.UUID())
651
logging.debug("Migrating vm=%s from %s to %s", vm.get_name(),
652
srcconn.get_uri(), dstconn.get_uri())
559
654
except Exception, e:
560
migrate_progress.destroy()
561
self.err.show_err(_("Error migrating domain: %s") % str(e),
562
"".join(traceback.format_exc()))
563
self.windowManager.conn_refresh_resources(conn)
564
self.windowManager.conn_refresh_resources(destconn)
566
def get_migrate_progress(self, vmname, hostname, desthostname):
567
migrate_progress = None
568
migrate_progress = gtk.MessageDialog(None, \
569
gtk.DIALOG_DESTROY_WITH_PARENT, \
572
_("%s will be migrated from %s to %s." % \
573
(vmname, hostname, desthostname)))
574
migrate_progress.set_title(" ")
575
return migrate_progress
577
def populate_migrate_menu(self, menu, migrate_func):
578
conns = self.get_available_migrate_hostnames()
655
errinfo = (str(e), ("Unable to migrate guest:\n %s" %
656
"".join(traceback.format_exc())))
659
asyncjob.set_error(errinfo[0], errinfo[1])
662
def populate_migrate_menu(self, menu, migrate_func, vm):
663
conns = self.get_available_migrate_hostnames(vm)
581
666
for item in menu:
582
667
menu.remove(item)
584
669
for ignore, val_list in conns.items():
585
can_migrate, label, tooltip = val_list
670
can_migrate, label, tooltip, uri = val_list
586
671
mitem = gtk.ImageMenuItem(label)
587
672
mitem.set_sensitive(can_migrate)
588
mitem.connect("activate", migrate_func)
673
mitem.connect("activate", migrate_func, uri)
590
675
util.tooltip_wrapper(mitem, tooltip)