2006-06-29 03:50:17 +08:00
|
|
|
#
|
2014-06-26 17:51:38 +08:00
|
|
|
# Copyright (C) 2006, 2013-2014 Red Hat, Inc.
|
2006-06-29 03:50:17 +08:00
|
|
|
# Copyright (C) 2006 Daniel P. Berrange <berrange@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
|
2007-11-21 00:12:20 +08:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA.
|
2006-06-29 03:50:17 +08:00
|
|
|
#
|
2007-11-21 00:12:20 +08:00
|
|
|
|
2006-09-26 06:41:47 +08:00
|
|
|
import logging
|
2013-07-13 10:10:16 +08:00
|
|
|
import re
|
2013-07-07 08:03:42 +08:00
|
|
|
import Queue
|
2009-07-12 09:23:16 +08:00
|
|
|
import threading
|
2014-04-16 22:32:52 +08:00
|
|
|
import traceback
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2016-06-07 23:33:21 +08:00
|
|
|
from gi.repository import Gio
|
|
|
|
from gi.repository import GLib
|
|
|
|
from gi.repository import GObject
|
|
|
|
from gi.repository import Gtk
|
|
|
|
|
2014-09-13 04:10:45 +08:00
|
|
|
from . import packageutils
|
|
|
|
from .about import vmmAbout
|
|
|
|
from .baseclass import vmmGObject
|
|
|
|
from .clone import vmmCloneVM
|
|
|
|
from .connect import vmmConnect
|
|
|
|
from .connection import vmmConnection
|
|
|
|
from .preferences import vmmPreferences
|
|
|
|
from .manager import vmmManager
|
|
|
|
from .migrate import vmmMigrateDialog
|
|
|
|
from .details import vmmDetails
|
|
|
|
from .asyncjob import vmmAsyncJob
|
|
|
|
from .create import vmmCreate
|
|
|
|
from .host import vmmHost
|
|
|
|
from .error import vmmErrorDialog
|
|
|
|
from .systray import vmmSystray
|
|
|
|
from .delete import vmmDeleteDialog
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2015-09-21 02:20:50 +08:00
|
|
|
# Enabling this will tell us, at app exit time, which vmmGObjects were not
|
|
|
|
# garbage collected. This is caused by circular references to other objects,
|
|
|
|
# like a signal that wasn't disconnected. It's not a big deal, but if we
|
|
|
|
# have objects that can be created and destroyed a lot over the course of
|
|
|
|
# the app lifecycle, every non-garbage collected class is a memory leak.
|
|
|
|
# So it's nice to poke at this every now and then and try to track down
|
|
|
|
# what we need to add to class _cleanup handling.
|
2013-01-31 01:50:55 +08:00
|
|
|
debug_ref_leaks = False
|
2011-04-12 00:54:47 +08:00
|
|
|
|
2011-06-09 04:33:20 +08:00
|
|
|
DETAILS_PERF = 1
|
|
|
|
DETAILS_CONFIG = 2
|
|
|
|
DETAILS_CONSOLE = 3
|
|
|
|
|
2013-07-07 21:42:21 +08:00
|
|
|
(PRIO_HIGH,
|
|
|
|
PRIO_LOW) = range(1, 3)
|
|
|
|
|
2013-04-14 02:34:52 +08:00
|
|
|
|
2010-12-10 01:37:48 +08:00
|
|
|
class vmmEngine(vmmGObject):
|
2015-11-25 04:21:26 +08:00
|
|
|
CLI_SHOW_DOMAIN_CREATOR = "creator"
|
|
|
|
CLI_SHOW_DOMAIN_EDITOR = "editor"
|
|
|
|
CLI_SHOW_DOMAIN_PERFORMANCE = "performance"
|
|
|
|
CLI_SHOW_DOMAIN_CONSOLE = "console"
|
|
|
|
CLI_SHOW_HOST_SUMMARY = "summary"
|
|
|
|
|
2012-05-14 21:24:56 +08:00
|
|
|
__gsignals__ = {
|
|
|
|
"conn-added": (GObject.SignalFlags.RUN_FIRST, None, [object]),
|
|
|
|
"conn-removed": (GObject.SignalFlags.RUN_FIRST, None, [str]),
|
|
|
|
}
|
|
|
|
|
2010-12-10 01:37:48 +08:00
|
|
|
def __init__(self):
|
|
|
|
vmmGObject.__init__(self)
|
2009-11-16 04:17:03 +08:00
|
|
|
|
2006-06-15 04:20:06 +08:00
|
|
|
self.windowConnect = None
|
2006-06-14 22:59:40 +08:00
|
|
|
self.windowPreferences = None
|
|
|
|
self.windowAbout = None
|
2006-08-09 05:02:15 +08:00
|
|
|
self.windowCreate = None
|
2007-08-10 04:19:41 +08:00
|
|
|
self.windowManager = None
|
2009-11-16 04:17:03 +08:00
|
|
|
self.windowMigrate = None
|
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
self.conns = {}
|
2010-12-01 03:33:21 +08:00
|
|
|
self.err = vmmErrorDialog()
|
2015-04-12 02:34:38 +08:00
|
|
|
self.err.set_find_parent_cb(self._find_error_parent_cb)
|
2006-06-14 22:59:40 +08:00
|
|
|
|
|
|
|
self.timer = None
|
|
|
|
self.last_timeout = 0
|
|
|
|
|
2009-07-28 10:30:01 +08:00
|
|
|
self.systray = None
|
2013-06-18 04:29:51 +08:00
|
|
|
self.delete_dialog = None
|
2015-12-04 04:54:52 +08:00
|
|
|
|
|
|
|
self._gtkapplication = None
|
|
|
|
self._init_gtk_application()
|
2009-07-28 10:30:01 +08:00
|
|
|
|
2013-07-07 08:03:42 +08:00
|
|
|
self._tick_counter = 0
|
2009-07-12 09:23:16 +08:00
|
|
|
self._tick_thread_slow = False
|
2013-07-07 08:03:42 +08:00
|
|
|
self._tick_thread = threading.Thread(name="Tick thread",
|
|
|
|
target=self._handle_tick_queue,
|
|
|
|
args=())
|
|
|
|
self._tick_thread.daemon = True
|
|
|
|
self._tick_queue = Queue.PriorityQueue(100)
|
2009-07-12 09:23:16 +08:00
|
|
|
|
2011-07-23 02:19:35 +08:00
|
|
|
self.inspection = None
|
2011-07-19 02:53:54 +08:00
|
|
|
self._create_inspection_thread()
|
|
|
|
|
2008-06-14 00:12:37 +08:00
|
|
|
# Counter keeping track of how many manager and details windows
|
2009-10-29 23:08:40 +08:00
|
|
|
# are open. When it is decremented to 0, close the app or
|
|
|
|
# keep running in system tray if enabled
|
2008-06-14 00:12:37 +08:00
|
|
|
self.windows = 0
|
|
|
|
|
2009-07-28 10:30:01 +08:00
|
|
|
self.init_systray()
|
2009-07-02 02:59:13 +08:00
|
|
|
|
2014-09-28 19:37:16 +08:00
|
|
|
self.add_gsettings_handle(
|
2011-04-13 21:27:02 +08:00
|
|
|
self.config.on_stats_update_interval_changed(self.reschedule_timer))
|
2014-09-28 19:37:16 +08:00
|
|
|
self.add_gsettings_handle(
|
2011-04-13 21:27:02 +08:00
|
|
|
self.config.on_view_system_tray_changed(self.system_tray_changed))
|
2006-06-14 22:59:40 +08:00
|
|
|
|
|
|
|
self.schedule_timer()
|
2007-09-10 10:57:24 +08:00
|
|
|
self.load_stored_uris()
|
2013-07-07 08:03:42 +08:00
|
|
|
|
|
|
|
self._tick_thread.start()
|
2006-06-14 22:59:40 +08:00
|
|
|
self.tick()
|
|
|
|
|
2010-03-04 05:58:50 +08:00
|
|
|
|
2015-12-04 04:54:52 +08:00
|
|
|
############################
|
|
|
|
# Gtk Application handling #
|
|
|
|
############################
|
|
|
|
|
|
|
|
def _on_gtk_application_activated(self, ignore):
|
|
|
|
"""
|
|
|
|
Invoked after application.run()
|
|
|
|
"""
|
|
|
|
if not self._application.get_windows():
|
|
|
|
logging.debug("Initial gtkapplication activated")
|
|
|
|
self._application.add_window(Gtk.Window())
|
|
|
|
|
|
|
|
def _init_gtk_application(self):
|
|
|
|
self._application = Gtk.Application(
|
|
|
|
application_id="org.virt-manager.virt-manager", flags=0)
|
|
|
|
self._application.register(None)
|
|
|
|
self._application.connect("activate",
|
|
|
|
self._on_gtk_application_activated)
|
|
|
|
|
|
|
|
action = Gio.SimpleAction.new("cli_command",
|
|
|
|
GLib.VariantType.new("(sss)"))
|
|
|
|
action.connect("activate", self._handle_cli_command)
|
|
|
|
self._application.add_action(action)
|
|
|
|
|
2017-10-20 23:46:40 +08:00
|
|
|
def _default_startup(self, skip_autostart, cliuri):
|
2015-12-04 04:54:52 +08:00
|
|
|
uris = self.conns.keys()
|
|
|
|
if not uris:
|
|
|
|
logging.debug("No stored URIs found.")
|
2013-05-30 05:43:38 +08:00
|
|
|
else:
|
2015-12-04 04:54:52 +08:00
|
|
|
logging.debug("Loading stored URIs:\n%s",
|
|
|
|
" \n".join(sorted(uris)))
|
2013-04-16 07:25:54 +08:00
|
|
|
|
2015-12-04 04:54:52 +08:00
|
|
|
if not skip_autostart:
|
|
|
|
self.idle_add(self.autostart_conns)
|
2013-04-16 07:25:54 +08:00
|
|
|
|
2017-10-20 23:46:40 +08:00
|
|
|
if not self.config.get_conn_uris() and not cliuri:
|
2015-12-04 04:54:52 +08:00
|
|
|
# Only add default if no connections are currently known
|
|
|
|
self.timeout_add(1000, self._add_default_conn)
|
|
|
|
|
|
|
|
def start(self, uri, show_window, domain, skip_autostart):
|
|
|
|
# Dispatch dbus CLI command
|
|
|
|
data = GLib.Variant("(sss)",
|
|
|
|
(uri or "", show_window or "", domain or ""))
|
|
|
|
self._application.activate_action("cli_command", data)
|
|
|
|
|
|
|
|
if self._application.get_is_remote():
|
|
|
|
logging.debug("Connected to remote app instance.")
|
|
|
|
return
|
|
|
|
|
2017-10-20 23:46:40 +08:00
|
|
|
self._default_startup(skip_autostart, uri)
|
2015-11-25 04:21:26 +08:00
|
|
|
self._application.run(None)
|
2013-04-16 07:25:54 +08:00
|
|
|
|
2015-12-04 04:54:52 +08:00
|
|
|
|
2009-07-28 10:30:01 +08:00
|
|
|
def init_systray(self):
|
|
|
|
if self.systray:
|
|
|
|
return
|
|
|
|
|
2015-09-21 02:20:50 +08:00
|
|
|
self.systray = vmmSystray()
|
2009-10-29 23:08:40 +08:00
|
|
|
self.systray.connect("action-toggle-manager", self._do_toggle_manager)
|
2009-07-28 10:30:01 +08:00
|
|
|
self.systray.connect("action-suspend-domain", self._do_suspend_domain)
|
|
|
|
self.systray.connect("action-resume-domain", self._do_resume_domain)
|
|
|
|
self.systray.connect("action-run-domain", self._do_run_domain)
|
|
|
|
self.systray.connect("action-shutdown-domain", self._do_shutdown_domain)
|
|
|
|
self.systray.connect("action-reboot-domain", self._do_reboot_domain)
|
|
|
|
self.systray.connect("action-destroy-domain", self._do_destroy_domain)
|
2013-03-17 05:59:32 +08:00
|
|
|
self.systray.connect("action-reset-domain", self._do_reset_domain)
|
2013-09-23 01:24:59 +08:00
|
|
|
self.systray.connect("action-save-domain", self._do_save_domain)
|
2013-09-23 03:13:41 +08:00
|
|
|
self.systray.connect("action-show-domain", self._do_show_vm)
|
|
|
|
self.systray.connect("action-migrate-domain", self._do_show_migrate)
|
|
|
|
self.systray.connect("action-delete-domain", self._do_delete_domain)
|
|
|
|
self.systray.connect("action-clone-domain", self._do_show_clone)
|
2010-11-24 09:13:50 +08:00
|
|
|
self.systray.connect("action-exit-app", self.exit_app)
|
2009-07-28 10:30:01 +08:00
|
|
|
|
2015-09-21 02:20:50 +08:00
|
|
|
self.connect("conn-added", self.systray.conn_added)
|
|
|
|
self.connect("conn-removed", self.systray.conn_removed)
|
|
|
|
|
|
|
|
|
2009-10-29 23:08:40 +08:00
|
|
|
def system_tray_changed(self, *ignore):
|
|
|
|
systray_enabled = self.config.get_view_system_tray()
|
|
|
|
if self.windows == 0 and not systray_enabled:
|
|
|
|
# Show the manager so that the user can control the application
|
2015-11-25 04:21:26 +08:00
|
|
|
self._show_manager()
|
2009-10-29 23:08:40 +08:00
|
|
|
|
2015-12-04 04:54:52 +08:00
|
|
|
def _add_default_conn(self):
|
|
|
|
manager = self.get_manager()
|
2013-09-02 02:19:23 +08:00
|
|
|
|
2010-03-04 05:58:50 +08:00
|
|
|
# Manager fail message
|
|
|
|
msg = _("Could not detect a default hypervisor. Make\n"
|
|
|
|
"sure the appropriate virtualization packages\n"
|
2017-08-14 22:04:43 +08:00
|
|
|
"containing kvm, qemu, libvirt, etc. are\n"
|
|
|
|
"installed, and that libvirtd is running.\n\n"
|
2010-03-04 05:58:50 +08:00
|
|
|
"A hypervisor connection can be manually\n"
|
|
|
|
"added via File->Add Connection")
|
|
|
|
|
|
|
|
logging.debug("Determining default libvirt URI")
|
|
|
|
|
|
|
|
ret = None
|
|
|
|
try:
|
2011-01-15 04:19:58 +08:00
|
|
|
libvirt_packages = self.config.libvirt_packages
|
|
|
|
packages = self.config.hv_packages + libvirt_packages
|
|
|
|
|
2013-09-02 02:19:23 +08:00
|
|
|
ret = packageutils.check_packagekit(manager, manager.err, packages)
|
2017-07-24 16:26:48 +08:00
|
|
|
except Exception:
|
2010-03-04 05:58:50 +08:00
|
|
|
logging.exception("Error talking to PackageKit")
|
|
|
|
|
2017-08-08 05:26:48 +08:00
|
|
|
tryuri = None
|
2013-09-02 02:19:23 +08:00
|
|
|
if ret:
|
2012-07-09 03:38:52 +08:00
|
|
|
tryuri = "qemu:///system"
|
2017-08-08 05:26:48 +08:00
|
|
|
elif not self.config.test_first_run:
|
2015-04-07 04:43:44 +08:00
|
|
|
tryuri = vmmConnect.default_uri()
|
2010-03-04 05:58:50 +08:00
|
|
|
|
|
|
|
if tryuri is None:
|
|
|
|
manager.set_startup_error(msg)
|
|
|
|
return
|
|
|
|
|
2013-06-25 00:15:28 +08:00
|
|
|
warnmsg = _("The 'libvirtd' service will need to be started.\n\n"
|
|
|
|
"After that, virt-manager will connect to libvirt on\n"
|
|
|
|
"the next application start up.")
|
2013-06-14 05:35:48 +08:00
|
|
|
|
|
|
|
# Do the initial connection in an idle callback, so the
|
|
|
|
# packagekit async dialog has a chance to go away
|
|
|
|
def idle_connect():
|
|
|
|
do_start = packageutils.start_libvirtd()
|
2014-02-01 23:44:45 +08:00
|
|
|
connected = self.connect_to_uri(tryuri,
|
|
|
|
autoconnect=True, do_start=do_start)
|
2013-10-16 23:38:37 +08:00
|
|
|
if not connected and do_start:
|
2013-06-14 05:35:48 +08:00
|
|
|
manager.err.ok(_("Libvirt service must be started"), warnmsg)
|
|
|
|
|
|
|
|
self.idle_add(idle_connect)
|
2010-03-04 05:58:50 +08:00
|
|
|
|
|
|
|
|
2007-08-29 05:57:25 +08:00
|
|
|
def load_stored_uris(self):
|
2015-12-04 04:54:52 +08:00
|
|
|
uris = self.config.get_conn_uris() or []
|
2012-11-08 18:02:17 +08:00
|
|
|
for uri in uris:
|
2013-08-08 20:11:18 +08:00
|
|
|
conn = self.make_conn(uri)
|
|
|
|
self.register_conn(conn, skip_config=True)
|
2007-08-29 05:57:25 +08:00
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
def autostart_conns(self):
|
2014-02-01 23:44:45 +08:00
|
|
|
"""
|
|
|
|
We serialize conn autostart, so polkit/ssh-askpass doesn't spam
|
|
|
|
"""
|
|
|
|
queue = Queue.Queue()
|
|
|
|
auto_conns = [uri for uri in self.conns
|
|
|
|
if self.conns[uri]["conn"].get_autoconnect()]
|
|
|
|
|
|
|
|
def add_next_to_queue():
|
|
|
|
if not auto_conns:
|
|
|
|
queue.put(None)
|
|
|
|
else:
|
|
|
|
queue.put(auto_conns.pop(0))
|
|
|
|
|
|
|
|
def state_change_cb(conn):
|
2014-09-12 06:16:21 +08:00
|
|
|
if conn.is_active():
|
2014-02-01 23:44:45 +08:00
|
|
|
add_next_to_queue()
|
|
|
|
conn.disconnect_by_func(state_change_cb)
|
|
|
|
|
|
|
|
def connect(uri):
|
|
|
|
self.connect_to_uri(uri)
|
|
|
|
|
|
|
|
def handle_queue():
|
|
|
|
while True:
|
|
|
|
uri = queue.get()
|
|
|
|
if uri is None:
|
|
|
|
return
|
|
|
|
if uri not in self.conns:
|
|
|
|
add_next_to_queue()
|
|
|
|
continue
|
|
|
|
|
|
|
|
conn = self.conns[uri]["conn"]
|
|
|
|
conn.connect("state-changed", state_change_cb)
|
|
|
|
self.idle_add(connect, uri)
|
|
|
|
|
|
|
|
add_next_to_queue()
|
2014-09-12 23:28:27 +08:00
|
|
|
self._start_thread(handle_queue, "Conn autostart thread")
|
2008-03-24 23:39:19 +08:00
|
|
|
|
2006-06-15 02:36:26 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_vm_removed(self, conn, connkey):
|
2011-07-23 01:54:40 +08:00
|
|
|
hvuri = conn.get_uri()
|
2014-06-03 05:17:47 +08:00
|
|
|
if connkey not in self.conns[hvuri]["windowDetails"]:
|
2011-04-12 06:35:21 +08:00
|
|
|
return
|
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
self.conns[hvuri]["windowDetails"][connkey].cleanup()
|
|
|
|
del(self.conns[hvuri]["windowDetails"][connkey])
|
2006-06-15 04:56:49 +08:00
|
|
|
|
2015-11-04 04:56:39 +08:00
|
|
|
def _do_vm_renamed(self, conn, oldconnkey, newconnkey):
|
|
|
|
hvuri = conn.get_uri()
|
|
|
|
if oldconnkey not in self.conns[hvuri]["windowDetails"]:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.conns[hvuri]["windowDetails"][newconnkey] = (
|
|
|
|
self.conns[hvuri]["windowDetails"].pop(oldconnkey))
|
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
def _do_conn_changed(self, conn):
|
2014-09-12 06:16:21 +08:00
|
|
|
if conn.is_active() or conn.is_connecting():
|
2007-09-27 09:04:02 +08:00
|
|
|
return
|
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
hvuri = conn.get_uri()
|
2011-04-12 06:35:21 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
for connkey in self.conns[hvuri]["windowDetails"].keys():
|
|
|
|
self.conns[hvuri]["windowDetails"][connkey].cleanup()
|
|
|
|
del(self.conns[hvuri]["windowDetails"][connkey])
|
2011-04-12 06:35:21 +08:00
|
|
|
|
|
|
|
if (self.windowCreate and
|
|
|
|
self.windowCreate.conn and
|
2009-03-10 04:16:45 +08:00
|
|
|
self.windowCreate.conn.get_uri() == hvuri):
|
|
|
|
self.windowCreate.close()
|
2007-09-27 09:04:02 +08:00
|
|
|
|
2013-06-15 04:22:33 +08:00
|
|
|
def reschedule_timer(self, *args, **kwargs):
|
2016-04-19 04:42:12 +08:00
|
|
|
ignore1 = args
|
|
|
|
ignore2 = kwargs
|
2006-06-14 22:59:40 +08:00
|
|
|
self.schedule_timer()
|
|
|
|
|
|
|
|
def schedule_timer(self):
|
2010-12-10 03:06:00 +08:00
|
|
|
interval = self.config.get_stats_update_interval() * 1000
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2012-11-08 21:15:02 +08:00
|
|
|
if self.timer is not None:
|
|
|
|
self.remove_gobject_timeout(self.timer)
|
2006-06-14 22:59:40 +08:00
|
|
|
self.timer = None
|
|
|
|
|
2012-11-08 21:15:02 +08:00
|
|
|
self.timer = self.timeout_add(interval, self.tick)
|
2006-06-14 22:59:40 +08:00
|
|
|
|
2013-07-07 23:06:15 +08:00
|
|
|
def _add_obj_to_tick_queue(self, obj, isprio, **kwargs):
|
2013-07-07 08:03:42 +08:00
|
|
|
if self._tick_queue.full():
|
2009-07-14 21:45:23 +08:00
|
|
|
if not self._tick_thread_slow:
|
2009-07-12 09:23:16 +08:00
|
|
|
logging.debug("Tick is slow, not running at requested rate.")
|
2009-10-02 00:04:03 +08:00
|
|
|
self._tick_thread_slow = True
|
2013-07-07 08:03:42 +08:00
|
|
|
return
|
2009-07-12 09:23:16 +08:00
|
|
|
|
2013-07-07 08:03:42 +08:00
|
|
|
self._tick_counter += 1
|
2013-07-07 21:42:21 +08:00
|
|
|
self._tick_queue.put((isprio and PRIO_HIGH or PRIO_LOW,
|
2013-07-07 23:06:15 +08:00
|
|
|
self._tick_counter,
|
|
|
|
obj, kwargs))
|
2007-03-10 05:22:43 +08:00
|
|
|
|
2013-07-07 23:06:15 +08:00
|
|
|
def _schedule_priority_tick(self, conn, kwargs):
|
|
|
|
self._add_obj_to_tick_queue(conn, True, **kwargs)
|
2013-07-07 08:03:42 +08:00
|
|
|
|
|
|
|
def tick(self):
|
2016-12-14 01:36:49 +08:00
|
|
|
for uri in self.conns:
|
2011-07-23 04:43:26 +08:00
|
|
|
conn = self.conns[uri]["conn"]
|
2013-07-07 23:06:15 +08:00
|
|
|
self._add_obj_to_tick_queue(conn, False,
|
|
|
|
stats_update=True, pollvm=True)
|
2013-07-07 08:03:42 +08:00
|
|
|
return 1
|
2011-07-26 01:31:36 +08:00
|
|
|
|
2015-04-12 02:41:02 +08:00
|
|
|
def _handle_tick_error(self, msg, details):
|
|
|
|
if self.windows <= 0:
|
|
|
|
# This means the systray icon is running. Don't raise an error
|
|
|
|
# here to avoid spamming dialogs out of nowhere.
|
|
|
|
logging.debug(msg + "\n\n" + details)
|
|
|
|
return
|
|
|
|
self.err.show_err(msg, details=details)
|
|
|
|
|
2013-07-07 08:03:42 +08:00
|
|
|
def _handle_tick_queue(self):
|
|
|
|
while True:
|
2014-04-16 22:32:52 +08:00
|
|
|
ignore1, ignore2, conn, kwargs = self._tick_queue.get()
|
|
|
|
try:
|
2015-04-14 04:56:46 +08:00
|
|
|
conn.tick_from_engine(**kwargs)
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2014-04-16 22:32:52 +08:00
|
|
|
tb = "".join(traceback.format_exc())
|
|
|
|
error_msg = (_("Error polling connection '%s': %s")
|
|
|
|
% (conn.get_uri(), e))
|
2015-04-12 02:41:02 +08:00
|
|
|
self.idle_add(self._handle_tick_error, error_msg, tb)
|
2014-04-16 22:32:52 +08:00
|
|
|
|
2015-09-21 02:20:50 +08:00
|
|
|
# Need to clear reference to make leak check happy
|
|
|
|
conn = None
|
2013-07-07 08:03:42 +08:00
|
|
|
self._tick_queue.task_done()
|
2006-06-14 22:59:40 +08:00
|
|
|
return 1
|
|
|
|
|
2013-07-07 08:03:42 +08:00
|
|
|
|
2011-04-13 22:47:31 +08:00
|
|
|
def increment_window_counter(self, src):
|
|
|
|
ignore = src
|
2008-06-14 00:12:37 +08:00
|
|
|
self.windows += 1
|
2012-01-17 11:04:40 +08:00
|
|
|
logging.debug("window counter incremented to %s", self.windows)
|
2008-06-14 00:12:37 +08:00
|
|
|
|
2011-04-13 22:47:31 +08:00
|
|
|
def decrement_window_counter(self, src):
|
2008-06-14 00:12:37 +08:00
|
|
|
self.windows -= 1
|
2012-01-17 11:04:40 +08:00
|
|
|
logging.debug("window counter decremented to %s", self.windows)
|
2011-04-13 21:27:02 +08:00
|
|
|
|
2015-12-04 04:54:52 +08:00
|
|
|
self._exit_app_if_no_windows(src)
|
2008-06-14 00:12:37 +08:00
|
|
|
|
2013-07-13 10:10:16 +08:00
|
|
|
def _can_exit(self):
|
|
|
|
# Don't exit if system tray is enabled
|
|
|
|
return (self.windows <= 0 and
|
|
|
|
self.systray and
|
|
|
|
not self.systray.is_visible())
|
|
|
|
|
2011-07-24 09:16:54 +08:00
|
|
|
def _cleanup(self):
|
|
|
|
self.err = None
|
|
|
|
|
|
|
|
if self.inspection:
|
|
|
|
self.inspection.cleanup()
|
|
|
|
self.inspection = None
|
|
|
|
|
2012-11-08 21:15:02 +08:00
|
|
|
if self.timer is not None:
|
2013-02-17 03:03:30 +08:00
|
|
|
GLib.source_remove(self.timer)
|
2011-07-24 09:16:54 +08:00
|
|
|
|
|
|
|
if self.systray:
|
|
|
|
self.systray.cleanup()
|
|
|
|
self.systray = None
|
|
|
|
|
|
|
|
self.get_manager()
|
|
|
|
if self.windowManager:
|
|
|
|
self.windowManager.cleanup()
|
|
|
|
self.windowManager = None
|
|
|
|
|
|
|
|
if self.windowPreferences:
|
|
|
|
self.windowPreferences.cleanup()
|
|
|
|
self.windowPreferences = None
|
|
|
|
|
|
|
|
if self.windowAbout:
|
|
|
|
self.windowAbout.cleanup()
|
|
|
|
self.windowAbout = None
|
|
|
|
|
|
|
|
if self.windowConnect:
|
|
|
|
self.windowConnect.cleanup()
|
|
|
|
self.windowConnect = None
|
|
|
|
|
|
|
|
if self.windowCreate:
|
|
|
|
self.windowCreate.cleanup()
|
|
|
|
self.windowCreate = None
|
|
|
|
|
|
|
|
if self.windowMigrate:
|
|
|
|
self.windowMigrate.cleanup()
|
|
|
|
self.windowMigrate = None
|
|
|
|
|
2013-06-18 04:29:51 +08:00
|
|
|
if self.delete_dialog:
|
|
|
|
self.delete_dialog.cleanup()
|
|
|
|
self.delete_dialog = None
|
|
|
|
|
2011-07-24 09:16:54 +08:00
|
|
|
# Do this last, so any manually 'disconnected' signals
|
|
|
|
# take precedence over cleanup signal removal
|
|
|
|
for uri in self.conns:
|
|
|
|
self.cleanup_conn(uri)
|
|
|
|
self.conns = {}
|
2011-04-13 21:27:02 +08:00
|
|
|
|
2015-12-04 04:54:52 +08:00
|
|
|
def _exit_app_if_no_windows(self, src=None):
|
|
|
|
def cb():
|
|
|
|
if self._can_exit():
|
|
|
|
logging.debug("No windows found, requesting app exit")
|
|
|
|
self.exit_app(src or self)
|
|
|
|
self.idle_add(cb)
|
|
|
|
|
2011-04-13 22:47:31 +08:00
|
|
|
def exit_app(self, src):
|
2011-04-13 21:27:02 +08:00
|
|
|
if self.err is None:
|
|
|
|
# Already in cleanup
|
|
|
|
return
|
|
|
|
|
|
|
|
self.cleanup()
|
2011-04-12 00:54:47 +08:00
|
|
|
|
|
|
|
if debug_ref_leaks:
|
2011-04-13 21:27:02 +08:00
|
|
|
objs = self.config.get_objects()
|
|
|
|
|
|
|
|
# Engine will always appear to leak
|
|
|
|
objs.remove(self.object_key)
|
|
|
|
|
2018-01-09 22:56:27 +08:00
|
|
|
if src and src.object_key in objs:
|
2011-04-14 23:26:53 +08:00
|
|
|
# UI that initiates the app exit will always appear to leak
|
|
|
|
objs.remove(src.object_key)
|
|
|
|
|
2011-04-13 21:27:02 +08:00
|
|
|
for name in objs:
|
2012-01-17 11:04:40 +08:00
|
|
|
logging.debug("Leaked %s", name)
|
2011-04-12 00:54:47 +08:00
|
|
|
|
2008-10-30 21:25:53 +08:00
|
|
|
logging.debug("Exiting app normally.")
|
2015-12-04 04:54:52 +08:00
|
|
|
self._application.quit()
|
2008-06-14 00:12:37 +08:00
|
|
|
|
2011-07-19 02:53:54 +08:00
|
|
|
def _create_inspection_thread(self):
|
2013-06-14 04:00:33 +08:00
|
|
|
logging.debug("libguestfs inspection support: %s",
|
|
|
|
self.config.support_inspection)
|
2011-07-19 02:53:54 +08:00
|
|
|
if not self.config.support_inspection:
|
|
|
|
return
|
2013-06-14 04:00:33 +08:00
|
|
|
|
2014-09-13 04:10:45 +08:00
|
|
|
from .inspection import vmmInspection
|
2011-07-23 02:19:35 +08:00
|
|
|
self.inspection = vmmInspection()
|
|
|
|
self.inspection.start()
|
2011-07-23 04:43:26 +08:00
|
|
|
self.connect("conn-added", self.inspection.conn_added)
|
|
|
|
self.connect("conn-removed", self.inspection.conn_removed)
|
2011-07-19 02:53:54 +08:00
|
|
|
return
|
|
|
|
|
2015-04-12 02:34:38 +08:00
|
|
|
def _find_error_parent_cb(self):
|
|
|
|
"""
|
|
|
|
Search over the toplevel windows for any that are visible or have
|
|
|
|
focus, and use that
|
|
|
|
"""
|
|
|
|
windowlist = [self.windowManager]
|
|
|
|
for conndict in self.conns.values():
|
|
|
|
windowlist.extend(conndict["windowDetails"].values())
|
|
|
|
windowlist.extend(
|
|
|
|
[conndict["windowHost"] for conndict in self.conns.values()])
|
|
|
|
|
|
|
|
use_win = None
|
|
|
|
for window in windowlist:
|
|
|
|
if not window:
|
|
|
|
continue
|
|
|
|
if window.topwin.has_focus():
|
|
|
|
use_win = window
|
|
|
|
break
|
|
|
|
if not use_win and window.is_visible():
|
|
|
|
use_win = window
|
|
|
|
|
|
|
|
if use_win:
|
|
|
|
return use_win.topwin
|
2012-11-08 18:02:17 +08:00
|
|
|
|
2013-08-08 20:11:18 +08:00
|
|
|
def make_conn(self, uri, probe=False):
|
2011-07-23 04:43:26 +08:00
|
|
|
conn = self._check_conn(uri)
|
2010-11-30 07:00:15 +08:00
|
|
|
if conn:
|
|
|
|
return conn
|
|
|
|
|
2011-07-15 08:52:40 +08:00
|
|
|
conn = vmmConnection(uri)
|
2011-07-23 04:43:26 +08:00
|
|
|
self.conns[uri] = {
|
|
|
|
"conn": conn,
|
2007-09-10 10:57:24 +08:00
|
|
|
"windowHost": None,
|
|
|
|
"windowDetails": {},
|
2009-07-27 03:54:14 +08:00
|
|
|
"windowClone": None,
|
2013-08-08 20:11:18 +08:00
|
|
|
"probeConnection": probe
|
2011-04-13 00:06:44 +08:00
|
|
|
}
|
2010-11-24 07:54:12 +08:00
|
|
|
|
|
|
|
conn.connect("vm-removed", self._do_vm_removed)
|
2015-11-04 04:56:39 +08:00
|
|
|
conn.connect("vm-renamed", self._do_vm_renamed)
|
2011-07-23 04:43:26 +08:00
|
|
|
conn.connect("state-changed", self._do_conn_changed)
|
2013-07-13 10:10:16 +08:00
|
|
|
conn.connect("connect-error", self._connect_error)
|
2013-07-07 08:03:42 +08:00
|
|
|
conn.connect("priority-tick", self._schedule_priority_tick)
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2009-07-15 02:48:09 +08:00
|
|
|
return conn
|
|
|
|
|
2012-11-08 18:02:17 +08:00
|
|
|
|
2013-08-08 20:11:18 +08:00
|
|
|
def register_conn(self, conn, skip_config=False):
|
|
|
|
# if `skip_config' then the connection is only showed in the ui and
|
|
|
|
# not added to the config.
|
|
|
|
if not skip_config and conn.get_uri() not in \
|
|
|
|
(self.config.get_conn_uris() or []):
|
|
|
|
self.config.add_conn(conn.get_uri())
|
|
|
|
self.emit("conn-added", conn)
|
2012-11-08 18:02:17 +08:00
|
|
|
|
2013-08-08 20:11:18 +08:00
|
|
|
|
|
|
|
def connect_to_uri(self, uri, autoconnect=None, do_start=True, probe=False):
|
|
|
|
try:
|
|
|
|
conn = self.make_conn(uri, probe=probe)
|
|
|
|
self.register_conn(conn)
|
2012-11-08 18:02:17 +08:00
|
|
|
|
|
|
|
if autoconnect is not None:
|
|
|
|
conn.set_autoconnect(bool(autoconnect))
|
|
|
|
|
|
|
|
if do_start:
|
|
|
|
conn.open()
|
2013-10-16 23:38:37 +08:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
conn.open()
|
2017-07-24 16:26:48 +08:00
|
|
|
except Exception:
|
2013-10-16 23:38:37 +08:00
|
|
|
return None
|
2012-11-08 18:02:17 +08:00
|
|
|
return conn
|
|
|
|
except Exception:
|
|
|
|
logging.exception("Error connecting to %s", uri)
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
def cleanup_conn(self, uri):
|
2011-04-13 21:27:02 +08:00
|
|
|
try:
|
2011-07-23 04:43:26 +08:00
|
|
|
if self.conns[uri]["windowHost"]:
|
|
|
|
self.conns[uri]["windowHost"].cleanup()
|
|
|
|
if self.conns[uri]["windowClone"]:
|
|
|
|
self.conns[uri]["windowClone"].cleanup()
|
2011-04-13 21:27:02 +08:00
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
details = self.conns[uri]["windowDetails"]
|
2011-04-13 21:27:02 +08:00
|
|
|
for win in details.values():
|
|
|
|
win.cleanup()
|
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
self.conns[uri]["conn"].cleanup()
|
2017-07-24 16:26:48 +08:00
|
|
|
except Exception:
|
2011-04-13 21:27:02 +08:00
|
|
|
logging.exception("Error cleaning up conn in engine")
|
|
|
|
|
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
def remove_conn(self, src, uri):
|
2011-07-23 01:42:20 +08:00
|
|
|
ignore = src
|
2011-07-23 04:43:26 +08:00
|
|
|
self.cleanup_conn(uri)
|
|
|
|
del(self.conns[uri])
|
2011-04-12 23:50:10 +08:00
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
self.emit("conn-removed", uri)
|
|
|
|
self.config.remove_conn(uri)
|
2007-09-10 10:57:24 +08:00
|
|
|
|
2011-04-12 01:06:59 +08:00
|
|
|
def connect(self, name, callback, *args):
|
|
|
|
handle_id = vmmGObject.connect(self, name, callback, *args)
|
2007-09-10 10:57:24 +08:00
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
if name == "conn-added":
|
2016-12-14 01:36:49 +08:00
|
|
|
for conn_dict in self.conns.values():
|
|
|
|
self.emit("conn-added", conn_dict["conn"])
|
2007-09-10 10:57:24 +08:00
|
|
|
|
|
|
|
return handle_id
|
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
def _check_conn(self, uri):
|
|
|
|
conn = self.conns.get(uri)
|
2010-03-24 22:57:42 +08:00
|
|
|
if conn:
|
2011-07-23 04:43:26 +08:00
|
|
|
return conn["conn"]
|
2010-03-24 22:57:42 +08:00
|
|
|
return None
|
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
def _lookup_conn(self, uri):
|
|
|
|
conn = self._check_conn(uri)
|
2009-07-15 02:48:09 +08:00
|
|
|
if not conn:
|
|
|
|
raise RuntimeError(_("Unknown connection URI %s") % uri)
|
2010-03-24 22:57:42 +08:00
|
|
|
return conn
|
2006-07-18 01:08:58 +08:00
|
|
|
|
2013-07-13 10:10:16 +08:00
|
|
|
def _connect_error(self, conn, errmsg, tb, warnconsole):
|
|
|
|
errmsg = errmsg.strip(" \n")
|
|
|
|
tb = tb.strip(" \n")
|
|
|
|
hint = ""
|
|
|
|
show_errmsg = True
|
|
|
|
|
|
|
|
if conn.is_remote():
|
2014-09-25 22:13:20 +08:00
|
|
|
logging.debug("connect_error: conn transport=%s",
|
2015-04-12 00:08:57 +08:00
|
|
|
conn.get_uri_transport())
|
2013-07-13 10:10:16 +08:00
|
|
|
if re.search(r"nc: .* -- 'U'", tb):
|
2017-08-08 06:16:45 +08:00
|
|
|
hint += _("The remote host requires a version of netcat/nc "
|
2013-07-13 10:10:16 +08:00
|
|
|
"which supports the -U option.")
|
|
|
|
show_errmsg = False
|
2015-04-12 00:08:57 +08:00
|
|
|
elif (conn.get_uri_transport() == "ssh" and
|
2013-07-13 10:10:16 +08:00
|
|
|
re.search(r"ssh-askpass", tb)):
|
|
|
|
|
2017-08-08 05:41:52 +08:00
|
|
|
askpass = (self.config.askpass_package and
|
|
|
|
self.config.askpass_package[0] or
|
|
|
|
"openssh-askpass")
|
|
|
|
hint += _("You need to install %s or "
|
2017-08-08 06:16:45 +08:00
|
|
|
"similar to connect to this host.") % askpass
|
2013-07-13 10:10:16 +08:00
|
|
|
show_errmsg = False
|
|
|
|
else:
|
2017-08-08 06:16:45 +08:00
|
|
|
hint += _("Verify that the 'libvirtd' daemon is running "
|
2013-07-13 10:10:16 +08:00
|
|
|
"on the remote host.")
|
|
|
|
|
|
|
|
elif conn.is_xen():
|
|
|
|
hint += _("Verify that:\n"
|
|
|
|
" - A Xen host kernel was booted\n"
|
|
|
|
" - The Xen service has been started")
|
|
|
|
|
|
|
|
else:
|
|
|
|
if warnconsole:
|
2017-08-08 06:16:45 +08:00
|
|
|
hint += _("Could not detect a local session: if you are "
|
|
|
|
"running virt-manager over ssh -X or VNC, you "
|
|
|
|
"may not be able to connect to libvirt as a "
|
2013-07-13 10:10:16 +08:00
|
|
|
"regular user. Try running as root.")
|
|
|
|
show_errmsg = False
|
|
|
|
elif re.search(r"libvirt-sock", tb):
|
|
|
|
hint += _("Verify that the 'libvirtd' daemon is running.")
|
|
|
|
show_errmsg = False
|
|
|
|
|
2013-08-08 20:11:18 +08:00
|
|
|
probe_connection = self.conns[conn.get_uri()]["probeConnection"]
|
2017-10-20 23:46:40 +08:00
|
|
|
msg = _("Unable to connect to libvirt %s." % conn.get_uri())
|
2013-07-13 10:10:16 +08:00
|
|
|
if show_errmsg:
|
|
|
|
msg += "\n\n%s" % errmsg
|
|
|
|
if hint:
|
|
|
|
msg += "\n\n%s" % hint
|
|
|
|
|
|
|
|
msg = msg.strip("\n")
|
|
|
|
details = msg
|
|
|
|
details += "\n\n"
|
|
|
|
details += "Libvirt URI is: %s\n\n" % conn.get_uri()
|
|
|
|
details += tb
|
|
|
|
|
2013-08-08 20:11:18 +08:00
|
|
|
if probe_connection:
|
2015-04-05 07:40:22 +08:00
|
|
|
msg += "\n\n"
|
|
|
|
msg += _("Would you still like to remember this connection?")
|
|
|
|
|
2013-08-08 20:11:18 +08:00
|
|
|
title = _("Virtual Machine Manager Connection Failure")
|
|
|
|
if probe_connection:
|
|
|
|
remember_connection = self.err.show_err(msg, details, title,
|
|
|
|
buttons=Gtk.ButtonsType.YES_NO,
|
2013-09-07 08:16:37 +08:00
|
|
|
dialog_type=Gtk.MessageType.QUESTION, modal=True)
|
2013-08-08 20:11:18 +08:00
|
|
|
if remember_connection:
|
|
|
|
self.conns[conn.get_uri()]["probeConnection"] = False
|
|
|
|
else:
|
|
|
|
self.idle_add(self._do_edit_connect, self.windowManager, conn)
|
2013-07-13 10:10:16 +08:00
|
|
|
else:
|
2013-08-08 20:11:18 +08:00
|
|
|
if self._can_exit():
|
2013-09-07 08:16:37 +08:00
|
|
|
self.err.show_err(msg, details, title, modal=True)
|
2015-12-04 04:54:52 +08:00
|
|
|
self._exit_app_if_no_windows(conn)
|
2013-08-08 20:11:18 +08:00
|
|
|
else:
|
|
|
|
self.err.show_err(msg, details, title)
|
2013-07-13 10:10:16 +08:00
|
|
|
|
2015-04-05 07:40:22 +08:00
|
|
|
|
2010-11-24 07:54:12 +08:00
|
|
|
####################
|
|
|
|
# Dialog launchers #
|
|
|
|
####################
|
|
|
|
|
2010-11-24 09:13:50 +08:00
|
|
|
def _do_show_about(self, src):
|
2010-11-24 07:54:12 +08:00
|
|
|
try:
|
2012-11-08 21:15:02 +08:00
|
|
|
if self.windowAbout is None:
|
2010-12-09 06:26:19 +08:00
|
|
|
self.windowAbout = vmmAbout()
|
2010-11-24 07:54:12 +08:00
|
|
|
self.windowAbout.show()
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2011-04-06 23:22:03 +08:00
|
|
|
src.err.show_err(_("Error launching 'About' dialog: %s") % str(e))
|
2010-11-24 07:54:12 +08:00
|
|
|
|
|
|
|
def _get_preferences(self):
|
|
|
|
if self.windowPreferences:
|
|
|
|
return self.windowPreferences
|
|
|
|
|
2010-12-09 06:26:19 +08:00
|
|
|
obj = vmmPreferences()
|
2010-11-24 07:54:12 +08:00
|
|
|
self.windowPreferences = obj
|
|
|
|
return self.windowPreferences
|
|
|
|
|
2010-11-24 09:13:50 +08:00
|
|
|
def _do_show_preferences(self, src):
|
2010-11-24 07:54:12 +08:00
|
|
|
try:
|
2011-04-14 20:47:42 +08:00
|
|
|
self._get_preferences().show(src.topwin)
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2011-04-06 23:22:03 +08:00
|
|
|
src.err.show_err(_("Error launching preferences: %s") % str(e))
|
2010-11-24 07:54:12 +08:00
|
|
|
|
|
|
|
def _get_host_dialog(self, uri):
|
2011-07-23 04:43:26 +08:00
|
|
|
if self.conns[uri]["windowHost"]:
|
|
|
|
return self.conns[uri]["windowHost"]
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
conn = self._lookup_conn(uri)
|
|
|
|
obj = vmmHost(conn)
|
2011-04-13 22:47:31 +08:00
|
|
|
|
2010-11-24 09:13:50 +08:00
|
|
|
obj.connect("action-exit-app", self.exit_app)
|
2010-11-24 07:54:12 +08:00
|
|
|
obj.connect("action-view-manager", self._do_show_manager)
|
2011-04-13 22:47:31 +08:00
|
|
|
obj.connect("host-opened", self.increment_window_counter)
|
|
|
|
obj.connect("host-closed", self.decrement_window_counter)
|
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
self.conns[uri]["windowHost"] = obj
|
|
|
|
return self.conns[uri]["windowHost"]
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2010-11-24 09:13:50 +08:00
|
|
|
def _do_show_host(self, src, uri):
|
2010-11-24 07:54:12 +08:00
|
|
|
try:
|
|
|
|
self._get_host_dialog(uri).show()
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2011-04-06 23:22:03 +08:00
|
|
|
src.err.show_err(_("Error launching host dialog: %s") % str(e))
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2012-11-08 18:02:17 +08:00
|
|
|
|
2010-11-24 07:54:12 +08:00
|
|
|
def _get_connect_dialog(self):
|
|
|
|
if self.windowConnect:
|
|
|
|
return self.windowConnect
|
|
|
|
|
2012-11-08 18:02:17 +08:00
|
|
|
def completed(src, uri, autoconnect):
|
2011-07-15 08:52:40 +08:00
|
|
|
ignore = src
|
2013-08-08 20:11:18 +08:00
|
|
|
return self.connect_to_uri(uri, autoconnect, probe=True)
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2012-11-08 18:02:17 +08:00
|
|
|
def cancelled(src):
|
|
|
|
if len(self.conns.keys()) == 0:
|
|
|
|
self.exit_app(src)
|
|
|
|
|
2010-12-09 06:26:19 +08:00
|
|
|
obj = vmmConnect()
|
2012-11-08 18:02:17 +08:00
|
|
|
obj.connect("completed", completed)
|
|
|
|
obj.connect("cancelled", cancelled)
|
2010-11-24 07:54:12 +08:00
|
|
|
self.windowConnect = obj
|
|
|
|
return self.windowConnect
|
|
|
|
|
2012-11-08 18:02:17 +08:00
|
|
|
|
2013-08-08 20:11:18 +08:00
|
|
|
def _do_show_connect(self, src, reset_state=True):
|
2010-11-24 07:54:12 +08:00
|
|
|
try:
|
2013-08-08 20:11:18 +08:00
|
|
|
self._get_connect_dialog().show(src.topwin, reset_state)
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2011-04-06 23:22:03 +08:00
|
|
|
src.err.show_err(_("Error launching connect dialog: %s") % str(e))
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2013-08-08 20:11:18 +08:00
|
|
|
def _do_edit_connect(self, src, connection):
|
|
|
|
try:
|
|
|
|
self._do_show_connect(src, False)
|
|
|
|
finally:
|
|
|
|
self.remove_conn(None, connection.get_uri())
|
|
|
|
|
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _get_details_dialog(self, uri, connkey):
|
|
|
|
if connkey in self.conns[uri]["windowDetails"]:
|
|
|
|
return self.conns[uri]["windowDetails"][connkey]
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
conn = self._lookup_conn(uri)
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
obj = vmmDetails(conn.get_vm(connkey))
|
2010-11-24 07:54:12 +08:00
|
|
|
obj.connect("action-save-domain", self._do_save_domain)
|
|
|
|
obj.connect("action-destroy-domain", self._do_destroy_domain)
|
2013-03-17 05:59:32 +08:00
|
|
|
obj.connect("action-reset-domain", self._do_reset_domain)
|
2010-11-24 07:54:12 +08:00
|
|
|
obj.connect("action-suspend-domain", self._do_suspend_domain)
|
|
|
|
obj.connect("action-resume-domain", self._do_resume_domain)
|
|
|
|
obj.connect("action-run-domain", self._do_run_domain)
|
|
|
|
obj.connect("action-shutdown-domain", self._do_shutdown_domain)
|
|
|
|
obj.connect("action-reboot-domain", self._do_reboot_domain)
|
2010-11-24 09:13:50 +08:00
|
|
|
obj.connect("action-exit-app", self.exit_app)
|
2010-11-24 07:54:12 +08:00
|
|
|
obj.connect("action-view-manager", self._do_show_manager)
|
2010-11-24 09:13:50 +08:00
|
|
|
obj.connect("action-migrate-domain", self._do_show_migrate)
|
2013-06-18 04:29:51 +08:00
|
|
|
obj.connect("action-delete-domain", self._do_delete_domain)
|
2010-11-24 09:13:50 +08:00
|
|
|
obj.connect("action-clone-domain", self._do_show_clone)
|
2011-04-13 22:47:31 +08:00
|
|
|
obj.connect("details-opened", self.increment_window_counter)
|
|
|
|
obj.connect("details-closed", self.decrement_window_counter)
|
2017-02-23 18:22:27 +08:00
|
|
|
obj.connect("inspection-refresh", self._do_refresh_inspection)
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
self.conns[uri]["windowDetails"][connkey] = obj
|
|
|
|
return self.conns[uri]["windowDetails"][connkey]
|
2013-07-13 10:10:16 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _show_vm_helper(self, src, uri, vm, page, forcepage):
|
|
|
|
try:
|
|
|
|
details = self._get_details_dialog(uri, vm.get_connkey())
|
2011-06-09 04:33:20 +08:00
|
|
|
|
|
|
|
if forcepage or not details.is_visible():
|
|
|
|
if page == DETAILS_PERF:
|
|
|
|
details.activate_performance_page()
|
|
|
|
elif page == DETAILS_CONFIG:
|
|
|
|
details.activate_config_page()
|
|
|
|
elif page == DETAILS_CONSOLE:
|
|
|
|
details.activate_console_page()
|
|
|
|
elif page is None:
|
|
|
|
details.activate_default_page()
|
|
|
|
|
2010-11-24 07:54:12 +08:00
|
|
|
details.show()
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2011-04-06 23:22:03 +08:00
|
|
|
src.err.show_err(_("Error launching details: %s") % str(e))
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_show_vm(self, src, uri, connkey):
|
|
|
|
conn = self._lookup_conn(uri)
|
|
|
|
vm = conn.get_vm(connkey)
|
|
|
|
self._show_vm_helper(src, uri, vm, None, False)
|
2010-11-24 07:54:12 +08:00
|
|
|
|
|
|
|
def get_manager(self):
|
|
|
|
if self.windowManager:
|
|
|
|
return self.windowManager
|
|
|
|
|
2011-07-23 01:42:20 +08:00
|
|
|
obj = vmmManager()
|
2010-11-24 07:54:12 +08:00
|
|
|
obj.connect("action-suspend-domain", self._do_suspend_domain)
|
|
|
|
obj.connect("action-resume-domain", self._do_resume_domain)
|
|
|
|
obj.connect("action-run-domain", self._do_run_domain)
|
|
|
|
obj.connect("action-shutdown-domain", self._do_shutdown_domain)
|
|
|
|
obj.connect("action-reboot-domain", self._do_reboot_domain)
|
|
|
|
obj.connect("action-destroy-domain", self._do_destroy_domain)
|
2013-03-17 05:59:32 +08:00
|
|
|
obj.connect("action-reset-domain", self._do_reset_domain)
|
2010-11-24 07:54:12 +08:00
|
|
|
obj.connect("action-save-domain", self._do_save_domain)
|
2010-11-24 09:13:50 +08:00
|
|
|
obj.connect("action-migrate-domain", self._do_show_migrate)
|
2013-06-18 04:29:51 +08:00
|
|
|
obj.connect("action-delete-domain", self._do_delete_domain)
|
2010-11-24 09:13:50 +08:00
|
|
|
obj.connect("action-clone-domain", self._do_show_clone)
|
2013-09-23 03:13:41 +08:00
|
|
|
obj.connect("action-show-domain", self._do_show_vm)
|
2010-11-24 07:54:12 +08:00
|
|
|
obj.connect("action-show-preferences", self._do_show_preferences)
|
|
|
|
obj.connect("action-show-create", self._do_show_create)
|
|
|
|
obj.connect("action-show-about", self._do_show_about)
|
|
|
|
obj.connect("action-show-host", self._do_show_host)
|
|
|
|
obj.connect("action-show-connect", self._do_show_connect)
|
2010-11-24 09:13:50 +08:00
|
|
|
obj.connect("action-exit-app", self.exit_app)
|
2011-04-13 22:47:31 +08:00
|
|
|
obj.connect("manager-opened", self.increment_window_counter)
|
|
|
|
obj.connect("manager-closed", self.decrement_window_counter)
|
2011-07-23 04:43:26 +08:00
|
|
|
obj.connect("remove-conn", self.remove_conn)
|
2011-07-23 01:42:20 +08:00
|
|
|
|
2011-07-23 04:43:26 +08:00
|
|
|
self.connect("conn-added", obj.add_conn)
|
|
|
|
self.connect("conn-removed", obj.remove_conn)
|
2010-11-24 07:54:12 +08:00
|
|
|
|
|
|
|
self.windowManager = obj
|
|
|
|
return self.windowManager
|
|
|
|
|
2010-11-24 09:13:50 +08:00
|
|
|
def _do_toggle_manager(self, ignore):
|
2010-11-24 07:54:12 +08:00
|
|
|
manager = self.get_manager()
|
2010-12-14 06:48:19 +08:00
|
|
|
if manager.is_visible():
|
|
|
|
manager.close()
|
|
|
|
else:
|
2010-11-24 07:54:12 +08:00
|
|
|
manager.show()
|
|
|
|
|
2010-11-24 09:13:50 +08:00
|
|
|
def _do_show_manager(self, src):
|
2010-11-24 07:54:12 +08:00
|
|
|
try:
|
2011-04-13 21:27:02 +08:00
|
|
|
manager = self.get_manager()
|
|
|
|
manager.show()
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2010-11-24 09:13:50 +08:00
|
|
|
if not src:
|
|
|
|
raise
|
2011-04-06 23:22:03 +08:00
|
|
|
src.err.show_err(_("Error launching manager: %s") % str(e))
|
2010-11-24 07:54:12 +08:00
|
|
|
|
|
|
|
def _get_create_dialog(self):
|
|
|
|
if self.windowCreate:
|
|
|
|
return self.windowCreate
|
|
|
|
|
2010-12-09 06:26:19 +08:00
|
|
|
obj = vmmCreate(self)
|
2013-09-23 03:13:41 +08:00
|
|
|
obj.connect("action-show-domain", self._do_show_vm)
|
2016-05-20 21:27:17 +08:00
|
|
|
obj.connect("create-opened", self.increment_window_counter)
|
|
|
|
obj.connect("create-closed", self.decrement_window_counter)
|
2010-11-24 07:54:12 +08:00
|
|
|
self.windowCreate = obj
|
|
|
|
return self.windowCreate
|
|
|
|
|
2010-11-24 09:13:50 +08:00
|
|
|
def _do_show_create(self, src, uri):
|
2010-11-24 07:54:12 +08:00
|
|
|
try:
|
2011-04-14 20:47:42 +08:00
|
|
|
self._get_create_dialog().show(src.topwin, uri)
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2011-04-06 23:22:03 +08:00
|
|
|
src.err.show_err(_("Error launching manager: %s") % str(e))
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_show_migrate(self, src, uri, connkey):
|
2010-11-24 07:54:12 +08:00
|
|
|
try:
|
2011-07-23 04:43:26 +08:00
|
|
|
conn = self._lookup_conn(uri)
|
2014-06-03 05:17:47 +08:00
|
|
|
vm = conn.get_vm(connkey)
|
2010-11-24 07:54:12 +08:00
|
|
|
|
|
|
|
if not self.windowMigrate:
|
2015-04-16 23:21:34 +08:00
|
|
|
self.windowMigrate = vmmMigrateDialog(self)
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2015-04-16 23:21:34 +08:00
|
|
|
self.windowMigrate.show(src.topwin, vm)
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2011-04-06 23:22:03 +08:00
|
|
|
src.err.show_err(_("Error launching migrate dialog: %s") % str(e))
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_show_clone(self, src, uri, connkey):
|
|
|
|
conn = self._lookup_conn(uri)
|
|
|
|
orig_vm = conn.get_vm(connkey)
|
2011-07-23 04:43:26 +08:00
|
|
|
clone_window = self.conns[uri]["windowClone"]
|
2010-11-24 07:54:12 +08:00
|
|
|
|
|
|
|
try:
|
2012-11-08 21:15:02 +08:00
|
|
|
if clone_window is None:
|
2010-12-09 06:26:19 +08:00
|
|
|
clone_window = vmmCloneVM(orig_vm)
|
2011-07-23 04:43:26 +08:00
|
|
|
self.conns[uri]["windowClone"] = clone_window
|
2010-11-24 07:54:12 +08:00
|
|
|
else:
|
|
|
|
clone_window.set_orig_vm(orig_vm)
|
|
|
|
|
2011-04-14 20:47:42 +08:00
|
|
|
clone_window.show(src.topwin)
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2011-04-06 23:22:03 +08:00
|
|
|
src.err.show_err(_("Error setting clone parameters: %s") % str(e))
|
2010-11-24 09:13:50 +08:00
|
|
|
|
2017-02-23 18:22:27 +08:00
|
|
|
def _do_refresh_inspection(self, src_ignore, uri, connkey):
|
|
|
|
if not self.inspection:
|
|
|
|
return
|
|
|
|
|
|
|
|
conn = self._lookup_conn(uri)
|
|
|
|
vm = conn.get_vm(connkey)
|
|
|
|
self.inspection.vm_refresh(vm)
|
|
|
|
|
2010-11-24 09:13:50 +08:00
|
|
|
##########################################
|
|
|
|
# Window launchers from virt-manager cli #
|
|
|
|
##########################################
|
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _find_vm_by_cli_str(self, uri, clistr):
|
|
|
|
"""
|
|
|
|
Lookup a VM by a string passed in on the CLI. Can be either
|
|
|
|
ID, domain name, or UUID
|
|
|
|
"""
|
|
|
|
if clistr.isdigit():
|
|
|
|
clistr = int(clistr)
|
|
|
|
|
|
|
|
for vm in self.conns[uri]["conn"].list_vms():
|
|
|
|
if clistr == vm.get_id():
|
|
|
|
return vm
|
|
|
|
elif clistr == vm.get_name():
|
|
|
|
return vm
|
|
|
|
elif clistr == vm.get_uuid():
|
|
|
|
return vm
|
|
|
|
|
|
|
|
def _cli_show_vm_helper(self, uri, clistr, page):
|
|
|
|
src = self.get_manager()
|
|
|
|
|
|
|
|
vm = self._find_vm_by_cli_str(uri, clistr)
|
|
|
|
if not vm:
|
|
|
|
src.err.show_err("%s does not have VM '%s'" %
|
|
|
|
(uri, clistr), modal=True)
|
|
|
|
return
|
|
|
|
|
|
|
|
self._show_vm_helper(src, uri, vm, page, True)
|
|
|
|
|
2015-11-25 04:21:26 +08:00
|
|
|
def _show_manager(self):
|
|
|
|
self._do_show_manager(None)
|
|
|
|
|
|
|
|
def _show_host_summary(self, uri):
|
|
|
|
self._do_show_host(self.get_manager(), uri)
|
|
|
|
|
|
|
|
def _show_domain_creator(self, uri):
|
|
|
|
self._do_show_create(self.get_manager(), uri)
|
|
|
|
|
|
|
|
def _show_domain_console(self, uri, clistr):
|
2015-12-04 04:54:52 +08:00
|
|
|
self._cli_show_vm_helper(uri, clistr, DETAILS_CONSOLE)
|
2014-06-03 05:17:47 +08:00
|
|
|
|
2015-11-25 04:21:26 +08:00
|
|
|
def _show_domain_editor(self, uri, clistr):
|
2015-12-04 04:54:52 +08:00
|
|
|
self._cli_show_vm_helper(uri, clistr, DETAILS_CONFIG)
|
2010-11-24 09:13:50 +08:00
|
|
|
|
2015-11-25 04:21:26 +08:00
|
|
|
def _show_domain_performance(self, uri, clistr):
|
2015-12-04 04:54:52 +08:00
|
|
|
self._cli_show_vm_helper(uri, clistr, DETAILS_PERF)
|
2010-11-24 07:54:12 +08:00
|
|
|
|
2015-11-25 04:21:26 +08:00
|
|
|
def _launch_cli_window(self, uri, show_window, clistr):
|
2015-12-04 04:54:52 +08:00
|
|
|
try:
|
|
|
|
logging.debug("Launching requested window '%s'", show_window)
|
|
|
|
if show_window == self.CLI_SHOW_DOMAIN_CREATOR:
|
|
|
|
self._show_domain_creator(uri)
|
|
|
|
elif show_window == self.CLI_SHOW_DOMAIN_EDITOR:
|
|
|
|
self._show_domain_editor(uri, clistr)
|
|
|
|
elif show_window == self.CLI_SHOW_DOMAIN_PERFORMANCE:
|
|
|
|
self._show_domain_performance(uri, clistr)
|
|
|
|
elif show_window == self.CLI_SHOW_DOMAIN_CONSOLE:
|
|
|
|
self._show_domain_console(uri, clistr)
|
|
|
|
elif show_window == self.CLI_SHOW_HOST_SUMMARY:
|
|
|
|
self._show_host_summary(uri)
|
|
|
|
else:
|
|
|
|
raise RuntimeError("Unknown cli window command '%s'" %
|
|
|
|
show_window)
|
|
|
|
finally:
|
|
|
|
# In case of cli error, we may need to exit the app
|
|
|
|
self._exit_app_if_no_windows()
|
2015-11-25 04:21:26 +08:00
|
|
|
|
|
|
|
def _cli_conn_connected_cb(self, conn, uri, show_window, domain):
|
2015-12-04 04:54:52 +08:00
|
|
|
try:
|
|
|
|
ignore = conn
|
2015-11-25 04:21:26 +08:00
|
|
|
|
2015-12-04 04:54:52 +08:00
|
|
|
if conn.is_disconnected():
|
|
|
|
raise RuntimeError("failed to connect to cli uri=%s" % uri)
|
2015-11-25 04:21:26 +08:00
|
|
|
|
2015-12-04 04:54:52 +08:00
|
|
|
if conn.is_active():
|
|
|
|
self._launch_cli_window(uri, show_window, domain)
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2017-07-24 16:26:48 +08:00
|
|
|
except Exception:
|
2015-12-04 04:54:52 +08:00
|
|
|
# In case of cli error, we may need to exit the app
|
|
|
|
logging.debug("Error in cli connection callback", exc_info=True)
|
|
|
|
self._exit_app_if_no_windows()
|
2015-11-25 04:21:26 +08:00
|
|
|
return True
|
|
|
|
|
2015-12-04 04:54:52 +08:00
|
|
|
def _do_handle_cli_command(self, actionobj, variant):
|
|
|
|
ignore = actionobj
|
|
|
|
uri = variant[0]
|
|
|
|
show_window = variant[1]
|
|
|
|
domain = variant[2]
|
2015-11-25 04:21:26 +08:00
|
|
|
|
2015-12-04 04:54:52 +08:00
|
|
|
logging.debug("processing cli command uri=%s show_window=%s domain=%s",
|
|
|
|
uri, show_window, domain)
|
2015-11-25 04:21:26 +08:00
|
|
|
if not uri:
|
2015-12-04 04:54:52 +08:00
|
|
|
logging.debug("No cli action requested, launching default window")
|
|
|
|
self._show_manager()
|
2015-11-25 04:21:26 +08:00
|
|
|
return
|
|
|
|
|
|
|
|
conn = self.make_conn(uri)
|
|
|
|
self.register_conn(conn, skip_config=True)
|
2015-12-04 04:54:52 +08:00
|
|
|
|
|
|
|
if conn.is_disconnected():
|
|
|
|
# Schedule connection open
|
|
|
|
def connect():
|
|
|
|
# We need to wrap this to ignore the return value, otherwise
|
|
|
|
# the callback will be rescheduled
|
|
|
|
self.connect_to_uri(uri)
|
|
|
|
self.idle_add(connect)
|
|
|
|
|
2015-11-25 04:21:26 +08:00
|
|
|
if show_window:
|
|
|
|
if conn.is_active():
|
|
|
|
self.idle_add(self._launch_cli_window,
|
|
|
|
uri, show_window, domain)
|
|
|
|
else:
|
|
|
|
conn.connect_opt_out("state-changed",
|
|
|
|
self._cli_conn_connected_cb, uri, show_window, domain)
|
2015-12-04 04:54:52 +08:00
|
|
|
else:
|
|
|
|
self.get_manager().set_initial_selection(uri)
|
|
|
|
self._show_manager()
|
2015-11-25 04:21:26 +08:00
|
|
|
|
2015-12-04 04:54:52 +08:00
|
|
|
def _handle_cli_command(self, actionobj, variant):
|
|
|
|
try:
|
|
|
|
return self._do_handle_cli_command(actionobj, variant)
|
2017-07-24 16:26:48 +08:00
|
|
|
except Exception:
|
2015-12-04 04:54:52 +08:00
|
|
|
# In case of cli error, we may need to exit the app
|
|
|
|
logging.debug("Error handling cli command", exc_info=True)
|
|
|
|
self._exit_app_if_no_windows()
|
2015-11-25 04:21:26 +08:00
|
|
|
|
2013-07-07 08:03:42 +08:00
|
|
|
|
2010-11-24 07:54:12 +08:00
|
|
|
#######################################
|
|
|
|
# Domain actions run/destroy/save ... #
|
|
|
|
#######################################
|
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_save_domain(self, src, uri, connkey):
|
2011-07-23 04:43:26 +08:00
|
|
|
conn = self._lookup_conn(uri)
|
2014-06-03 05:17:47 +08:00
|
|
|
vm = conn.get_vm(connkey)
|
2009-03-09 03:14:00 +08:00
|
|
|
|
2014-01-27 06:42:24 +08:00
|
|
|
if not src.err.chkbox_helper(self.config.get_confirm_poweroff,
|
2017-09-20 15:36:27 +08:00
|
|
|
self.config.set_confirm_poweroff,
|
|
|
|
text1=_("Are you sure you want to save '%s'?") % vm.get_name()):
|
2011-04-15 04:43:17 +08:00
|
|
|
return
|
2009-03-09 03:14:00 +08:00
|
|
|
|
2013-06-14 05:05:33 +08:00
|
|
|
_cancel_cb = None
|
2010-12-09 01:52:33 +08:00
|
|
|
if vm.getjobinfo_supported:
|
2013-06-14 05:05:33 +08:00
|
|
|
_cancel_cb = (self._save_cancel, vm)
|
2010-12-09 01:52:33 +08:00
|
|
|
|
2013-07-05 20:59:58 +08:00
|
|
|
def cb(asyncjob):
|
2015-04-12 01:52:48 +08:00
|
|
|
vm.save(meter=asyncjob.get_meter())
|
2013-09-07 08:59:01 +08:00
|
|
|
def finish_cb(error, details):
|
|
|
|
if error is not None:
|
|
|
|
error = _("Error saving domain: %s") % error
|
|
|
|
src.err.show_err(error, details=details)
|
2013-07-05 20:59:58 +08:00
|
|
|
|
|
|
|
progWin = vmmAsyncJob(cb, [],
|
2013-09-07 08:59:01 +08:00
|
|
|
finish_cb, [],
|
2010-12-13 02:48:20 +08:00
|
|
|
_("Saving Virtual Machine"),
|
|
|
|
_("Saving virtual machine memory to disk "),
|
2013-06-14 05:05:33 +08:00
|
|
|
src.topwin, cancel_cb=_cancel_cb)
|
2013-09-07 08:59:01 +08:00
|
|
|
progWin.run()
|
2007-11-28 00:31:30 +08:00
|
|
|
|
2010-12-10 22:57:42 +08:00
|
|
|
def _save_cancel(self, asyncjob, vm):
|
2010-12-09 03:14:38 +08:00
|
|
|
logging.debug("Cancelling save job")
|
2010-12-09 01:52:33 +08:00
|
|
|
if not vm:
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
vm.abort_job()
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2010-12-09 03:14:38 +08:00
|
|
|
logging.exception("Error cancelling save job")
|
2010-12-11 00:47:07 +08:00
|
|
|
asyncjob.show_warning(_("Error cancelling save job: %s") % str(e))
|
2010-12-09 01:52:33 +08:00
|
|
|
return
|
|
|
|
|
|
|
|
asyncjob.job_canceled = True
|
|
|
|
return
|
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_destroy_domain(self, src, uri, connkey):
|
2011-07-23 04:43:26 +08:00
|
|
|
conn = self._lookup_conn(uri)
|
2014-06-03 05:17:47 +08:00
|
|
|
vm = conn.get_vm(connkey)
|
2011-04-15 04:43:17 +08:00
|
|
|
|
2014-01-27 06:42:24 +08:00
|
|
|
if not src.err.chkbox_helper(
|
2013-08-09 21:23:01 +08:00
|
|
|
self.config.get_confirm_forcepoweroff,
|
2011-04-15 04:43:17 +08:00
|
|
|
self.config.set_confirm_forcepoweroff,
|
|
|
|
text1=_("Are you sure you want to force poweroff '%s'?" %
|
|
|
|
vm.get_name()),
|
|
|
|
text2=_("This will immediately poweroff the VM without "
|
|
|
|
"shutting down the OS and may cause data loss.")):
|
|
|
|
return
|
2009-07-15 02:48:09 +08:00
|
|
|
|
2012-01-17 11:04:40 +08:00
|
|
|
logging.debug("Destroying vm '%s'", vm.get_name())
|
2011-04-16 03:23:13 +08:00
|
|
|
vmmAsyncJob.simple_async_noshow(vm.destroy, [], src,
|
|
|
|
_("Error shutting down domain"))
|
2007-11-28 00:31:30 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_suspend_domain(self, src, uri, connkey):
|
2011-07-23 04:43:26 +08:00
|
|
|
conn = self._lookup_conn(uri)
|
2014-06-03 05:17:47 +08:00
|
|
|
vm = conn.get_vm(connkey)
|
2009-11-19 05:11:17 +08:00
|
|
|
|
2014-01-27 06:42:24 +08:00
|
|
|
if not src.err.chkbox_helper(self.config.get_confirm_pause,
|
2011-04-15 04:43:17 +08:00
|
|
|
self.config.set_confirm_pause,
|
|
|
|
text1=_("Are you sure you want to pause '%s'?" %
|
|
|
|
vm.get_name())):
|
|
|
|
return
|
2009-07-15 02:48:09 +08:00
|
|
|
|
2012-01-17 11:04:40 +08:00
|
|
|
logging.debug("Pausing vm '%s'", vm.get_name())
|
2011-04-16 03:23:13 +08:00
|
|
|
vmmAsyncJob.simple_async_noshow(vm.suspend, [], src,
|
|
|
|
_("Error pausing domain"))
|
2009-07-15 02:48:09 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_resume_domain(self, src, uri, connkey):
|
2011-07-23 04:43:26 +08:00
|
|
|
conn = self._lookup_conn(uri)
|
2014-06-03 05:17:47 +08:00
|
|
|
vm = conn.get_vm(connkey)
|
2009-07-15 02:48:09 +08:00
|
|
|
|
2012-01-17 11:04:40 +08:00
|
|
|
logging.debug("Unpausing vm '%s'", vm.get_name())
|
2011-04-16 03:23:13 +08:00
|
|
|
vmmAsyncJob.simple_async_noshow(vm.resume, [], src,
|
|
|
|
_("Error unpausing domain"))
|
2009-07-15 02:48:09 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_run_domain(self, src, uri, connkey):
|
2011-07-23 04:43:26 +08:00
|
|
|
conn = self._lookup_conn(uri)
|
2014-06-03 05:17:47 +08:00
|
|
|
vm = conn.get_vm(connkey)
|
2009-07-15 02:48:09 +08:00
|
|
|
|
2012-01-17 11:04:40 +08:00
|
|
|
logging.debug("Starting vm '%s'", vm.get_name())
|
2010-12-11 03:40:08 +08:00
|
|
|
|
2014-09-12 06:01:41 +08:00
|
|
|
if vm.has_managed_save():
|
2012-07-09 04:06:16 +08:00
|
|
|
def errorcb(error, details):
|
|
|
|
# This is run from the main thread
|
|
|
|
res = src.err.show_err(
|
|
|
|
_("Error restoring domain") + ": " + error,
|
|
|
|
details=details,
|
|
|
|
text2=_(
|
|
|
|
"The domain could not be restored. Would you like\n"
|
|
|
|
"to remove the saved state and perform a regular\n"
|
|
|
|
"start up?"),
|
2012-11-08 21:15:02 +08:00
|
|
|
dialog_type=Gtk.MessageType.WARNING,
|
|
|
|
buttons=Gtk.ButtonsType.YES_NO,
|
2013-09-07 08:16:37 +08:00
|
|
|
modal=True)
|
2012-07-09 04:06:16 +08:00
|
|
|
|
|
|
|
if not res:
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
2014-09-12 06:01:41 +08:00
|
|
|
vm.remove_saved_image()
|
2014-06-03 05:17:47 +08:00
|
|
|
self._do_run_domain(src, uri, connkey)
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2012-07-09 04:06:16 +08:00
|
|
|
src.err.show_err(_("Error removing domain state: %s")
|
|
|
|
% str(e))
|
|
|
|
|
|
|
|
# VM will be restored, which can take some time, so show progress
|
2010-12-13 02:48:20 +08:00
|
|
|
title = _("Restoring Virtual Machine")
|
|
|
|
text = _("Restoring virtual machine memory from disk")
|
2013-10-05 22:03:56 +08:00
|
|
|
vmmAsyncJob.simple_async(vm.startup, [], src,
|
|
|
|
title, text, "", errorcb=errorcb)
|
2010-12-11 03:40:08 +08:00
|
|
|
|
|
|
|
else:
|
|
|
|
# Regular startup
|
|
|
|
errorintro = _("Error starting domain")
|
2011-04-15 03:28:22 +08:00
|
|
|
vmmAsyncJob.simple_async_noshow(vm.startup, [], src, errorintro)
|
2009-04-04 04:06:46 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_shutdown_domain(self, src, uri, connkey):
|
2011-07-23 04:43:26 +08:00
|
|
|
conn = self._lookup_conn(uri)
|
2014-06-03 05:17:47 +08:00
|
|
|
vm = conn.get_vm(connkey)
|
2009-11-19 05:11:17 +08:00
|
|
|
|
2014-01-27 06:42:24 +08:00
|
|
|
if not src.err.chkbox_helper(self.config.get_confirm_poweroff,
|
2011-04-15 04:43:17 +08:00
|
|
|
self.config.set_confirm_poweroff,
|
|
|
|
text1=_("Are you sure you want to poweroff '%s'?" %
|
|
|
|
vm.get_name())):
|
|
|
|
return
|
2009-07-15 02:48:09 +08:00
|
|
|
|
2012-01-17 11:04:40 +08:00
|
|
|
logging.debug("Shutting down vm '%s'", vm.get_name())
|
2011-04-16 03:23:13 +08:00
|
|
|
vmmAsyncJob.simple_async_noshow(vm.shutdown, [], src,
|
|
|
|
_("Error shutting down domain"))
|
2007-11-28 00:31:30 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_reboot_domain(self, src, uri, connkey):
|
2011-07-23 04:43:26 +08:00
|
|
|
conn = self._lookup_conn(uri)
|
2014-06-03 05:17:47 +08:00
|
|
|
vm = conn.get_vm(connkey)
|
2009-11-19 05:11:17 +08:00
|
|
|
|
2014-01-27 06:42:24 +08:00
|
|
|
if not src.err.chkbox_helper(self.config.get_confirm_poweroff,
|
2011-04-15 04:43:17 +08:00
|
|
|
self.config.set_confirm_poweroff,
|
|
|
|
text1=_("Are you sure you want to reboot '%s'?" %
|
|
|
|
vm.get_name())):
|
|
|
|
return
|
2009-07-15 02:48:09 +08:00
|
|
|
|
2012-01-17 11:04:40 +08:00
|
|
|
logging.debug("Rebooting vm '%s'", vm.get_name())
|
2015-04-11 23:09:09 +08:00
|
|
|
vmmAsyncJob.simple_async_noshow(vm.reboot, [], src,
|
|
|
|
_("Error rebooting domain"))
|
2008-04-09 02:30:47 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_reset_domain(self, src, uri, connkey):
|
2013-03-17 05:59:32 +08:00
|
|
|
conn = self._lookup_conn(uri)
|
2014-06-03 05:17:47 +08:00
|
|
|
vm = conn.get_vm(connkey)
|
2013-03-17 05:59:32 +08:00
|
|
|
|
2014-01-27 06:42:24 +08:00
|
|
|
if not src.err.chkbox_helper(
|
2013-08-09 21:23:01 +08:00
|
|
|
self.config.get_confirm_forcepoweroff,
|
2013-03-17 05:59:32 +08:00
|
|
|
self.config.set_confirm_forcepoweroff,
|
|
|
|
text1=_("Are you sure you want to force reset '%s'?" %
|
|
|
|
vm.get_name()),
|
|
|
|
text2=_("This will immediately reset the VM without "
|
|
|
|
"shutting down the OS and may cause data loss.")):
|
|
|
|
return
|
|
|
|
|
|
|
|
logging.debug("Resetting vm '%s'", vm.get_name())
|
|
|
|
vmmAsyncJob.simple_async_noshow(vm.reset, [], src,
|
|
|
|
_("Error resetting domain"))
|
2013-06-18 04:29:51 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
def _do_delete_domain(self, src, uri, connkey):
|
2013-06-18 04:29:51 +08:00
|
|
|
conn = self._lookup_conn(uri)
|
2014-06-03 05:17:47 +08:00
|
|
|
vm = conn.get_vm(connkey)
|
2013-06-18 04:29:51 +08:00
|
|
|
|
2014-05-01 03:54:00 +08:00
|
|
|
try:
|
|
|
|
if not self.delete_dialog:
|
|
|
|
self.delete_dialog = vmmDeleteDialog()
|
|
|
|
self.delete_dialog.show(vm, src.topwin)
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2014-05-01 03:54:00 +08:00
|
|
|
src.err.show_err(_("Error launching delete dialog: %s") % str(e))
|