2006-06-28 23:50:17 +04:00
#
# Copyright (C) 2006 Red Hat, Inc.
# 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-20 19:12:20 +03:00
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
2006-06-28 23:50:17 +04:00
#
2007-11-20 19:12:20 +03:00
2006-06-14 18:59:40 +04:00
import gobject
2006-06-14 22:36:26 +04:00
import gtk
2009-11-16 04:54:55 +03:00
2006-09-26 02:41:47 +04:00
import logging
2007-03-22 18:11:05 +03:00
import traceback
2009-07-12 05:23:16 +04:00
import threading
2010-03-04 00:58:50 +03:00
import os
2006-06-14 18:59:40 +04:00
2009-11-16 04:54:55 +03:00
import libvirt
import virtinst
2010-03-04 00:58:50 +03:00
import dbus
2009-11-16 04:54:55 +03:00
2006-06-14 18:59:40 +04:00
from virtManager . about import vmmAbout
2010-12-09 20:37:48 +03:00
from virtManager . baseclass import vmmGObject
2009-07-26 23:54:14 +04:00
from virtManager . clone import vmmCloneVM
2006-06-14 18:59:40 +04:00
from virtManager . connect import vmmConnect
from virtManager . connection import vmmConnection
2010-12-11 00:04:42 +03:00
from virtManager . createmeter import vmmCreateMeter
2006-06-14 18:59:40 +04:00
from virtManager . preferences import vmmPreferences
2006-06-15 00:20:06 +04:00
from virtManager . manager import vmmManager
2009-11-15 23:17:03 +03:00
from virtManager . migrate import vmmMigrateDialog
2006-06-15 00:20:06 +04:00
from virtManager . details import vmmDetails
2006-07-24 21:50:11 +04:00
from virtManager . asyncjob import vmmAsyncJob
2006-08-09 01:02:15 +04:00
from virtManager . create import vmmCreate
2007-03-28 03:52:00 +04:00
from virtManager . host import vmmHost
2007-11-27 19:31:30 +03:00
from virtManager . error import vmmErrorDialog
2009-07-28 06:30:01 +04:00
from virtManager . systray import vmmSystray
2011-04-13 17:27:02 +04:00
import virtManager . uihelpers as uihelpers
2009-01-26 19:12:43 +03:00
import virtManager . util as util
2006-06-14 18:59:40 +04:00
2011-04-11 20:54:47 +04:00
# Enable this to get a report of leaked objects on app shutdown
2011-04-13 17:27:02 +04:00
debug_ref_leaks = True
2011-04-11 20:54:47 +04:00
2010-03-04 00:58:50 +03:00
def default_uri ( ) :
tryuri = None
if os . path . exists ( " /var/lib/xend " ) and os . path . exists ( " /proc/xen " ) :
tryuri = " xen:/// "
2010-05-12 21:21:37 +04:00
elif ( os . path . exists ( " /dev/kvm " ) or
os . path . exists ( " /usr/bin/qemu " ) or
2010-03-04 00:58:50 +03:00
os . path . exists ( " /usr/bin/qemu-kvm " ) or
2010-05-12 21:21:37 +04:00
os . path . exists ( " /usr/bin/kvm " ) or
os . path . exists ( " /usr/libexec/qemu-kvm " ) ) :
2010-03-04 00:58:50 +03:00
tryuri = " qemu:///system "
return tryuri
#############################
# PackageKit lookup helpers #
#############################
2011-01-14 23:19:58 +03:00
def check_packagekit ( errbox , packages , libvirt_packages ) :
2010-03-04 00:58:50 +03:00
"""
Returns None when we determine nothing useful .
Returns ( success , did we just install libvirt ) otherwise .
"""
2011-01-14 23:19:58 +03:00
if not packages :
2010-05-12 21:41:46 +04:00
logging . debug ( " No PackageKit packages to search for. " )
2010-03-04 00:58:50 +03:00
return
logging . debug ( " Asking PackageKit what ' s installed locally. " )
try :
session = dbus . SystemBus ( )
pk_control = dbus . Interface (
session . get_object ( " org.freedesktop.PackageKit " ,
" /org/freedesktop/PackageKit " ) ,
" org.freedesktop.PackageKit " )
except Exception :
logging . exception ( " Couldn ' t connect to packagekit " )
return
found = [ ]
2010-12-09 20:37:48 +03:00
progWin = vmmAsyncJob ( _do_async_search ,
2011-01-14 23:19:58 +03:00
[ session , pk_control , packages ] ,
2010-03-04 00:58:50 +03:00
_ ( " Searching for available hypervisors... " ) ,
2010-12-10 17:57:42 +03:00
_ ( " Searching for available hypervisors... " ) ,
2010-03-04 00:58:50 +03:00
run_main = False )
2010-12-10 17:57:42 +03:00
error , ignore = progWin . run ( )
2010-03-04 00:58:50 +03:00
if error :
return
found = progWin . get_data ( )
2011-01-14 23:19:58 +03:00
not_found = filter ( lambda x : x not in found , packages )
2010-03-04 00:58:50 +03:00
logging . debug ( " Missing packages: %s " % not_found )
do_install = not_found
if not do_install :
if not not_found :
# Got everything we wanted, try to connect
logging . debug ( " All packages found locally. " )
return ( True , False )
else :
logging . debug ( " No packages are available for install. " )
return
msg = ( _ ( " The following packages are not installed: \n %s \n \n "
" These are required to create KVM guests locally. \n "
" Would you like to install them now? " ) %
reduce ( lambda x , y : x + " \n " + y , do_install , " " ) )
ret = errbox . yes_no ( _ ( " Packages required for KVM usage " ) , msg )
if not ret :
logging . debug ( " Package install declined. " )
return
try :
packagekit_install ( do_install )
except Exception , e :
2011-04-06 19:22:03 +04:00
errbox . show_err ( _ ( " Error talking to PackageKit: %s " ) % str ( e ) )
2010-03-04 00:58:50 +03:00
return
2011-01-14 23:19:58 +03:00
need_libvirt = False
for p in libvirt_packages :
if p in do_install :
need_libvirt = True
break
return ( True , need_libvirt )
2010-03-04 00:58:50 +03:00
2011-01-14 23:19:58 +03:00
def _do_async_search ( asyncjob , session , pk_control , packages ) :
2010-03-04 00:58:50 +03:00
found = [ ]
try :
2011-01-14 23:19:58 +03:00
for name in packages :
ret_found = packagekit_search ( session , pk_control , name , packages )
2010-03-04 00:58:50 +03:00
found + = ret_found
except Exception , e :
logging . exception ( " Error searching for installed packages " )
asyncjob . set_error ( str ( e ) , " " . join ( traceback . format_exc ( ) ) )
asyncjob . set_data ( found )
def packagekit_install ( package_list ) :
session = dbus . SessionBus ( )
pk_control = dbus . Interface (
session . get_object ( " org.freedesktop.PackageKit " ,
" /org/freedesktop/PackageKit " ) ,
" org.freedesktop.PackageKit.Modify " )
2011-03-23 19:20:55 +03:00
# Set 2 hour timeout
timeout = 60 * 60 * 2
2010-03-04 00:58:50 +03:00
logging . debug ( " Installing packages: %s " % package_list )
2011-03-23 19:20:55 +03:00
pk_control . InstallPackageNames ( 0 , package_list , " hide-confirm-search " ,
timeout = timeout )
2010-03-04 00:58:50 +03:00
2011-01-14 23:19:58 +03:00
def packagekit_search ( session , pk_control , package_name , packages ) :
2010-03-04 00:58:50 +03:00
tid = pk_control . GetTid ( )
pk_trans = dbus . Interface (
session . get_object ( " org.freedesktop.PackageKit " , tid ) ,
" org.freedesktop.PackageKit.Transaction " )
found = [ ]
def package ( info , package_id , summary ) :
2010-12-09 19:22:35 +03:00
ignore = info
ignore = summary
2010-03-04 00:58:50 +03:00
found_name = str ( package_id . split ( " ; " ) [ 0 ] )
2011-01-14 23:19:58 +03:00
if found_name in packages :
2010-03-04 00:58:50 +03:00
found . append ( found_name )
def error ( code , details ) :
raise RuntimeError ( " PackageKit search failure: %s %s " %
( code , details ) )
2010-12-09 19:22:35 +03:00
def finished ( ignore , runtime_ignore ) :
2010-03-04 00:58:50 +03:00
gtk . main_quit ( )
pk_trans . connect_to_signal ( ' Finished ' , finished )
pk_trans . connect_to_signal ( ' ErrorCode ' , error )
pk_trans . connect_to_signal ( ' Package ' , package )
2010-05-12 21:41:46 +04:00
try :
pk_trans . SearchNames ( " installed " , [ package_name ] )
except dbus . exceptions . DBusException , e :
if e . get_dbus_name ( ) != " org.freedesktop.DBus.Error.UnknownMethod " :
raise
# Try older search API
pk_trans . SearchName ( " installed " , package_name )
2010-03-04 00:58:50 +03:00
# Call main() so this function is synchronous
gtk . main ( )
return found
2010-12-09 20:37:48 +03:00
class vmmEngine ( vmmGObject ) :
2007-09-10 06:57:24 +04:00
__gsignals__ = {
" connection-added " : ( gobject . SIGNAL_RUN_FIRST , gobject . TYPE_NONE ,
[ object ] ) ,
" connection-removed " : ( gobject . SIGNAL_RUN_FIRST , gobject . TYPE_NONE ,
2011-04-12 19:50:10 +04:00
[ str ] )
2007-09-10 06:57:24 +04:00
}
2010-12-09 20:37:48 +03:00
def __init__ ( self ) :
vmmGObject . __init__ ( self )
2009-11-15 23:17:03 +03:00
2006-06-15 00:20:06 +04:00
self . windowConnect = None
2006-06-14 18:59:40 +04:00
self . windowPreferences = None
self . windowAbout = None
2006-08-09 01:02:15 +04:00
self . windowCreate = None
2007-08-10 00:19:41 +04:00
self . windowManager = None
2009-11-15 23:17:03 +03:00
self . windowMigrate = None
2006-06-14 18:59:40 +04:00
self . connections = { }
2010-11-30 22:33:21 +03:00
self . err = vmmErrorDialog ( )
2006-06-14 18:59:40 +04:00
self . timer = None
self . last_timeout = 0
2009-07-28 06:30:01 +04:00
self . systray = None
2009-07-12 05:23:16 +04:00
self . _tick_thread = None
self . _tick_thread_slow = False
2009-11-16 04:54:55 +03:00
self . _libvirt_support_threading = virtinst . support . support_threading ( )
2009-07-12 05:23:16 +04:00
if not self . _libvirt_support_threading :
logging . debug ( " Libvirt doesn ' t support threading, skipping. " )
2008-06-13 20:12:37 +04:00
# Counter keeping track of how many manager and details windows
2009-10-29 18:08:40 +03:00
# are open. When it is decremented to 0, close the app or
# keep running in system tray if enabled
2008-06-13 20:12:37 +04:00
self . windows = 0
2009-07-28 06:30:01 +04:00
self . init_systray ( )
2009-07-01 22:59:13 +04:00
2011-04-13 17:27:02 +04:00
self . add_gconf_handle (
self . config . on_stats_update_interval_changed ( self . reschedule_timer ) )
self . add_gconf_handle (
self . config . on_view_system_tray_changed ( self . system_tray_changed ) )
2006-06-14 18:59:40 +04:00
self . schedule_timer ( )
2007-09-10 06:57:24 +04:00
self . load_stored_uris ( )
2006-06-14 18:59:40 +04:00
self . tick ( )
2010-03-04 00:58:50 +03:00
2009-07-28 06:30:01 +04:00
def init_systray ( self ) :
if self . systray :
return
2010-12-09 22:06:00 +03:00
self . systray = vmmSystray ( self )
2009-10-29 18:08:40 +03:00
self . systray . connect ( " action-toggle-manager " , self . _do_toggle_manager )
2009-07-28 06:30:01 +04: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 )
self . systray . connect ( " action-show-console " , self . _do_show_console )
self . systray . connect ( " action-show-details " , self . _do_show_details )
2010-11-24 04:13:50 +03:00
self . systray . connect ( " action-exit-app " , self . exit_app )
2009-07-28 06:30:01 +04:00
2009-10-29 18:08:40 +03: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
self . show_manager ( )
2010-11-24 02:54:12 +03:00
########################
# First run PackageKit #
########################
2010-03-04 00:58:50 +03:00
def add_default_connection ( self ) :
# Only add default if no connections are currently known
if self . config . get_connections ( ) :
return
# Manager fail message
msg = _ ( " Could not detect a default hypervisor. Make \n "
" sure the appropriate virtualization packages \n "
" are installed (kvm, qemu, libvirt, etc.), and \n "
" that libvirtd is running. \n \n "
" A hypervisor connection can be manually \n "
" added via File->Add Connection " )
manager = self . get_manager ( )
logging . debug ( " Determining default libvirt URI " )
ret = None
did_install_libvirt = False
try :
2011-01-14 23:19:58 +03:00
libvirt_packages = self . config . libvirt_packages
packages = self . config . hv_packages + libvirt_packages
ret = check_packagekit ( self . err , packages , libvirt_packages )
2010-03-04 00:58:50 +03:00
except :
logging . exception ( " Error talking to PackageKit " )
if ret :
# We found the default packages via packagekit: use default URI
ignore , did_install_libvirt = ret
tryuri = " qemu:///system "
else :
tryuri = default_uri ( )
if tryuri is None :
manager . set_startup_error ( msg )
return
if did_install_libvirt :
warnmsg = _ (
" Libvirt was just installed, so the ' libvirtd ' service will \n "
" will need to be started. This can be done with one \n "
" of the following: \n \n "
" - From GNOME menus: System->Administration->Services \n "
" - From the terminal: su -c ' service libvirtd restart ' \n "
" - Restart your computer \n \n "
" virt-manager will connect to libvirt on the next application \n "
" start up. " )
self . err . ok ( _ ( " Libvirt service must be started " ) , warnmsg )
self . connect_to_uri ( tryuri , autoconnect = True ,
do_start = not did_install_libvirt )
2007-08-29 01:57:25 +04:00
def load_stored_uris ( self ) :
uris = self . config . get_connections ( )
if uris != None :
logging . debug ( " About to connect to uris %s " % uris )
for uri in uris :
2007-09-10 06:57:24 +04:00
self . add_connection ( uri )
2007-08-29 01:57:25 +04:00
2008-03-24 18:39:19 +03:00
def autostart_connections ( self ) :
for uri in self . connections :
conn = self . connections [ uri ] [ " connection " ]
if conn . get_autoconnect ( ) :
self . connect_to_uri ( uri )
2010-03-04 00:58:50 +03:00
def connect_to_uri ( self , uri , readOnly = None , autoconnect = False ,
do_start = True ) :
2006-06-27 18:08:55 +04:00
try :
2010-03-24 17:57:42 +03:00
conn = self . _check_connection ( uri )
if not conn :
# Unknown connection, add it
2009-07-14 22:48:09 +04:00
conn = self . add_connection ( uri , readOnly , autoconnect )
2007-08-10 00:19:41 +04:00
self . show_manager ( )
2010-03-04 00:58:50 +03:00
if do_start :
conn . open ( )
2007-08-17 00:38:24 +04:00
return conn
2009-10-29 03:35:13 +03:00
except Exception :
2010-03-24 17:57:42 +03:00
logging . exception ( " Error connecting to %s " % uri )
2007-08-17 00:38:24 +04:00
return None
2006-06-14 22:36:26 +04:00
2010-12-09 19:22:35 +03:00
def _do_connect ( self , src_ignore , uri ) :
2010-11-24 04:13:50 +03:00
return self . connect_to_uri ( uri )
2011-04-13 17:27:02 +04:00
def _connect_cancelled ( self , src ) :
2006-06-27 18:08:55 +04:00
if len ( self . connections . keys ( ) ) == 0 :
2011-04-13 17:27:02 +04:00
self . exit_app ( src )
2006-06-14 22:36:26 +04:00
2006-06-15 00:56:49 +04:00
def _do_vm_removed ( self , connection , hvuri , vmuuid ) :
2010-12-09 19:22:35 +03:00
ignore = connection
2011-04-12 02:35:21 +04:00
if vmuuid not in self . connections [ hvuri ] [ " windowDetails " ] :
return
self . connections [ hvuri ] [ " windowDetails " ] [ vmuuid ] . cleanup ( )
del ( self . connections [ hvuri ] [ " windowDetails " ] [ vmuuid ] )
2006-06-15 00:56:49 +04:00
2007-09-27 05:04:02 +04:00
def _do_connection_changed ( self , connection ) :
2011-04-12 02:35:21 +04:00
if ( connection . get_state ( ) == connection . STATE_ACTIVE or
connection . get_state ( ) == connection . STATE_CONNECTING ) :
2007-09-27 05:04:02 +04:00
return
hvuri = connection . get_uri ( )
2011-04-12 02:35:21 +04:00
2007-09-27 05:04:02 +04:00
for vmuuid in self . connections [ hvuri ] [ " windowDetails " ] . keys ( ) :
2011-04-12 02:35:21 +04:00
self . connections [ hvuri ] [ " windowDetails " ] [ vmuuid ] . cleanup ( )
del ( self . connections [ hvuri ] [ " windowDetails " ] [ vmuuid ] )
if ( self . windowCreate and
self . windowCreate . conn and
2009-03-09 23:16:45 +03:00
self . windowCreate . conn . get_uri ( ) == hvuri ) :
self . windowCreate . close ( )
2007-09-27 05:04:02 +04:00
2010-11-29 22:06:43 +03:00
def reschedule_timer ( self , ignore1 , ignore2 , ignore3 , ignore4 ) :
2006-06-14 18:59:40 +04:00
self . schedule_timer ( )
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
if self . timer != None :
gobject . source_remove ( self . timer )
self . timer = None
2010-02-11 20:32:00 +03:00
# No need to use 'safe_timeout_add', the tick should be
# manually made thread safe
2006-06-14 18:59:40 +04:00
self . timer = gobject . timeout_add ( interval , self . tick )
def tick ( self ) :
2009-07-12 05:23:16 +04:00
if not self . _libvirt_support_threading :
2007-03-13 18:48:19 +03:00
return self . _tick ( )
2009-07-12 05:23:16 +04:00
if self . _tick_thread and self . _tick_thread . isAlive ( ) :
2009-07-14 17:45:23 +04:00
if not self . _tick_thread_slow :
2009-07-12 05:23:16 +04:00
logging . debug ( " Tick is slow, not running at requested rate. " )
2009-10-01 20:04:03 +04:00
self . _tick_thread_slow = True
2009-07-12 05:23:16 +04:00
return 1
self . _tick_thread = threading . Thread ( name = " Tick thread " ,
target = self . _tick , args = ( ) )
2010-02-11 20:32:00 +03:00
self . _tick_thread . daemon = True
2009-07-12 05:23:16 +04:00
self . _tick_thread . start ( )
return 1
2007-03-10 00:22:43 +03:00
def _tick ( self ) :
2006-06-14 18:59:40 +04:00
for uri in self . connections . keys ( ) :
2010-01-26 20:24:33 +03:00
conn = self . connections [ uri ] [ " connection " ]
2006-06-14 18:59:40 +04:00
try :
2010-01-26 20:24:33 +03:00
conn . tick ( )
2006-07-11 23:36:54 +04:00
except KeyboardInterrupt :
2008-11-19 01:01:22 +03:00
raise
2009-09-17 00:02:19 +04:00
except libvirt . libvirtError , e :
2010-04-21 18:08:04 +04:00
if ( e . get_error_domain ( ) == libvirt . VIR_FROM_REMOTE and
e . get_error_code ( ) == libvirt . VIR_ERR_SYSTEM_ERROR ) :
2009-09-17 00:02:19 +04:00
logging . exception ( " Could not refresh connection %s . " % uri )
logging . debug ( " Closing connection since libvirtd "
" appears to have stopped. " )
2010-02-11 20:32:00 +03:00
util . safe_idle_add ( conn . close )
2009-09-17 00:02:19 +04:00
else :
raise
2006-06-14 18:59:40 +04:00
return 1
2010-11-24 02:54:12 +03:00
def change_timer_interval ( self , ignore1 , ignore2 , ignore3 , ignore4 ) :
2006-06-14 18:59:40 +04:00
gobject . source_remove ( self . timer )
self . schedule_timer ( )
2008-06-13 20:12:37 +04:00
def increment_window_counter ( self ) :
self . windows + = 1
logging . debug ( " window counter incremented to %s " % self . windows )
def decrement_window_counter ( self ) :
self . windows - = 1
logging . debug ( " window counter decremented to %s " % self . windows )
2011-04-13 17:27:02 +04:00
2009-10-29 18:08:40 +03:00
# Don't exit if system tray is enabled
2011-04-13 17:27:02 +04:00
if ( self . windows < = 0 and
self . systray and
not self . systray . is_visible ( ) ) :
2008-06-13 22:40:26 +04:00
self . exit_app ( )
2008-06-13 20:12:37 +04:00
2011-04-13 17:27:02 +04:00
def cleanup ( self ) :
try :
vmmGObject . cleanup ( self )
uihelpers . cleanup ( )
self . err = None
if self . timer != None :
gobject . source_remove ( self . timer )
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
# Do this last, so any manually 'disconnected' signals
# take precedence over cleanup signal removal
for uri in self . connections :
self . cleanup_connection ( uri )
self . connections = { }
except :
logging . exception ( " Error cleaning up engine " )
def exit_app ( self , src = None ) :
if self . err is None :
# Already in cleanup
return
self . cleanup ( )
2011-04-11 20:54:47 +04:00
if debug_ref_leaks :
2011-04-13 17:27:02 +04:00
objs = self . config . get_objects ( )
if src and src . object_key in objs :
# Whatever UI initiates the app exit will always appear
# to leak
logging . debug ( " Exitting app from %s , skipping leak check " %
src . object_key )
objs . remove ( src . object_key )
# Engine will always appear to leak
objs . remove ( self . object_key )
for name in objs :
2011-04-11 20:54:47 +04:00
logging . debug ( " Leaked %s " % name )
2008-10-30 16:25:53 +03:00
logging . debug ( " Exiting app normally. " )
2008-06-13 22:40:26 +04:00
gtk . main_quit ( )
2008-06-13 20:12:37 +04:00
2008-06-11 22:59:50 +04:00
def add_connection ( self , uri , readOnly = None , autoconnect = False ) :
2010-11-30 02:00:15 +03:00
conn = self . _check_connection ( uri )
if conn :
return conn
2010-12-09 22:06:00 +03:00
conn = vmmConnection ( uri , readOnly = readOnly )
2007-09-10 06:57:24 +04:00
self . connections [ uri ] = {
" connection " : conn ,
" windowHost " : None ,
" windowDetails " : { } ,
2009-07-26 23:54:14 +04:00
" windowClone " : None ,
2011-04-12 20:06:44 +04:00
}
2010-11-24 02:54:12 +03:00
conn . connect ( " vm-removed " , self . _do_vm_removed )
conn . connect ( " state-changed " , self . _do_connection_changed )
conn . tick ( )
2007-09-10 06:57:24 +04:00
self . emit ( " connection-added " , conn )
self . config . add_connection ( conn . get_uri ( ) )
2010-11-24 02:54:12 +03:00
2008-06-11 22:59:50 +04:00
if autoconnect :
2009-12-10 20:28:55 +03:00
conn . set_autoconnect ( True )
2007-09-10 06:57:24 +04:00
2009-07-14 22:48:09 +04:00
return conn
2011-04-13 17:27:02 +04:00
def cleanup_connection ( self , uri ) :
try :
if self . connections [ uri ] [ " windowHost " ] :
self . connections [ uri ] [ " windowHost " ] . cleanup ( )
if self . connections [ uri ] [ " windowClone " ] :
self . connections [ uri ] [ " windowClone " ] . cleanup ( )
details = self . connections [ uri ] [ " windowDetails " ]
for win in details . values ( ) :
win . cleanup ( )
self . connections [ uri ] [ " connection " ] . cleanup ( )
except :
logging . exception ( " Error cleaning up conn in engine " )
2007-09-10 06:57:24 +04:00
def remove_connection ( self , uri ) :
2011-04-13 17:27:02 +04:00
self . cleanup_connection ( uri )
del ( self . connections [ uri ] )
2011-04-12 19:50:10 +04:00
self . emit ( " connection-removed " , uri )
2011-04-13 17:27:02 +04:00
self . config . remove_connection ( uri )
2007-09-10 06:57:24 +04:00
2011-04-11 21:06:59 +04:00
def connect ( self , name , callback , * args ) :
handle_id = vmmGObject . connect ( self , name , callback , * args )
2007-09-10 06:57:24 +04:00
if name == " connection-added " :
for uri in self . connections . keys ( ) :
2011-04-11 21:06:59 +04:00
self . emit ( " connection-added " ,
self . connections [ uri ] [ " connection " ] )
2007-09-10 06:57:24 +04:00
return handle_id
2010-03-24 17:57:42 +03:00
def _check_connection ( self , uri ) :
2009-07-14 22:48:09 +04:00
conn = self . connections . get ( uri )
2010-03-24 17:57:42 +03:00
if conn :
return conn [ " connection " ]
return None
def _lookup_connection ( self , uri ) :
conn = self . _check_connection ( uri )
2009-07-14 22:48:09 +04:00
if not conn :
raise RuntimeError ( _ ( " Unknown connection URI %s " ) % uri )
2010-03-24 17:57:42 +03:00
return conn
2006-07-17 21:08:58 +04:00
2010-11-24 02:54:12 +03:00
####################
# Dialog launchers #
####################
2010-11-24 04:13:50 +03:00
def _do_show_about ( self , src ) :
2010-11-24 02:54:12 +03:00
try :
if self . windowAbout == None :
2010-12-09 01:26:19 +03:00
self . windowAbout = vmmAbout ( )
2010-11-24 02:54:12 +03:00
self . windowAbout . show ( )
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error launching ' About ' dialog: %s " ) % str ( e ) )
2010-11-24 02:54:12 +03:00
2010-11-24 04:13:50 +03:00
def _do_show_help ( self , src , index ) :
2010-11-24 02:54:12 +03:00
try :
uri = " ghelp: %s " % self . config . get_appname ( )
if index :
uri + = " # %s " % index
logging . debug ( " Showing help for %s " % uri )
gtk . show_uri ( None , uri , gtk . get_current_event_time ( ) )
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Unable to display documentation: %s " ) % e )
2010-11-24 02:54:12 +03:00
def _get_preferences ( self ) :
if self . windowPreferences :
return self . windowPreferences
2010-12-09 01:26:19 +03:00
obj = vmmPreferences ( )
2010-11-24 02:54:12 +03:00
obj . connect ( " action-show-help " , self . _do_show_help )
self . windowPreferences = obj
return self . windowPreferences
2010-11-24 04:13:50 +03:00
def _do_show_preferences ( self , src ) :
2010-11-24 02:54:12 +03:00
try :
self . _get_preferences ( ) . show ( )
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error launching preferences: %s " ) % str ( e ) )
2010-11-24 02:54:12 +03:00
def _get_host_dialog ( self , uri ) :
if self . connections [ uri ] [ " windowHost " ] :
return self . connections [ uri ] [ " windowHost " ]
con = self . _lookup_connection ( uri )
2010-12-09 01:26:19 +03:00
obj = vmmHost ( con , self )
2010-11-24 02:54:12 +03:00
obj . connect ( " action-show-help " , self . _do_show_help )
2010-11-24 04:13:50 +03:00
obj . connect ( " action-exit-app " , self . exit_app )
2010-11-24 02:54:12 +03:00
obj . connect ( " action-view-manager " , self . _do_show_manager )
obj . connect ( " action-restore-domain " , self . _do_restore_domain )
self . connections [ uri ] [ " windowHost " ] = obj
return self . connections [ uri ] [ " windowHost " ]
2010-11-24 04:13:50 +03:00
def _do_show_host ( self , src , uri ) :
2010-11-24 02:54:12 +03:00
try :
self . _get_host_dialog ( uri ) . show ( )
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error launching host dialog: %s " ) % str ( e ) )
2010-11-24 02:54:12 +03:00
def _get_connect_dialog ( self ) :
if self . windowConnect :
return self . windowConnect
2010-12-09 19:22:35 +03:00
def connect_wrap ( src_ignore , * args ) :
2010-11-24 02:54:12 +03:00
return self . connect_to_uri ( * args )
2010-12-09 01:26:19 +03:00
obj = vmmConnect ( )
2010-11-24 02:54:12 +03:00
obj . connect ( " completed " , connect_wrap )
obj . connect ( " cancelled " , self . _connect_cancelled )
self . windowConnect = obj
return self . windowConnect
2010-11-24 04:13:50 +03:00
def _do_show_connect ( self , src ) :
2010-11-24 02:54:12 +03:00
try :
self . _get_connect_dialog ( ) . show ( )
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error launching connect dialog: %s " ) % str ( e ) )
2010-11-24 02:54:12 +03:00
def _get_details_dialog ( self , uri , uuid ) :
if uuid in self . connections [ uri ] [ " windowDetails " ] :
return self . connections [ uri ] [ " windowDetails " ] [ uuid ]
con = self . _lookup_connection ( uri )
2010-12-09 01:26:19 +03:00
obj = vmmDetails ( con . get_vm ( uuid ) , self )
2010-11-24 02:54:12 +03:00
obj . connect ( " action-save-domain " , self . _do_save_domain )
obj . connect ( " action-destroy-domain " , self . _do_destroy_domain )
obj . connect ( " action-show-help " , self . _do_show_help )
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 04:13:50 +03:00
obj . connect ( " action-exit-app " , self . exit_app )
2010-11-24 02:54:12 +03:00
obj . connect ( " action-view-manager " , self . _do_show_manager )
2010-11-24 04:13:50 +03:00
obj . connect ( " action-migrate-domain " , self . _do_show_migrate )
obj . connect ( " action-clone-domain " , self . _do_show_clone )
2010-11-24 02:54:12 +03:00
self . connections [ uri ] [ " windowDetails " ] [ uuid ] = obj
self . connections [ uri ] [ " windowDetails " ] [ uuid ] . show ( )
return self . connections [ uri ] [ " windowDetails " ] [ uuid ]
2010-11-24 04:13:50 +03:00
def _do_show_details ( self , src , uri , uuid ) :
2010-11-24 02:54:12 +03:00
try :
details = self . _get_details_dialog ( uri , uuid )
details . show ( )
return details
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error launching details: %s " ) % str ( e ) )
2010-11-24 02:54:12 +03:00
2010-11-24 04:13:50 +03:00
def _do_show_console ( self , src , uri , uuid ) :
win = self . _do_show_details ( src , uri , uuid )
2010-11-24 02:54:12 +03:00
if not win :
return
win . activate_console_page ( )
def get_manager ( self ) :
if self . windowManager :
return self . windowManager
2010-12-09 01:26:19 +03:00
obj = vmmManager ( self )
2010-11-24 02:54:12 +03: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 )
obj . connect ( " action-save-domain " , self . _do_save_domain )
2010-11-24 04:13:50 +03:00
obj . connect ( " action-migrate-domain " , self . _do_show_migrate )
obj . connect ( " action-clone-domain " , self . _do_show_clone )
2010-11-24 02:54:12 +03:00
obj . connect ( " action-show-console " , self . _do_show_console )
obj . connect ( " action-show-details " , self . _do_show_details )
obj . connect ( " action-show-preferences " , self . _do_show_preferences )
obj . connect ( " action-show-create " , self . _do_show_create )
obj . connect ( " action-show-help " , self . _do_show_help )
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 )
obj . connect ( " action-connect " , self . _do_connect )
2010-11-24 04:13:50 +03:00
obj . connect ( " action-exit-app " , self . exit_app )
2010-11-24 02:54:12 +03:00
self . windowManager = obj
return self . windowManager
2010-11-24 04:13:50 +03:00
def _do_toggle_manager ( self , ignore ) :
2010-11-24 02:54:12 +03:00
manager = self . get_manager ( )
2010-12-14 01:48:19 +03:00
if manager . is_visible ( ) :
manager . close ( )
else :
2010-11-24 02:54:12 +03:00
manager . show ( )
2010-11-24 04:13:50 +03:00
def _do_show_manager ( self , src ) :
2010-11-24 02:54:12 +03:00
try :
2011-04-13 17:27:02 +04:00
manager = self . get_manager ( )
manager . show ( )
2010-11-24 02:54:12 +03:00
except Exception , e :
2010-11-24 04:13:50 +03:00
if not src :
raise
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error launching manager: %s " ) % str ( e ) )
2010-11-24 02:54:12 +03:00
def _get_create_dialog ( self ) :
if self . windowCreate :
return self . windowCreate
2010-12-09 01:26:19 +03:00
obj = vmmCreate ( self )
2010-11-24 02:54:12 +03:00
obj . connect ( " action-show-console " , self . _do_show_console )
obj . connect ( " action-show-help " , self . _do_show_help )
self . windowCreate = obj
return self . windowCreate
2010-11-24 04:13:50 +03:00
def _do_show_create ( self , src , uri ) :
2010-11-24 02:54:12 +03:00
try :
2010-11-24 16:28:50 +03:00
self . _get_create_dialog ( ) . show ( uri )
2010-11-24 02:54:12 +03:00
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error launching manager: %s " ) % str ( e ) )
2010-11-24 02:54:12 +03:00
2010-11-24 04:13:50 +03:00
def _do_show_migrate ( self , src , uri , uuid ) :
2010-11-24 02:54:12 +03:00
try :
conn = self . _lookup_connection ( uri )
vm = conn . get_vm ( uuid )
if not self . windowMigrate :
2010-12-09 01:26:19 +03:00
self . windowMigrate = vmmMigrateDialog ( vm , self )
2010-11-24 02:54:12 +03:00
self . windowMigrate . set_state ( vm )
self . windowMigrate . show ( )
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error launching migrate dialog: %s " ) % str ( e ) )
2010-11-24 02:54:12 +03:00
2010-11-24 04:13:50 +03:00
def _do_show_clone ( self , src , uri , uuid ) :
2010-11-24 02:54:12 +03:00
con = self . _lookup_connection ( uri )
orig_vm = con . get_vm ( uuid )
clone_window = self . connections [ uri ] [ " windowClone " ]
try :
if clone_window == None :
2010-12-09 01:26:19 +03:00
clone_window = vmmCloneVM ( orig_vm )
2010-11-24 02:54:12 +03:00
clone_window . connect ( " action-show-help " , self . _do_show_help )
self . connections [ uri ] [ " windowClone " ] = clone_window
else :
clone_window . set_orig_vm ( orig_vm )
clone_window . show ( )
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error setting clone parameters: %s " ) % str ( e ) )
2010-11-24 04:13:50 +03:00
##########################################
# Window launchers from virt-manager cli #
##########################################
def show_manager ( self ) :
self . _do_show_manager ( None )
2010-11-24 22:01:51 +03:00
def show_connect ( self ) :
self . _do_show_connect ( self . get_manager ( ) )
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 )
2010-11-24 04:13:50 +03:00
2010-11-24 22:01:51 +03:00
def show_domain_console ( self , uri , uuid ) :
2010-11-24 04:13:50 +03:00
win = self . _do_show_details ( self . get_manager ( ) , uri , uuid )
if not win :
return
win . activate_console_page ( )
2010-11-24 02:54:12 +03:00
2010-11-24 22:01:51 +03:00
def show_domain_editor ( self , uri , uuid ) :
2010-11-24 04:13:50 +03:00
win = self . _do_show_details ( self . get_manager ( ) , uri , uuid )
if not win :
return
2010-11-24 22:01:51 +03:00
win . activate_config_page ( )
2010-11-24 04:13:50 +03:00
2010-11-24 22:01:51 +03:00
def show_domain_performance ( self , uri , uuid ) :
2010-11-24 04:13:50 +03:00
win = self . _do_show_details ( self . get_manager ( ) , uri , uuid )
if not win :
return
2010-11-24 22:01:51 +03:00
win . activate_performance_page ( )
2010-11-24 02:54:12 +03:00
#######################################
# Domain actions run/destroy/save ... #
#######################################
2010-11-24 04:13:50 +03:00
def _do_save_domain ( self , src , uri , uuid ) :
2009-07-14 22:48:09 +04:00
conn = self . _lookup_connection ( uri )
2010-05-12 03:01:25 +04:00
vm = conn . get_vm ( uuid )
2010-05-12 20:57:32 +04:00
managed = bool ( vm . managedsave_supported )
2010-05-12 03:01:25 +04:00
do_prompt = self . config . get_confirm_poweroff ( )
2010-09-08 15:51:48 +04:00
if not managed and conn . is_remote ( ) :
2010-11-24 04:13:50 +03:00
src . err . val_err ( _ ( " Saving virtual machines over remote "
" connections is not supported with this "
" libvirt version or hypervisor. " ) )
2008-01-10 00:44:10 +03:00
return
2009-03-08 22:14:00 +03:00
2010-05-12 03:01:25 +04:00
if do_prompt :
2010-11-24 04:13:50 +03:00
res = src . err . warn_chkbox (
2010-05-12 03:01:25 +04:00
text1 = _ ( " Are you sure you want to save "
" ' %s ' ? " % vm . get_name ( ) ) ,
chktext = _ ( " Don ' t ask me again. " ) ,
buttons = gtk . BUTTONS_YES_NO )
response , skip_prompt = res
if not response :
return
self . config . set_confirm_poweroff ( not skip_prompt )
2009-03-08 22:14:00 +03:00
2010-05-12 20:57:32 +04:00
path = None
if not managed :
2010-11-24 04:13:50 +03:00
path = util . browse_local ( src . topwin ,
2010-05-12 20:57:32 +04:00
_ ( " Save Virtual Machine " ) ,
2010-12-09 22:06:00 +03:00
conn ,
2010-05-12 20:57:32 +04:00
dialog_type = gtk . FILE_CHOOSER_ACTION_SAVE ,
browse_reason = self . config . CONFIG_DIR_SAVE )
if not path :
return
2009-04-03 22:15:15 +04:00
2010-12-10 22:59:24 +03:00
_cancel_back = None
_cancel_args = [ ]
2010-12-08 20:52:33 +03:00
if vm . getjobinfo_supported :
_cancel_back = self . _save_cancel
_cancel_args = [ vm ]
2010-12-09 20:37:48 +03:00
progWin = vmmAsyncJob ( self . _save_callback ,
2010-12-12 21:48:20 +03:00
[ vm , path ] ,
_ ( " Saving Virtual Machine " ) ,
_ ( " Saving virtual machine memory to disk " ) ,
cancel_back = _cancel_back ,
cancel_args = _cancel_args )
2010-12-10 17:57:42 +03:00
error , details = progWin . run ( )
2009-03-08 22:14:00 +03:00
2009-04-03 22:15:15 +04:00
if error is not None :
2010-12-10 17:57:42 +03:00
error = _ ( " Error saving domain: %s " ) % error
2011-04-06 19:22:03 +04:00
src . err . show_err ( error ,
2011-04-06 19:52:26 +04:00
details = details )
2007-11-27 19:31:30 +03:00
2010-12-10 17:57:42 +03:00
def _save_cancel ( self , asyncjob , vm ) :
2010-12-08 22:14:38 +03:00
logging . debug ( " Cancelling save job " )
2010-12-08 20:52:33 +03:00
if not vm :
return
try :
vm . abort_job ( )
except Exception , e :
2010-12-08 22:14:38 +03:00
logging . exception ( " Error cancelling save job " )
2010-12-10 19:47:07 +03:00
asyncjob . show_warning ( _ ( " Error cancelling save job: %s " ) % str ( e ) )
2010-12-08 20:52:33 +03:00
return
asyncjob . job_canceled = True
return
2010-12-10 17:57:42 +03:00
def _save_callback ( self , asyncjob , vm , file_to_save ) :
2010-12-10 22:59:24 +03:00
conn = util . dup_conn ( vm . connection )
newvm = conn . get_vm ( vm . get_uuid ( ) )
2010-12-11 00:04:42 +03:00
meter = vmmCreateMeter ( asyncjob )
newvm . save ( file_to_save , meter = meter )
2010-05-12 20:57:32 +04:00
2007-11-27 19:31:30 +03:00
2010-11-24 04:13:50 +03:00
def _do_restore_domain ( self , src , uri ) :
2010-05-12 19:42:59 +04:00
conn = self . _lookup_connection ( uri )
if conn . is_remote ( ) :
2010-11-24 04:13:50 +03:00
src . err . val_err ( _ ( " Restoring virtual machines over remote "
" connections is not yet supported " ) )
2010-05-12 19:42:59 +04:00
return
2010-11-24 04:13:50 +03:00
path = util . browse_local ( src . topwin ,
2010-05-12 19:42:59 +04:00
_ ( " Restore Virtual Machine " ) ,
2010-12-09 22:06:00 +03:00
conn ,
2010-05-12 19:42:59 +04:00
browse_reason = self . config . CONFIG_DIR_RESTORE )
if not path :
return
2010-12-09 20:37:48 +03:00
progWin = vmmAsyncJob ( self . _restore_saved_callback ,
2010-12-12 21:48:20 +03:00
[ path , conn ] ,
_ ( " Restoring Virtual Machine " ) ,
_ ( " Restoring virtual machine memory from disk " ) )
2010-12-10 17:57:42 +03:00
error , details = progWin . run ( )
2010-05-12 19:42:59 +04:00
if error is not None :
2010-12-10 17:57:42 +03:00
error = _ ( " Error restoring domain: %s " ) % error
2011-04-06 19:22:03 +04:00
src . err . show_err ( error ,
2011-04-06 19:52:26 +04:00
details = details )
2010-05-12 19:42:59 +04:00
2010-12-10 17:57:42 +03:00
def _restore_saved_callback ( self , asyncjob , file_to_load , conn ) :
ignore = asyncjob
newconn = util . dup_conn ( conn )
newconn . restore ( file_to_load )
2010-05-12 19:42:59 +04:00
2010-11-24 04:13:50 +03:00
def _do_destroy_domain ( self , src , uri , uuid ) :
2009-07-14 22:48:09 +04:00
conn = self . _lookup_connection ( uri )
vm = conn . get_vm ( uuid )
2009-11-19 00:11:17 +03:00
do_prompt = self . config . get_confirm_forcepoweroff ( )
if do_prompt :
2010-11-24 04:13:50 +03:00
res = src . err . warn_chkbox (
2009-11-19 00:11:17 +03:00
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. " ) ,
chktext = _ ( " Don ' t ask me again. " ) ,
buttons = gtk . BUTTONS_YES_NO )
response , skip_prompt = res
if not response :
return
self . config . set_confirm_forcepoweroff ( not skip_prompt )
2009-07-14 22:48:09 +04:00
logging . debug ( " Destroying vm ' %s ' . " % vm . get_name ( ) )
try :
vm . destroy ( )
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error shutting down domain: %s " % str ( e ) ) )
2007-11-27 19:31:30 +03:00
2010-11-24 04:13:50 +03:00
def _do_suspend_domain ( self , src , uri , uuid ) :
2009-07-14 22:48:09 +04:00
conn = self . _lookup_connection ( uri )
vm = conn . get_vm ( uuid )
2009-11-19 00:11:17 +03:00
do_prompt = self . config . get_confirm_pause ( )
if do_prompt :
2010-11-24 04:13:50 +03:00
res = src . err . warn_chkbox (
2009-11-19 00:11:17 +03:00
text1 = _ ( " Are you sure you want to pause "
" ' %s ' ? " % vm . get_name ( ) ) ,
chktext = _ ( " Don ' t ask me again. " ) ,
buttons = gtk . BUTTONS_YES_NO )
response , skip_prompt = res
if not response :
return
self . config . set_confirm_pause ( not skip_prompt )
2009-07-14 22:48:09 +04:00
logging . debug ( " Pausing vm ' %s ' . " % vm . get_name ( ) )
try :
vm . suspend ( )
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error pausing domain: %s " % str ( e ) ) )
2009-07-14 22:48:09 +04:00
2010-11-24 04:13:50 +03:00
def _do_resume_domain ( self , src , uri , uuid ) :
2009-07-14 22:48:09 +04:00
conn = self . _lookup_connection ( uri )
vm = conn . get_vm ( uuid )
logging . debug ( " Unpausing vm ' %s ' . " % vm . get_name ( ) )
try :
vm . resume ( )
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error unpausing domain: %s " % str ( e ) ) )
2009-07-14 22:48:09 +04:00
2010-11-24 04:13:50 +03:00
def _do_run_domain ( self , src , uri , uuid ) :
2009-07-14 22:48:09 +04:00
conn = self . _lookup_connection ( uri )
vm = conn . get_vm ( uuid )
logging . debug ( " Starting vm ' %s ' . " % vm . get_name ( ) )
2010-12-10 22:40:08 +03:00
def asyncfunc ( asyncjob ) :
ignore = asyncjob
2009-07-14 22:48:09 +04:00
vm . startup ( )
2010-12-10 22:40:08 +03:00
if vm . hasSavedImage ( ) :
# VM will be restored, which can take some time, so show a
# progress dialog.
errorintro = _ ( " Error restoring domain " )
2010-12-12 21:48:20 +03:00
title = _ ( " Restoring Virtual Machine " )
text = _ ( " Restoring virtual machine memory from disk " )
2010-12-10 22:40:08 +03:00
vmmAsyncJob . simple_async ( asyncfunc , [ ] , title , text , src ,
errorintro )
else :
# Regular startup
errorintro = _ ( " Error starting domain " )
vmmAsyncJob . simple_async_noshow ( asyncfunc , [ ] , src , errorintro )
2009-04-04 00:06:46 +04:00
2010-11-24 04:13:50 +03:00
def _do_shutdown_domain ( self , src , uri , uuid ) :
2009-07-14 22:48:09 +04:00
conn = self . _lookup_connection ( uri )
vm = conn . get_vm ( uuid )
2009-11-19 00:11:17 +03:00
do_prompt = self . config . get_confirm_poweroff ( )
if do_prompt :
2010-11-24 04:13:50 +03:00
res = src . err . warn_chkbox (
2009-11-19 00:11:17 +03:00
text1 = _ ( " Are you sure you want to poweroff "
" ' %s ' ? " % vm . get_name ( ) ) ,
chktext = _ ( " Don ' t ask me again. " ) ,
buttons = gtk . BUTTONS_YES_NO )
response , skip_prompt = res
if not response :
return
self . config . set_confirm_poweroff ( not skip_prompt )
2009-07-14 22:48:09 +04:00
logging . debug ( " Shutting down vm ' %s ' . " % vm . get_name ( ) )
try :
vm . shutdown ( )
except Exception , e :
2011-04-06 19:22:03 +04:00
src . err . show_err ( _ ( " Error shutting down domain: %s " % str ( e ) ) )
2007-11-27 19:31:30 +03:00
2010-11-24 04:13:50 +03:00
def _do_reboot_domain ( self , src , uri , uuid ) :
2009-07-14 22:48:09 +04:00
conn = self . _lookup_connection ( uri )
vm = conn . get_vm ( uuid )
2009-11-19 00:11:17 +03:00
do_prompt = self . config . get_confirm_poweroff ( )
if do_prompt :
2010-11-24 04:13:50 +03:00
res = src . err . warn_chkbox (
2009-11-19 00:11:17 +03:00
text1 = _ ( " Are you sure you want to reboot "
" ' %s ' ? " % vm . get_name ( ) ) ,
chktext = _ ( " Don ' t ask me again. " ) ,
buttons = gtk . BUTTONS_YES_NO )
response , skip_prompt = res
if not response :
return
self . config . set_confirm_poweroff ( not skip_prompt )
2009-07-14 22:48:09 +04:00
logging . debug ( " Rebooting vm ' %s ' . " % vm . get_name ( ) )
2010-03-17 23:41:50 +03:00
no_support = False
reboot_err = None
2009-07-14 22:48:09 +04:00
try :
vm . reboot ( )
2010-03-17 23:41:50 +03:00
except Exception , reboot_err :
no_support = virtinst . support . is_error_nosupport ( reboot_err )
if not no_support :
2010-11-24 04:13:50 +03:00
src . err . show_err ( _ ( " Error rebooting domain: %s " %
2011-04-06 19:22:03 +04:00
str ( reboot_err ) ) )
2010-03-17 23:41:50 +03:00
if not no_support :
return
# Reboot isn't supported. Let's try to emulate it
logging . debug ( " Hypervisor doesn ' t support reboot, let ' s fake it " )
try :
vm . manual_reboot ( )
except :
logging . exception ( " Could not fake a reboot " )
# Raise the original error message
2010-11-24 04:13:50 +03:00
src . err . show_err ( _ ( " Error rebooting domain: %s " %
2011-04-06 19:22:03 +04:00
str ( reboot_err ) ) )
2008-04-08 22:30:47 +04:00
2010-12-09 20:37:48 +03:00
vmmGObject . type_register ( vmmEngine )