2014-06-26 13:51:38 +04:00
# Copyright (C) 2006, 2013-2014 Red Hat, Inc.
2006-06-28 23:50:17 +04:00
# Copyright (C) 2006 Daniel P. Berrange <berrange@redhat.com>
#
2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2007-11-20 19:12:20 +03:00
2017-10-11 14:35:53 +03:00
import queue
2009-07-12 05:23:16 +04:00
import threading
2006-06-14 18:59:40 +04:00
2016-06-07 18:33:21 +03:00
from gi . repository import Gio
from gi . repository import GLib
from gi . repository import Gtk
2019-06-17 04:12:39 +03:00
from virtinst import log
2014-09-13 00:10:45 +04:00
from . baseclass import vmmGObject
2019-06-17 05:03:25 +03:00
from . createconn import vmmCreateConn
2018-03-16 04:22:14 +03:00
from . connmanager import vmmConnectionManager
2019-06-17 05:19:17 +03:00
from . lib . inspection import vmmInspection
2018-03-17 18:46:38 +03:00
from . systray import vmmSystray
2006-06-14 18:59:40 +04:00
2013-07-07 17:42:21 +04:00
( PRIO_HIGH ,
PRIO_LOW ) = range ( 1 , 3 )
2013-04-13 22:34:52 +04:00
2018-03-17 23:21:27 +03:00
def _show_startup_error ( fn ) :
"""
Decorator to show a modal error dialog if an exception is raised
from a startup routine
"""
# pylint: disable=protected-access
def newfn ( self , * args , * * kwargs ) :
try :
return fn ( self , * args , * * kwargs )
except Exception as e :
modal = self . _can_exit ( )
self . err . show_err ( str ( e ) , modal = modal )
self . _exit_app_if_no_windows ( )
return newfn
2010-12-09 20:37:48 +03:00
class vmmEngine ( vmmGObject ) :
2018-01-09 20:58:38 +03:00
CLI_SHOW_MANAGER = " manager "
2015-11-24 23:21:26 +03:00
CLI_SHOW_DOMAIN_CREATOR = " creator "
CLI_SHOW_DOMAIN_EDITOR = " editor "
CLI_SHOW_DOMAIN_PERFORMANCE = " performance "
CLI_SHOW_DOMAIN_CONSOLE = " console "
2019-03-04 21:34:22 +03:00
CLI_SHOW_DOMAIN_DELETE = " delete "
2015-11-24 23:21:26 +03:00
CLI_SHOW_HOST_SUMMARY = " summary "
2021-11-04 03:45:04 +03:00
CLI_SHOW_SYSTEM_TRAY = " systray "
2015-11-24 23:21:26 +03:00
2018-03-15 01:43:47 +03:00
@classmethod
def get_instance ( cls ) :
if not cls . _instance :
2018-03-17 23:08:20 +03:00
cls . _instance = vmmEngine ( )
2018-03-15 01:43:47 +03:00
return cls . _instance
2018-03-15 14:43:56 +03:00
__gsignals__ = {
" app-closing " : ( vmmGObject . RUN_FIRST , None , [ ] ) ,
}
2010-12-09 20:37:48 +03:00
def __init__ ( self ) :
vmmGObject . __init__ ( self )
2009-11-15 23:17:03 +03:00
2018-03-15 12:53:58 +03:00
self . _exiting = False
2015-12-03 23:54:52 +03:00
2018-03-15 12:53:58 +03:00
self . _window_count = 0
2015-12-03 23:54:52 +03:00
self . _gtkapplication = None
self . _init_gtk_application ( )
2009-07-28 06:30:01 +04:00
2018-03-15 12:53:58 +03:00
self . _timer = None
2013-07-07 04:03:42 +04:00
self . _tick_counter = 0
2009-07-12 05:23:16 +04:00
self . _tick_thread_slow = False
2013-07-07 04:03:42 +04:00
self . _tick_thread = threading . Thread ( name = " Tick thread " ,
target = self . _handle_tick_queue ,
args = ( ) )
self . _tick_thread . daemon = True
2017-10-11 14:35:53 +03:00
self . _tick_queue = queue . PriorityQueue ( 100 )
2009-07-12 05:23:16 +04:00
2010-03-04 00:58:50 +03:00
2018-03-14 17:29:20 +03:00
@property
2018-03-14 20:13:22 +03:00
def _connobjs ( self ) :
return vmmConnectionManager . get_instance ( ) . conns
2018-03-14 17:29:20 +03:00
2018-03-15 01:43:47 +03:00
def _cleanup ( self ) :
2020-09-19 21:08:10 +03:00
# self._timer should be automatically cleaned up
pass
2018-03-15 01:43:47 +03:00
#################
# init handling #
#################
2015-12-03 23:54:52 +03:00
2017-10-20 18:46:40 +03:00
def _default_startup ( self , skip_autostart , cliuri ) :
2018-03-15 01:43:47 +03:00
"""
Actual startup routines if we are running a new instance of the app
"""
2024-03-03 19:54:37 +03:00
vmmSystray . get_instance ( )
2018-03-15 01:43:47 +03:00
vmmInspection . get_instance ( )
self . add_gsettings_handle (
self . config . on_stats_update_interval_changed (
self . _timer_changed_cb ) )
self . _schedule_timer ( )
self . _tick_thread . start ( )
self . _tick ( )
2018-03-08 21:08:17 +03:00
2018-03-15 12:53:58 +03:00
uris = list ( self . _connobjs . keys ( ) )
2015-12-03 23:54:52 +03:00
if not uris :
2019-06-17 04:12:39 +03:00
log . debug ( " No stored URIs found. " )
2013-05-30 01:43:38 +04:00
else :
2019-06-17 04:12:39 +03:00
log . debug ( " Loading stored URIs: \n %s " ,
2015-12-03 23:54:52 +03:00
" \n " . join ( sorted ( uris ) ) )
2013-04-16 03:25:54 +04:00
2015-12-03 23:54:52 +03:00
if not skip_autostart :
2018-03-15 01:43:47 +03:00
self . idle_add ( self . _autostart_conns )
2013-04-16 03:25:54 +04:00
2017-10-20 18:46:40 +03:00
if not self . config . get_conn_uris ( ) and not cliuri :
2015-12-03 23:54:52 +03:00
# Only add default if no connections are currently known
2018-10-07 20:26:13 +03:00
manager = self . _get_manager ( )
manager . set_startup_error (
_ ( " Checking for virtualization packages... " ) )
2015-12-03 23:54:52 +03:00
self . timeout_add ( 1000 , self . _add_default_conn )
def _add_default_conn ( self ) :
2018-03-15 01:43:47 +03:00
"""
If there ' s no cached connections, or any requested on the command
2018-10-07 20:26:13 +03:00
line , try to determine a default URI and open it , first checking
if libvirt is running
2018-03-15 01:43:47 +03:00
"""
2020-08-29 19:34:44 +03:00
from . lib import connectauth
2010-03-04 00:58:50 +03:00
2023-09-12 20:18:42 +03:00
detected_uri = vmmCreateConn . default_uri ( )
log . debug ( " Probed default URI= %s " , detected_uri )
2020-08-29 20:07:19 +03:00
if self . config . CLITestOptions . firstrun_uri is not None :
2023-09-12 20:18:42 +03:00
detected_uri = self . config . CLITestOptions . firstrun_uri or None
log . debug ( " Using test-options firstrun_uri= %s " , detected_uri )
2018-10-07 20:26:13 +03:00
2020-08-29 19:34:44 +03:00
manager = self . _get_manager ( )
2023-09-12 20:18:42 +03:00
msg = connectauth . setup_first_uri ( self . config , detected_uri )
2018-10-07 20:26:13 +03:00
if msg :
2010-03-04 00:58:50 +03:00
manager . set_startup_error ( msg )
return
2018-10-07 20:26:13 +03:00
# Launch idle callback to connect to default URI
2013-06-14 01:35:48 +04:00
def idle_connect ( ) :
2018-03-16 04:22:14 +03:00
def _open_completed ( c , ConnectError ) :
if ConnectError :
self . _handle_conn_error ( c , ConnectError )
2013-06-14 01:35:48 +04:00
2023-09-12 20:18:42 +03:00
conn = vmmConnectionManager . get_instance ( ) . add_conn ( detected_uri )
2018-03-16 04:22:14 +03:00
conn . set_autoconnect ( True )
2018-03-17 01:00:09 +03:00
conn . connect_once ( " open-completed " , _open_completed )
2018-03-16 04:22:14 +03:00
conn . open ( )
2013-06-14 01:35:48 +04:00
self . idle_add ( idle_connect )
2010-03-04 00:58:50 +03:00
2018-03-15 01:43:47 +03:00
def _autostart_conns ( self ) :
2014-02-01 19:44:45 +04:00
"""
We serialize conn autostart , so polkit / ssh - askpass doesn ' t spam
"""
2018-03-15 14:43:56 +03:00
if self . _exiting :
2020-08-28 18:55:36 +03:00
return # pragma: no cover
2018-03-15 14:43:56 +03:00
2017-10-11 14:35:53 +03:00
connections_queue = queue . Queue ( )
2018-03-14 20:13:22 +03:00
auto_conns = [ conn . get_uri ( ) for conn in self . _connobjs . values ( ) if
conn . get_autoconnect ( ) ]
2014-02-01 19:44:45 +04:00
def add_next_to_queue ( ) :
if not auto_conns :
2017-10-11 14:35:53 +03:00
connections_queue . put ( None )
2014-02-01 19:44:45 +04:00
else :
2017-10-11 14:35:53 +03:00
connections_queue . put ( auto_conns . pop ( 0 ) )
2014-02-01 19:44:45 +04:00
2018-03-16 04:22:14 +03:00
def conn_open_completed ( _conn , ConnectError ) :
# Explicitly ignore connection errors, we've done that
# for a while and it can be noisy
2020-08-29 19:34:36 +03:00
if ConnectError is not None : # pragma: no cover
2019-06-17 04:12:39 +03:00
log . debug ( " Autostart connection error: %s " ,
2018-04-04 16:35:40 +03:00
ConnectError . details )
2018-03-16 04:22:14 +03:00
add_next_to_queue ( )
2014-02-01 19:44:45 +04:00
def handle_queue ( ) :
while True :
2017-10-11 14:35:53 +03:00
uri = connections_queue . get ( )
2014-02-01 19:44:45 +04:00
if uri is None :
return
2018-03-15 14:43:56 +03:00
if self . _exiting :
2020-08-29 19:34:36 +03:00
return # pragma: no cover
if uri not in self . _connobjs : # pragma: no cover
2014-02-01 19:44:45 +04:00
add_next_to_queue ( )
continue
2018-03-14 20:13:22 +03:00
conn = self . _connobjs [ uri ]
2018-03-17 01:00:09 +03:00
conn . connect_once ( " open-completed " , conn_open_completed )
2018-03-16 04:22:14 +03:00
self . idle_add ( conn . open )
2014-02-01 19:44:45 +04:00
add_next_to_queue ( )
2014-09-12 19:28:27 +04:00
self . _start_thread ( handle_queue , " Conn autostart thread " )
2008-03-24 18:39:19 +03:00
2006-06-14 22:36:26 +04:00
2018-03-15 01:43:47 +03:00
############################
# Gtk Application handling #
############################
2011-04-12 02:35:21 +04:00
2018-03-15 01:43:47 +03:00
def _on_gtk_application_activated ( self , ignore ) :
"""
Invoked after application . run ( )
"""
if not self . _application . get_windows ( ) :
2019-06-17 04:12:39 +03:00
log . debug ( " Initial gtkapplication activated " )
2018-03-15 01:43:47 +03:00
self . _application . add_window ( Gtk . Window ( ) )
2006-06-15 00:56:49 +04:00
2018-03-15 01:43:47 +03:00
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 )
2015-11-03 23:56:39 +03:00
2024-10-13 18:01:42 +03:00
# pylint: disable=no-member
2018-03-15 01:43:47 +03:00
action = Gio . SimpleAction . new ( " cli_command " ,
GLib . VariantType . new ( " (sss) " ) )
action . connect ( " activate " , self . _handle_cli_command )
self . _application . add_action ( action )
2015-11-03 23:56:39 +03:00
2018-03-15 01:43:47 +03:00
def start ( self , uri , show_window , domain , skip_autostart ) :
"""
Public entrypoint from virt - manager cli . If app is already
running , connect to it and exit , otherwise run our functional
default startup .
"""
# Dispatch dbus CLI command
if uri and not show_window :
show_window = self . CLI_SHOW_MANAGER
data = GLib . Variant ( " (sss) " ,
( uri or " " , show_window or " " , domain or " " ) )
2018-03-15 14:43:56 +03:00
is_remote = self . _application . get_is_remote ( )
if not is_remote :
self . _default_startup ( skip_autostart , uri )
2018-03-15 01:43:47 +03:00
self . _application . activate_action ( " cli_command " , data )
2018-03-15 14:43:56 +03:00
if is_remote :
2019-06-17 04:12:39 +03:00
log . debug ( " Connected to remote app instance. " )
2007-09-27 05:04:02 +04:00
return
2018-03-15 01:43:47 +03:00
self . _application . run ( None )
2011-04-12 02:35:21 +04:00
2018-03-15 01:43:47 +03:00
###########################
# timer and tick handling #
###########################
2007-09-27 05:04:02 +04:00
2018-03-15 01:43:47 +03:00
def _timer_changed_cb ( self , * args , * * kwargs ) :
2016-04-18 23:42:12 +03:00
ignore1 = args
ignore2 = kwargs
2018-03-15 01:43:47 +03:00
self . _schedule_timer ( )
2006-06-14 18:59:40 +04:00
2018-03-15 01:43:47 +03:00
def _schedule_timer ( self ) :
2010-12-09 22:06:00 +03:00
interval = self . config . get_stats_update_interval ( ) * 1000
2006-06-14 18:59:40 +04:00
2018-03-15 01:43:47 +03:00
if self . _timer is not None :
self . remove_gobject_timeout ( self . _timer )
self . _timer = None
2006-06-14 18:59:40 +04:00
2018-03-15 01:43:47 +03:00
self . _timer = self . timeout_add ( interval , self . _tick )
2006-06-14 18:59:40 +04:00
2013-07-07 19:06:15 +04:00
def _add_obj_to_tick_queue ( self , obj , isprio , * * kwargs ) :
2020-08-29 19:34:36 +03:00
if self . _tick_queue . full ( ) : # pragma: no cover
2009-07-14 17:45:23 +04:00
if not self . _tick_thread_slow :
2019-06-17 04:12:39 +03:00
log . debug ( " Tick is slow, not running at requested rate. " )
2009-10-01 20:04:03 +04:00
self . _tick_thread_slow = True
2013-07-07 04:03:42 +04:00
return
2009-07-12 05:23:16 +04:00
2013-07-07 04:03:42 +04:00
self . _tick_counter + = 1
2013-07-07 17:42:21 +04:00
self . _tick_queue . put ( ( isprio and PRIO_HIGH or PRIO_LOW ,
2013-07-07 19:06:15 +04:00
self . _tick_counter ,
obj , kwargs ) )
2007-03-10 00:22:43 +03:00
2018-03-16 04:22:14 +03:00
def schedule_priority_tick ( self , conn , kwargs ) :
# Called directly from connection
2013-07-07 19:06:15 +04:00
self . _add_obj_to_tick_queue ( conn , True , * * kwargs )
2013-07-07 04:03:42 +04:00
2018-03-15 01:43:47 +03:00
def _tick ( self ) :
2018-03-14 20:13:22 +03:00
for conn in self . _connobjs . values ( ) :
2013-07-07 19:06:15 +04:00
self . _add_obj_to_tick_queue ( conn , False ,
stats_update = True , pollvm = True )
2013-07-07 04:03:42 +04:00
return 1
2011-07-25 21:31:36 +04:00
2013-07-07 04:03:42 +04:00
def _handle_tick_queue ( self ) :
while True :
2014-04-16 18:32:52 +04:00
ignore1 , ignore2 , conn , kwargs = self . _tick_queue . get ( )
try :
2015-04-13 23:56:46 +03:00
conn . tick_from_engine ( * * kwargs )
2020-08-28 18:55:36 +03:00
except Exception : # pragma: no cover
2018-03-17 23:21:27 +03:00
# Don't attempt to show any UI error here, since it
# can cause dialogs to appear from nowhere if say
# libvirtd is shut down
2019-06-17 04:12:39 +03:00
log . debug ( " Error polling connection %s " ,
2018-03-17 23:21:27 +03:00
conn . get_uri ( ) , exc_info = True )
2018-10-13 21:27:10 +03:00
# Need to clear reference to make leak check happy
conn = None
2013-07-07 04:03:42 +04:00
self . _tick_queue . task_done ( )
2006-06-14 18:59:40 +04:00
2013-07-07 04:03:42 +04:00
2018-03-15 01:43:47 +03:00
#####################################
# window counting and exit handling #
#####################################
2018-03-15 02:06:30 +03:00
def increment_window_counter ( self ) :
"""
Public function , called by toplevel windows
"""
2018-03-15 12:53:58 +03:00
self . _window_count + = 1
2019-06-17 04:12:39 +03:00
log . debug ( " window counter incremented to %s " , self . _window_count )
2008-06-13 20:12:37 +04:00
2018-03-15 02:06:30 +03:00
def decrement_window_counter ( self ) :
"""
Public function , called by toplevel windows
"""
2018-03-15 12:53:58 +03:00
self . _window_count - = 1
2019-06-17 04:12:39 +03:00
log . debug ( " window counter decremented to %s " , self . _window_count )
2011-04-13 17:27:02 +04:00
2018-03-15 02:06:30 +03:00
self . _exit_app_if_no_windows ( )
2008-06-13 20:12:37 +04:00
2018-03-17 18:46:38 +03:00
def _systray_is_embedded ( self ) :
"""
We don ' t use window tracking here: systray isn ' t a window and even
when ' show ' has been requested it may not be embedded in a visible
tray area , so we have to check it separately .
"""
return vmmSystray . get_instance ( ) . is_embedded ( )
2024-03-03 19:54:37 +03:00
def _show_systray_from_cli ( self ) :
"""
Handler for - - show - systray from CLI .
We force show the systray , and wait for a timeout to report if
its embedded . If not we raise an error and exit the app
"""
vmmSystray . get_instance ( ) . show_from_cli ( )
@_show_startup_error
def check ( self , count ) :
count - = 1
if self . _systray_is_embedded ( ) :
log . debug ( " systray embedded " )
return
if count < = 0 : # pragma: no cover
raise RuntimeError ( " systray did not show up " )
self . timeout_add ( 1000 , check , self , count ) # pragma: no cover
startcount = 5
timeout = 1000
if self . config . CLITestOptions . fake_systray :
timeout = 1
self . timeout_add ( timeout , check , self , startcount )
2013-07-13 06:10:16 +04:00
def _can_exit ( self ) :
2018-03-17 18:46:38 +03:00
return ( self . _window_count < = 0 and not
self . _systray_is_embedded ( ) )
2013-07-13 06:10:16 +04:00
2018-03-15 02:06:30 +03:00
def _exit_app_if_no_windows ( self ) :
2018-03-18 01:47:13 +03:00
if self . _exiting :
return
2018-03-15 12:53:58 +03:00
if self . _can_exit ( ) :
2019-06-17 04:12:39 +03:00
log . debug ( " No windows found, requesting app exit " )
2018-03-15 12:53:58 +03:00
self . exit_app ( )
2015-12-03 23:54:52 +03:00
2018-03-15 01:58:22 +03:00
def exit_app ( self ) :
"""
Public call , manager / details / . . . use this to force exit the app
"""
2018-03-15 12:53:58 +03:00
if self . _exiting :
2020-08-28 18:55:36 +03:00
return # pragma: no cover
2011-04-13 17:27:02 +04:00
2018-03-15 14:43:56 +03:00
self . _exiting = True
2011-04-14 19:26:53 +04:00
2018-03-15 14:43:56 +03:00
def _do_exit ( ) :
try :
vmmConnectionManager . get_instance ( ) . cleanup ( )
self . emit ( " app-closing " )
self . cleanup ( )
2011-04-11 20:54:47 +04:00
2019-06-05 20:19:44 +03:00
if self . config . CLITestOptions . leak_debug :
2018-03-15 14:43:56 +03:00
objs = self . config . get_objects ( )
# Engine will always appear to leak
objs . remove ( self . object_key )
2008-06-13 20:12:37 +04:00
2020-08-28 18:55:36 +03:00
for name in objs : # pragma: no cover
2019-06-17 04:12:39 +03:00
log . debug ( " LEAK: %s " , name )
2015-04-11 21:34:38 +03:00
2019-06-17 04:12:39 +03:00
log . debug ( " Exiting app normally. " )
2018-03-15 14:43:56 +03:00
finally :
self . _application . quit ( )
2012-11-08 14:02:17 +04:00
2018-03-15 14:43:56 +03:00
# We stick this in an idle callback, so the exit_app() caller
# reference is dropped, and leak check debug doesn't give a
# false positive
self . idle_add ( _do_exit )
2010-11-24 02:54:12 +03:00
2017-02-23 13:22:27 +03:00
2010-11-24 04:13:50 +03:00
##########################################
# Window launchers from virt-manager cli #
##########################################
2014-06-03 01:17:47 +04: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 )
2018-03-14 20:13:22 +03:00
for vm in self . _connobjs [ uri ] . list_vms ( ) :
2014-06-03 01:17:47 +04:00
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 ) :
vm = self . _find_vm_by_cli_str ( uri , clistr )
if not vm :
2018-09-29 22:53:54 +03:00
raise RuntimeError ( " %s does not have VM ' %s ' " %
( uri , clistr ) )
2014-06-03 01:17:47 +04:00
2019-05-05 23:25:35 +03:00
from . vmwindow import vmmVMWindow
details = vmmVMWindow . get_instance ( None , vm )
2018-09-29 22:53:54 +03:00
if page == self . CLI_SHOW_DOMAIN_PERFORMANCE :
details . activate_performance_page ( )
2019-03-04 21:34:22 +03:00
elif ( page in [ self . CLI_SHOW_DOMAIN_EDITOR ,
self . CLI_SHOW_DOMAIN_DELETE ] ) :
2018-09-29 22:53:54 +03:00
details . activate_config_page ( )
elif page == self . CLI_SHOW_DOMAIN_CONSOLE :
details . activate_console_page ( )
details . show ( )
2018-03-15 12:53:58 +03:00
2019-03-04 21:34:22 +03:00
if page == self . CLI_SHOW_DOMAIN_DELETE :
from . delete import vmmDeleteDialog
vmmDeleteDialog . show_instance ( details , vm )
2018-03-15 12:53:58 +03:00
def _get_manager ( self ) :
from . manager import vmmManager
2018-03-17 01:58:11 +03:00
return vmmManager . get_instance ( None )
2010-11-24 02:54:12 +03:00
2018-03-17 23:21:27 +03:00
@_show_startup_error
2015-11-24 23:21:26 +03:00
def _launch_cli_window ( self , uri , show_window , clistr ) :
2019-06-17 04:12:39 +03:00
log . debug ( " Launching requested window ' %s ' " , show_window )
2018-03-17 23:21:27 +03:00
if show_window == self . CLI_SHOW_MANAGER :
manager = self . _get_manager ( )
manager . set_initial_selection ( uri )
manager . show ( )
elif show_window == self . CLI_SHOW_DOMAIN_CREATOR :
2019-06-17 05:00:57 +03:00
from . createvm import vmmCreateVM
vmmCreateVM . show_instance ( None , uri )
2018-03-17 23:21:27 +03:00
elif show_window == self . CLI_SHOW_HOST_SUMMARY :
from . host import vmmHost
vmmHost . show_instance ( None , self . _connobjs [ uri ] )
2018-09-29 22:53:54 +03:00
elif ( show_window in [ self . CLI_SHOW_DOMAIN_EDITOR ,
self . CLI_SHOW_DOMAIN_PERFORMANCE ,
2019-03-04 21:34:22 +03:00
self . CLI_SHOW_DOMAIN_CONSOLE ,
self . CLI_SHOW_DOMAIN_DELETE ] ) :
2018-09-29 22:53:54 +03:00
self . _cli_show_vm_helper ( uri , clistr , show_window )
2021-11-04 03:45:04 +03:00
elif show_window == self . CLI_SHOW_SYSTEM_TRAY :
2024-03-03 19:54:37 +03:00
# Handled elsewhere
pass
2020-08-28 18:55:36 +03:00
else : # pragma: no cover
2018-03-17 23:21:27 +03:00
raise RuntimeError ( " Unknown cli window command ' %s ' " %
show_window )
2015-11-24 23:21:26 +03:00
2018-03-16 04:22:14 +03:00
def _handle_conn_error ( self , _conn , ConnectError ) :
msg , details , title = ConnectError
modal = self . _can_exit ( )
self . err . show_err ( msg , details , title , modal = modal )
self . _exit_app_if_no_windows ( )
2015-11-24 23:21:26 +03:00
2018-03-17 23:21:27 +03:00
@_show_startup_error
def _handle_cli_command ( self , actionobj , variant ) :
2015-12-03 23:54:52 +03:00
ignore = actionobj
uri = variant [ 0 ]
2018-03-16 04:22:14 +03:00
show_window = variant [ 1 ] or self . CLI_SHOW_MANAGER
2015-12-03 23:54:52 +03:00
domain = variant [ 2 ]
2015-11-24 23:21:26 +03:00
2019-06-17 04:12:39 +03:00
log . debug ( " processing cli command uri= %s show_window= %s domain= %s " ,
2015-12-03 23:54:52 +03:00
uri , show_window , domain )
2021-11-04 03:45:04 +03:00
2024-03-03 19:54:37 +03:00
if show_window == self . CLI_SHOW_SYSTEM_TRAY :
log . debug ( " Launching only in the system tray " )
self . _show_systray_from_cli ( )
if not uri :
return
elif not uri :
2019-06-17 04:12:39 +03:00
log . debug ( " No cli action requested, launching default window " )
2018-03-15 12:53:58 +03:00
self . _get_manager ( ) . show ( )
2015-11-24 23:21:26 +03:00
return
2018-03-17 00:33:06 +03:00
conn_is_new = uri not in self . _connobjs
2018-03-16 04:22:14 +03:00
conn = vmmConnectionManager . get_instance ( ) . add_conn ( uri )
if conn . is_active ( ) :
self . idle_add ( self . _launch_cli_window ,
uri , show_window , domain )
return
2015-12-03 23:54:52 +03:00
2018-03-16 04:22:14 +03:00
def _open_completed ( _c , ConnectError ) :
if ConnectError :
2018-03-17 00:33:06 +03:00
if conn_is_new :
2019-06-17 04:12:39 +03:00
log . debug ( " Removing failed uri= %s " , uri )
2018-03-17 00:33:06 +03:00
vmmConnectionManager . get_instance ( ) . remove_conn ( uri )
2018-03-16 04:22:14 +03:00
self . _handle_conn_error ( conn , ConnectError )
2015-11-24 23:21:26 +03:00
else :
2018-03-16 04:22:14 +03:00
self . _launch_cli_window ( uri , show_window , domain )
2018-03-17 01:00:09 +03:00
conn . connect_once ( " open-completed " , _open_completed )
2018-03-16 04:22:14 +03:00
conn . open ( )