2006-06-28 23:50:17 +04:00
#
2012-12-03 20:12:59 +04:00
# Copyright (C) 2006, 2012 Red Hat, Inc.
2006-06-28 23:50:17 +04: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-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
#
2006-08-22 01:45:24 +04:00
import os
2011-01-07 22:59:31 +03:00
import logging
2006-06-14 18:59:40 +04:00
2012-05-14 17:24:56 +04:00
from gi . repository import Gtk
from gi . repository import GConf
2011-01-07 22:59:31 +03:00
2009-05-11 20:37:47 +04:00
import virtinst
2013-04-11 20:04:28 +04:00
from virtinst import uriutil
2011-01-07 22:59:31 +03:00
2012-11-09 19:08:15 +04:00
from virtManager . keyring import vmmKeyring , vmmSecret
2006-07-19 22:33:23 +04:00
2010-12-09 01:26:19 +03:00
class vmmConfig ( object ) :
2009-02-24 02:50:47 +03:00
2009-06-24 03:30:12 +04:00
# GConf directory names for saving last used paths
CONFIG_DIR_IMAGE = " image "
2011-07-23 03:12:48 +04:00
CONFIG_DIR_ISO_MEDIA = " isomedia "
CONFIG_DIR_FLOPPY_MEDIA = " floppymedia "
2009-06-24 03:30:12 +04:00
CONFIG_DIR_SAVE = " save "
CONFIG_DIR_RESTORE = " restore "
CONFIG_DIR_SCREENSHOT = " screenshot "
2011-06-09 02:37:35 +04:00
CONFIG_DIR_FS = " fs "
2009-06-24 03:30:12 +04:00
2009-11-10 22:30:51 +03:00
# Metadata mapping for browse types. Prob shouldn't go here, but works
# for now.
browse_reason_data = {
CONFIG_DIR_IMAGE : {
" enable_create " : True ,
" storage_title " : _ ( " Locate or create storage volume " ) ,
" local_title " : _ ( " Locate existing storage " ) ,
2012-05-14 17:24:56 +04:00
" dialog_type " : Gtk . FileChooserAction . SAVE ,
" choose_button " : Gtk . STOCK_OPEN ,
2009-11-10 22:30:51 +03:00
} ,
2011-07-23 03:12:48 +04:00
CONFIG_DIR_ISO_MEDIA : {
2009-11-10 22:30:51 +03:00
" enable_create " : False ,
" storage_title " : _ ( " Locate ISO media volume " ) ,
" local_title " : _ ( " Locate ISO media " ) ,
2011-06-09 02:37:35 +04:00
} ,
2011-07-23 03:12:48 +04:00
CONFIG_DIR_FLOPPY_MEDIA : {
" enable_create " : False ,
" storage_title " : _ ( " Locate floppy media volume " ) ,
" local_title " : _ ( " Locate floppy media " ) ,
} ,
2011-06-09 02:37:35 +04:00
CONFIG_DIR_FS : {
" enable_create " : False ,
" storage_title " : _ ( " Locate directory volume " ) ,
" local_title " : _ ( " Locate directory volume " ) ,
2012-05-14 17:24:56 +04:00
" dialog_type " : Gtk . FileChooserAction . SELECT_FOLDER ,
2011-06-09 02:37:35 +04:00
} ,
2009-11-10 22:30:51 +03:00
}
2009-02-24 02:50:47 +03:00
CONSOLE_SCALE_NEVER = 0
CONSOLE_SCALE_FULLSCREEN = 1
CONSOLE_SCALE_ALWAYS = 2
2011-04-18 21:14:14 +04:00
CONSOLE_KEYGRAB_NEVER = 0
CONSOLE_KEYGRAB_FULLSCREEN = 1
CONSOLE_KEYGRAB_MOUSEOVER = 2
2009-05-11 20:37:47 +04:00
_PEROBJ_FUNC_SET = 0
_PEROBJ_FUNC_GET = 1
_PEROBJ_FUNC_LISTEN = 2
2011-04-18 21:14:14 +04:00
DEFAULT_XEN_IMAGE_DIR = " /var/lib/xen/images "
DEFAULT_XEN_SAVE_DIR = " /var/lib/xen/dump "
DEFAULT_VIRT_IMAGE_DIR = " /var/lib/libvirt/images "
DEFAULT_VIRT_SAVE_DIR = " /var/lib/libvirt "
2012-10-29 02:49:48 +04:00
def __init__ ( self , appname , appversion , ui_dir , test_first_run = False ) :
2006-06-14 18:59:40 +04:00
self . appname = appname
2006-08-04 23:46:06 +04:00
self . appversion = appversion
2011-07-14 02:48:02 +04:00
self . conf_dir = " /apps/ " + appname
2012-02-02 02:26:46 +04:00
self . ui_dir = ui_dir
2012-10-29 02:49:48 +04:00
self . test_first_run = bool ( test_first_run )
2011-07-14 02:48:02 +04:00
2012-05-14 17:24:56 +04:00
self . conf = GConf . Client . get_default ( )
self . conf . add_dir ( self . conf_dir , GConf . ClientPreloadType . PRELOAD_NONE )
2010-12-13 19:22:01 +03:00
2006-08-22 01:45:24 +04:00
# We don't create it straight away, since we don't want
2006-07-19 22:33:23 +04:00
# to block the app pending user authorizaation to access
# the keyring
self . keyring = None
2006-06-14 18:59:40 +04:00
2010-12-13 19:22:01 +03:00
self . default_qemu_user = " root "
2010-12-13 22:31:27 +03:00
# Use this key to disable certain features not supported on RHEL
2011-07-22 21:13:26 +04:00
self . rhel6_defaults = True
2010-12-14 00:02:59 +03:00
self . preferred_distros = [ ]
2011-01-14 23:19:58 +03:00
self . hv_packages = [ ]
self . libvirt_packages = [ ]
2012-07-08 23:38:52 +04:00
self . askpass_package = [ ]
2013-03-17 05:32:29 +04:00
self . default_graphics_from_config = " vnc "
2010-12-13 22:31:27 +03:00
2011-04-11 20:54:47 +04:00
self . _objects = [ ]
2011-04-14 23:43:31 +04:00
self . support_threading = virtinst . support . support_threading ( )
2011-07-18 22:53:54 +04:00
self . support_inspection = self . check_inspection ( self . support_threading )
2011-04-18 21:01:22 +04:00
self . _spice_error = None
2011-04-14 23:43:31 +04:00
2012-05-14 17:24:56 +04:00
def get_string_list ( self , path ) :
val = self . conf . get ( path )
if val is None :
return None
values = [ ]
for v in val . get_list ( ) :
values . append ( v . get_string ( ) )
return values
def set_string_list ( self , path , values ) :
newValues = [ ]
for v in values :
nv = GConf . Value . new ( GConf . ValueType . STRING )
nv . set_string ( v )
newValues . append ( nv )
ignore = path
#XXX: set_list is not available with introspection
# val = GConf.Value()
#val.set_list(newValues)
#self.conf.set(path, val)
2011-07-18 22:53:54 +04:00
def check_inspection ( self , support_threading ) :
if not support_threading :
return False
try :
# Check we can open the Python guestfs module.
from guestfs import GuestFS
g = GuestFS ( )
# Check for the first version which fixed Python GIL bug.
version = g . version ( )
if version [ " major " ] == 1 : # major must be 1
if version [ " minor " ] == 8 :
if version [ " release " ] > = 6 : # >= 1.8.6
return True
elif version [ " minor " ] == 10 :
if version [ " release " ] > = 1 : # >= 1.10.1
return True
elif version [ " minor " ] == 11 :
if version [ " release " ] > = 2 : # >= 1.11.2
return True
elif version [ " minor " ] > = 12 : # >= 1.12, 1.13, etc.
return True
except :
pass
return False
2006-06-15 01:09:08 +04:00
2013-01-13 23:41:25 +04:00
# General app wide helpers (gconf agnostic)
2009-07-20 23:09:32 +04:00
2006-06-14 18:59:40 +04:00
def get_appname ( self ) :
return self . appname
2006-08-04 23:46:06 +04:00
def get_appversion ( self ) :
return self . appversion
2012-02-02 02:26:46 +04:00
def get_ui_dir ( self ) :
return self . ui_dir
2006-06-14 18:59:40 +04:00
2011-01-07 22:59:31 +03:00
def embeddable_graphics ( self ) :
2012-05-14 17:24:56 +04:00
ret = [ " vnc " , " spice " ]
2011-01-07 22:59:31 +03:00
return ret
2011-04-11 19:00:57 +04:00
def remove_notifier ( self , h ) :
self . conf . notify_remove ( h )
2011-04-11 20:54:47 +04:00
# Used for debugging reference leaks, we keep track of all objects
# come and go so we can do a leak report at app shutdown
def add_object ( self , obj ) :
self . _objects . append ( obj )
def remove_object ( self , obj ) :
self . _objects . remove ( obj )
def get_objects ( self ) :
return self . _objects [ : ]
2009-05-11 20:37:47 +04:00
# Per-VM/Connection/Connection Host Option dealings
def _perconn_helper ( self , uri , pref_func , func_type , value = None ) :
2012-05-14 17:24:56 +04:00
suffix = " connection_prefs/ %s " % GConf . escape_key ( uri , len ( uri ) )
2009-05-11 20:37:47 +04:00
return self . _perobj_helper ( suffix , pref_func , func_type , value )
def _perhost_helper ( self , uri , pref_func , func_type , value = None ) :
2013-04-11 20:04:28 +04:00
host = uriutil . get_uri_hostname ( uri )
2009-05-11 20:37:47 +04:00
if not host :
host = " localhost "
suffix = " connection_prefs/hosts/ %s " % host
return self . _perobj_helper ( suffix , pref_func , func_type , value )
def _pervm_helper ( self , uri , uuid , pref_func , func_type , value = None ) :
2009-07-01 22:51:41 +04:00
suffix = ( " connection_prefs/ %s /vms/ %s " %
2012-05-14 17:24:56 +04:00
( GConf . escape_key ( uri , len ( uri ) ) , uuid ) )
2009-05-11 20:37:47 +04:00
return self . _perobj_helper ( suffix , pref_func , func_type , value )
def _perobj_helper ( self , suffix , pref_func , func_type , value = None ) :
# This function wraps the regular preference setting functions,
# replacing conf_dir with a connection, host, or vm specific path. For
# VMs, the path is:
#
# conf_dir/connection_prefs/{CONN_URI}/vms/{VM_UUID}
#
# So a per-VM pref will look like
2009-11-18 23:16:57 +03:00
# .../connection_prefs/qemu:---system/vms/1234.../console/scaling
2009-05-11 20:37:47 +04:00
#
# Yeah this is evil but it's also nice and easy :)
oldconf = self . conf_dir
newconf = oldconf
# Don't make a bogus gconf path if this is called nested.
if not oldconf . count ( suffix ) :
newconf = " %s / %s " % ( oldconf , suffix )
ret = None
try :
self . conf_dir = newconf
if func_type == self . _PEROBJ_FUNC_SET :
2009-11-29 04:07:01 +03:00
if type ( value ) is not tuple :
value = ( value , )
pref_func ( * value )
2009-05-11 20:37:47 +04:00
elif func_type == self . _PEROBJ_FUNC_GET :
ret = pref_func ( )
elif func_type == self . _PEROBJ_FUNC_LISTEN :
2011-04-13 18:45:10 +04:00
ret = pref_func ( value )
2009-05-11 20:37:47 +04:00
finally :
self . conf_dir = oldconf
return ret
2009-11-29 04:07:01 +03:00
def set_pervm ( self , uri , uuid , pref_func , args ) :
2009-05-11 20:37:47 +04:00
"""
@param uri : VM connection URI
@param uuid : VM UUID
@param value : Set value or listener callback function
@param pref_func : Global preference get / set / listen func that the
pervm instance will overshadow
"""
2009-11-29 04:07:01 +03:00
self . _ pervm_helper ( uri , uuid , pref_func , self . _PEROBJ_FUNC_SET , args )
2009-05-11 20:37:47 +04:00
def get_pervm ( self , uri , uuid , pref_func ) :
ret = self . _pervm_helper ( uri , uuid , pref_func , self . _PEROBJ_FUNC_GET )
2012-11-08 17:15:02 +04:00
if ret is None :
2009-05-11 20:37:47 +04:00
# If the GConf value is unset, return the global default.
ret = pref_func ( )
return ret
def listen_pervm ( self , uri , uuid , pref_func , cb ) :
2011-04-13 18:45:10 +04:00
return self . _pervm_helper ( uri , uuid , pref_func ,
self . _PEROBJ_FUNC_LISTEN , cb )
2009-05-11 20:37:47 +04:00
def set_perconn ( self , uri , pref_func , value ) :
self . _perconn_helper ( uri , pref_func , self . _PEROBJ_FUNC_SET , value )
def get_perconn ( self , uri , pref_func ) :
ret = self . _perconn_helper ( uri , pref_func , self . _PEROBJ_FUNC_GET )
2012-11-08 17:15:02 +04:00
if ret is None :
2009-05-11 20:37:47 +04:00
# If the GConf value is unset, return the global default.
ret = pref_func ( )
return ret
def listen_perconn ( self , uri , pref_func , cb ) :
2011-04-13 18:45:10 +04:00
return self . _perconn_helper ( uri , pref_func ,
self . _PEROBJ_FUNC_LISTEN , cb )
2009-05-11 20:37:47 +04:00
def set_perhost ( self , uri , pref_func , value ) :
self . _perhost_helper ( uri , pref_func , self . _PEROBJ_FUNC_SET , value )
def get_perhost ( self , uri , pref_func ) :
ret = self . _perhost_helper ( uri , pref_func , self . _PEROBJ_FUNC_GET )
2012-11-08 17:15:02 +04:00
if ret is None :
2009-05-11 20:37:47 +04:00
# If the GConf value is unset, return the global default.
ret = pref_func ( )
return ret
def listen_perhost ( self , uri , pref_func , cb ) :
2011-04-13 18:45:10 +04:00
return self . _perhost_helper ( uri , pref_func ,
self . _PEROBJ_FUNC_LISTEN , cb )
2009-05-11 20:37:47 +04:00
2009-05-11 20:05:46 +04:00
def reconcile_vm_entries ( self , uri , current_vms ) :
"""
Remove any old VM preference entries for the passed URI
"""
2012-05-14 17:24:56 +04:00
uri = GConf . escape_key ( uri , len ( uri ) )
2009-05-11 20:05:46 +04:00
key = self . conf_dir + " /connection_prefs/ %s /vms " % uri
kill_vms = [ ]
2013-04-12 00:32:00 +04:00
gconf_vms = [ inp . split ( " / " ) [ - 1 ] for inp in self . conf . all_dirs ( key ) ]
2009-05-11 20:05:46 +04:00
for uuid in gconf_vms :
if len ( uuid ) == 36 and not uuid in current_vms :
kill_vms . append ( uuid )
for uuid in kill_vms :
self . conf . recursive_unset ( key + " / %s " % uuid , 0 )
if kill_vms :
# Suggest gconf syncs, so that the unset dirs are fully removed
self . conf . suggest_sync ( )
2009-05-11 20:37:47 +04:00
2009-11-18 23:16:57 +03:00
#########################
# General GConf helpers #
#########################
# Manager stats view preferences
2011-07-12 16:49:47 +04:00
def is_vmlist_guest_cpu_usage_visible ( self ) :
2009-11-11 19:02:57 +03:00
return self . conf . get_bool ( self . conf_dir + " /vmlist-fields/cpu_usage " )
2011-07-12 16:49:47 +04:00
def is_vmlist_host_cpu_usage_visible ( self ) :
return self . conf . get_bool ( self . conf_dir +
" /vmlist-fields/host_cpu_usage " )
2009-11-11 19:02:57 +03:00
def is_vmlist_disk_io_visible ( self ) :
return self . conf . get_bool ( self . conf_dir + " /vmlist-fields/disk_usage " )
def is_vmlist_network_traffic_visible ( self ) :
2009-11-18 23:16:57 +03:00
return self . conf . get_bool ( self . conf_dir +
" /vmlist-fields/network_traffic " )
2009-11-11 19:02:57 +03:00
2011-07-12 16:49:47 +04:00
def set_vmlist_guest_cpu_usage_visible ( self , state ) :
2009-11-11 19:02:57 +03:00
self . conf . set_bool ( self . conf_dir + " /vmlist-fields/cpu_usage " , state )
2011-07-12 16:49:47 +04:00
def set_vmlist_host_cpu_usage_visible ( self , state ) :
self . conf . set_bool ( self . conf_dir + " /vmlist-fields/host_cpu_usage " ,
state )
2009-11-11 19:02:57 +03:00
def set_vmlist_disk_io_visible ( self , state ) :
self . conf . set_bool ( self . conf_dir + " /vmlist-fields/disk_usage " , state )
def set_vmlist_network_traffic_visible ( self , state ) :
2009-11-18 23:16:57 +03:00
self . conf . set_bool ( self . conf_dir + " /vmlist-fields/network_traffic " ,
state )
2009-06-24 03:30:12 +04:00
2012-05-14 17:24:56 +04:00
def on_vmlist_guest_cpu_usage_visible_changed ( self , cb , userdata = None ) :
2011-04-12 22:57:32 +04:00
return self . conf . notify_add ( self . conf_dir + " /vmlist-fields/cpu_usage " ,
2012-05-14 17:24:56 +04:00
cb , userdata )
def on_vmlist_host_cpu_usage_visible_changed ( self , cb , userdata = None ) :
2011-07-12 16:49:47 +04:00
return self . conf . notify_add ( self . conf_dir +
2012-05-14 17:24:56 +04:00
" /vmlist-fields/host_cpu_usage " , cb , userdata )
def on_vmlist_disk_io_visible_changed ( self , cb , userdata = None ) :
2011-04-12 22:57:32 +04:00
return self . conf . notify_add ( self . conf_dir + " /vmlist-fields/disk_usage " ,
2012-05-14 17:24:56 +04:00
cb , userdata )
def on_vmlist_network_traffic_visible_changed ( self , cb , userdata = None ) :
2011-04-12 22:57:32 +04:00
return self . conf . notify_add (
2012-05-14 17:24:56 +04:00
self . conf_dir + " /vmlist-fields/network_traffic " , cb , userdata )
2009-06-24 03:30:12 +04:00
2010-08-23 19:50:36 +04:00
# Keys preferences
2012-01-30 06:51:20 +04:00
def get_keys_combination ( self ) :
ret = self . conf . get_string ( self . conf_dir + " /keys/grab-keys " )
if not ret :
# Left Control + Left Alt
return " 65507,65513 "
return ret
2010-08-23 19:50:36 +04:00
def set_keys_combination ( self , val ) :
# Val have to be a list of integers
2013-04-12 00:32:00 +04:00
val = ' , ' . join ( [ str ( v ) for v in val ] )
2010-08-23 19:50:36 +04:00
self . conf . set_string ( self . conf_dir + " /keys/grab-keys " , val )
2012-05-14 17:24:56 +04:00
def on_keys_combination_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /keys/grab-keys " , cb , userdata )
2006-06-14 18:59:40 +04:00
2009-11-19 00:11:17 +03:00
# Confirmation preferences
def get_confirm_forcepoweroff ( self ) :
return self . conf . get_bool ( self . conf_dir + " /confirm/forcepoweroff " )
def get_confirm_poweroff ( self ) :
return self . conf . get_bool ( self . conf_dir + " /confirm/poweroff " )
def get_confirm_pause ( self ) :
return self . conf . get_bool ( self . conf_dir + " /confirm/pause " )
2009-11-19 00:46:36 +03:00
def get_confirm_removedev ( self ) :
return self . conf . get_bool ( self . conf_dir + " /confirm/removedev " )
2010-02-09 06:34:23 +03:00
def get_confirm_interface ( self ) :
return self . conf . get_bool ( self . conf_dir + " /confirm/interface_power " )
2011-07-20 04:29:07 +04:00
def get_confirm_unapplied ( self ) :
return self . conf . get_bool ( self . conf_dir + " /confirm/unapplied_dev " )
2012-12-03 20:12:59 +04:00
def get_confirm_delstorage ( self ) :
# If no schema is installed, we _really_ want this to default to True
path = self . conf_dir + " /confirm/delete_storage "
ret = self . conf . get ( path )
2012-11-08 17:15:02 +04:00
if ret is None :
2012-12-03 20:12:59 +04:00
return True
return self . conf . get_bool ( path )
2010-02-09 06:34:23 +03:00
2009-11-19 00:11:17 +03:00
def set_confirm_forcepoweroff ( self , val ) :
self . conf . set_bool ( self . conf_dir + " /confirm/forcepoweroff " , val )
def set_confirm_poweroff ( self , val ) :
self . conf . set_bool ( self . conf_dir + " /confirm/poweroff " , val )
def set_confirm_pause ( self , val ) :
self . conf . set_bool ( self . conf_dir + " /confirm/pause " , val )
2009-11-19 00:46:36 +03:00
def set_confirm_removedev ( self , val ) :
self . conf . set_bool ( self . conf_dir + " /confirm/removedev " , val )
2010-02-09 06:34:23 +03:00
def set_confirm_interface ( self , val ) :
self . conf . set_bool ( self . conf_dir + " /confirm/interface_power " , val )
2011-07-20 04:29:07 +04:00
def set_confirm_unapplied ( self , val ) :
self . conf . set_bool ( self . conf_dir + " /confirm/unapplied_dev " , val )
2012-12-03 20:12:59 +04:00
def set_confirm_delstorage ( self , val ) :
self . conf . set_bool ( self . conf_dir + " /confirm/delete_storage " , val )
2009-11-19 00:11:17 +03:00
2012-05-14 17:24:56 +04:00
def on_confirm_forcepoweroff_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /confirm/forcepoweroff " , cb , userdata )
def on_confirm_poweroff_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /confirm/poweroff " , cb , userdata )
def on_confirm_pause_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /confirm/pause " , cb , userdata )
def on_confirm_removedev_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /confirm/removedev " , cb , userdata )
def on_confirm_interface_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /confirm/interface_power " , cb , userdata )
def on_confirm_unapplied_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /confirm/unapplied_dev " , cb , userdata )
def on_confirm_delstorage_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /confirm/delete_storage " , cb , userdata )
2009-11-19 00:11:17 +03:00
2009-11-18 23:16:57 +03:00
# System tray visibility
2012-05-14 17:24:56 +04:00
def on_view_system_tray_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /system-tray " , cb , userdata )
2009-07-28 06:30:01 +04:00
def get_view_system_tray ( self ) :
return self . conf . get_bool ( self . conf_dir + " /system-tray " )
def set_view_system_tray ( self , val ) :
self . conf . set_bool ( self . conf_dir + " /system-tray " , val )
2006-06-14 18:59:40 +04:00
2009-11-18 23:16:57 +03:00
# Stats history and interval length
2006-06-14 18:59:40 +04:00
def get_stats_update_interval ( self ) :
interval = self . conf . get_int ( self . conf_dir + " /stats/update-interval " )
if interval < 1 :
return 1
return interval
def get_stats_history_length ( self ) :
history = self . conf . get_int ( self . conf_dir + " /stats/history-length " )
if history < 10 :
return 10
return history
def set_stats_update_interval ( self , interval ) :
self . conf . set_int ( self . conf_dir + " /stats/update-interval " , interval )
def set_stats_history_length ( self , length ) :
self . conf . set_int ( self . conf_dir + " /stats/history-length " , length )
2012-05-14 17:24:56 +04:00
def on_stats_update_interval_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /stats/update-interval " , cb , userdata )
def on_stats_history_length_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /stats/history-length " , cb , userdata )
2006-06-14 18:59:40 +04:00
2008-12-17 23:27:06 +03:00
# Disable/Enable different stats polling
def get_stats_enable_disk_poll ( self ) :
return self . conf . get_bool ( self . conf_dir + " /stats/enable-disk-poll " )
def get_stats_enable_net_poll ( self ) :
return self . conf . get_bool ( self . conf_dir + " /stats/enable-net-poll " )
def set_stats_enable_disk_poll ( self , val ) :
self . conf . set_bool ( self . conf_dir + " /stats/enable-disk-poll " , val )
def set_stats_enable_net_poll ( self , val ) :
self . conf . set_bool ( self . conf_dir + " /stats/enable-net-poll " , val )
def on_stats_enable_disk_poll_changed ( self , cb , userdata = None ) :
2011-04-11 19:00:57 +04:00
return self . conf . notify_add ( self . conf_dir + " /stats/enable-disk-poll " ,
cb , userdata )
2008-12-17 23:27:06 +03:00
def on_stats_enable_net_poll_changed ( self , cb , userdata = None ) :
2011-04-11 19:00:57 +04:00
return self . conf . notify_add ( self . conf_dir + " /stats/enable-net-poll " ,
cb , userdata )
2008-12-17 23:27:06 +03:00
# VM Console preferences
2012-05-14 17:24:56 +04:00
def on_console_accels_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /console/enable-accels " , cb , userdata )
2010-12-02 21:41:22 +03:00
def get_console_accels ( self ) :
console_pref = self . conf . get_bool ( self . conf_dir +
" /console/enable-accels " )
2012-11-08 17:15:02 +04:00
if console_pref is None :
2010-12-02 21:41:22 +03:00
console_pref = False
2006-10-31 22:29:22 +03:00
return console_pref
2010-12-02 21:41:22 +03:00
def set_console_accels ( self , pref ) :
self . conf . set_bool ( self . conf_dir + " /console/enable-accels " , pref )
2006-06-14 18:59:40 +04:00
2012-05-14 17:24:56 +04:00
def on_console_scaling_changed ( self , cb , userdata = None ) :
return self . conf . notify_add ( self . conf_dir + " /console/scaling " , cb , userdata )
2009-02-24 02:50:47 +03:00
def get_console_scaling ( self ) :
2009-05-11 18:45:25 +04:00
ret = self . conf . get ( self . conf_dir + " /console/scaling " )
2012-11-08 17:15:02 +04:00
if ret is not None :
2009-05-11 18:45:25 +04:00
ret = ret . get_int ( )
return ret
2009-02-24 02:50:47 +03:00
def set_console_scaling ( self , pref ) :
self . conf . set_int ( self . conf_dir + " /console/scaling " , pref )
2009-11-18 23:16:57 +03:00
# Show VM details toolbar
2008-09-06 00:34:14 +04:00
def get_details_show_toolbar ( self ) :
2008-09-08 02:43:33 +04:00
res = self . conf . get_bool ( self . conf_dir + " /details/show-toolbar " )
2012-11-08 17:15:02 +04:00
if res is None :
2008-09-08 02:43:33 +04:00
res = True
return res
2008-09-06 00:34:14 +04:00
def set_details_show_toolbar ( self , state ) :
self . conf . set_bool ( self . conf_dir + " /details/show-toolbar " , state )
2009-11-29 04:07:01 +03:00
# VM details default size
def get_details_window_size ( self ) :
w = self . conf . get_int ( self . conf_dir + " /details/window_width " )
h = self . conf . get_int ( self . conf_dir + " /details/window_height " )
return ( w , h )
def set_details_window_size ( self , w , h ) :
self . conf . set_int ( self . conf_dir + " /details/window_width " , w )
self . conf . set_int ( self . conf_dir + " /details/window_height " , h )
2009-11-18 23:16:57 +03:00
# Create sound device for default guest
2008-09-02 20:09:39 +04:00
def get_local_sound ( self ) :
return self . conf . get_bool ( self . conf_dir + " /new-vm/local-sound " )
def get_remote_sound ( self ) :
return self . conf . get_bool ( self . conf_dir + " /new-vm/remote-sound " )
def set_local_sound ( self , state ) :
self . conf . set_bool ( self . conf_dir + " /new-vm/local-sound " , state )
def set_remote_sound ( self , state ) :
self . conf . set_bool ( self . conf_dir + " /new-vm/remote-sound " , state )
2007-06-19 21:20:29 +04:00
2009-11-18 23:16:57 +03:00
def on_sound_local_changed ( self , cb , data = None ) :
2011-04-12 22:57:32 +04:00
return self . conf . notify_add ( self . conf_dir + " /new-vm/local-sound " , cb , data )
2009-11-18 23:16:57 +03:00
def on_sound_remote_changed ( self , cb , data = None ) :
2011-04-12 22:57:32 +04:00
return self . conf . notify_add ( self . conf_dir + " /new-vm/remote-sound " , cb , data )
2009-02-12 21:32:55 +03:00
2011-03-18 15:59:14 +03:00
def get_graphics_type ( self ) :
2011-03-24 18:37:26 +03:00
ret = self . conf . get_string ( self . conf_dir + " /new-vm/graphics_type " )
2013-03-17 05:32:29 +04:00
if ret == " system " :
return self . default_graphics_from_config
2011-03-24 18:37:26 +03:00
if ret not in [ " vnc " , " spice " ] :
return " vnc "
return ret
2011-03-18 15:59:14 +03:00
def set_graphics_type ( self , gtype ) :
self . conf . set_string ( self . conf_dir + " /new-vm/graphics_type " ,
gtype . lower ( ) )
def on_graphics_type_changed ( self , cb , data = None ) :
2011-04-12 22:57:32 +04:00
return self . conf . notify_add ( self . conf_dir + " /new-vm/graphics_type " ,
cb , data )
2011-03-18 15:59:14 +03:00
2012-02-13 23:49:00 +04:00
def get_storage_format ( self ) :
ret = self . conf . get_string ( self . conf_dir + " /new-vm/storage-format " )
if ret not in [ " default " , " raw " , " qcow2 " ] :
return " default "
return ret
def set_storage_format ( self , typ ) :
self . conf . set_string ( self . conf_dir + " /new-vm/storage-format " ,
typ . lower ( ) )
def on_storage_format_changed ( self , cb , data = None ) :
return self . conf . notify_add ( self . conf_dir + " /new-vm/storage-format " ,
cb , data )
2006-10-11 17:07:45 +04:00
2009-11-18 23:16:57 +03:00
# URL/Media path history
2009-05-11 19:00:03 +04:00
def _url_add_helper ( self , gconf_path , url ) :
2012-05-14 17:24:56 +04:00
urls = self . get_string_list ( gconf_path )
2012-11-08 17:15:02 +04:00
if urls is None :
2006-10-11 17:07:45 +04:00
urls = [ ]
2009-05-11 19:00:03 +04:00
if urls . count ( url ) == 0 and len ( url ) > 0 and not url . isspace ( ) :
# The url isn't already in the list, so add it
2010-11-29 22:06:43 +03:00
urls . insert ( 0 , url )
2006-10-11 17:07:45 +04:00
length = self . get_url_list_length ( )
if len ( urls ) > length :
2010-12-10 19:47:07 +03:00
del urls [ len ( urls ) - 1 ]
2012-05-14 17:24:56 +04:00
self . set_string_list ( gconf_path , urls )
2009-05-11 19:00:03 +04:00
def add_media_url ( self , url ) :
self . _url_add_helper ( self . conf_dir + " /urls/media " , url )
2006-10-11 17:07:45 +04:00
def add_kickstart_url ( self , url ) :
2009-05-11 19:00:03 +04:00
self . _url_add_helper ( self . conf_dir + " /urls/kickstart " , url )
def add_iso_path ( self , path ) :
self . _url_add_helper ( self . conf_dir + " /urls/local_media " , path )
2006-10-11 17:07:45 +04:00
2009-11-18 23:16:57 +03:00
def get_media_urls ( self ) :
2012-05-14 17:24:56 +04:00
return self . get_string_list ( self . conf_dir + " /urls/media " )
2009-11-18 23:16:57 +03:00
def get_kickstart_urls ( self ) :
2012-05-14 17:24:56 +04:00
return self . get_string_list ( self . conf_dir + " /urls/kickstart " )
2009-11-18 23:16:57 +03:00
def get_iso_paths ( self ) :
2012-05-14 17:24:56 +04:00
return self . get_string_list ( self . conf_dir + " /urls/local_media " )
2009-11-18 23:16:57 +03:00
def get_url_list_length ( self ) :
length = self . conf . get_int ( self . conf_dir + " /urls/url-list-length " )
if length < 5 :
return 5
return length
def set_url_list_length ( self , length ) :
self . conf . set_int ( self . conf_dir + " /urls/url-list-length " , length )
2009-12-01 20:23:19 +03:00
# Whether to ask about fixing path permissions
def add_perms_fix_ignore ( self , pathlist ) :
current_list = self . get_perms_fix_ignore ( ) or [ ]
for path in pathlist :
if path in current_list :
continue
current_list . append ( path )
2012-05-14 17:24:56 +04:00
self . set_string_list ( self . conf_dir + " /paths/perms_fix_ignore " ,
current_list )
2009-12-01 20:23:19 +03:00
def get_perms_fix_ignore ( self ) :
2012-05-14 17:24:56 +04:00
return self . get_string_list ( self . conf_dir + " /paths/perms_fix_ignore " )
2009-12-01 20:23:19 +03:00
2009-11-18 23:16:57 +03:00
# Manager view connection list
2011-07-23 00:43:26 +04:00
def add_conn ( self , uri ) :
2012-10-29 02:49:48 +04:00
if self . test_first_run :
return
2012-05-14 17:24:56 +04:00
uris = self . get_string_list ( self . conf_dir + " /connections/uris " )
2012-11-08 17:15:02 +04:00
if uris is None :
2007-08-29 01:57:25 +04:00
uris = [ ]
2008-03-24 18:39:19 +03:00
2009-11-18 23:16:57 +03:00
if uris . count ( uri ) == 0 :
uris . insert ( len ( uris ) - 1 , uri )
2012-05-14 17:24:56 +04:00
self . set_string_list ( self . conf_dir + " /connections/uris " , uris )
2011-07-23 00:43:26 +04:00
def remove_conn ( self , uri ) :
2012-05-14 17:24:56 +04:00
uris = self . get_string_list ( self . conf_dir + " /connections/uris " )
2012-11-08 17:15:02 +04:00
if uris is None :
2007-08-29 01:57:25 +04:00
return
2009-11-18 23:16:57 +03:00
2007-08-29 01:57:25 +04:00
if uris . count ( uri ) != 0 :
uris . remove ( uri )
2012-05-14 17:24:56 +04:00
self . set_string_list ( self . conf_dir + " /connections/uris " , uris )
2009-11-18 23:16:57 +03:00
2008-03-24 18:39:19 +03:00
if self . get_conn_autoconnect ( uri ) :
2012-05-14 17:24:56 +04:00
uris = self . get_string_list ( self . conf_dir +
" /connections/autoconnect " )
2008-03-24 18:39:19 +03:00
uris . remove ( uri )
2012-05-14 17:24:56 +04:00
self . set_string_list ( self . conf_dir + " /connections/autoconnect " ,
uris )
2008-03-24 18:39:19 +03:00
2011-07-23 00:43:26 +04:00
def get_conn_uris ( self ) :
2012-10-29 02:49:48 +04:00
if self . test_first_run :
return [ ]
2012-05-14 17:24:56 +04:00
return self . get_string_list ( self . conf_dir + " /connections/uris " )
2008-03-24 18:39:19 +03:00
2009-11-29 05:00:46 +03:00
# Manager default window size
def get_manager_window_size ( self ) :
w = self . conf . get_int ( self . conf_dir + " /manager_window_width " )
h = self . conf . get_int ( self . conf_dir + " /manager_window_height " )
return ( w , h )
def set_manager_window_size ( self , w , h ) :
self . conf . set_int ( self . conf_dir + " /manager_window_width " , w )
self . conf . set_int ( self . conf_dir + " /manager_window_height " , h )
2009-11-18 23:16:57 +03:00
# URI autoconnect
2008-03-24 18:39:19 +03:00
def get_conn_autoconnect ( self , uri ) :
2012-05-14 17:24:56 +04:00
uris = self . get_string_list ( self . conf_dir + " /connections/autoconnect " )
2008-03-24 18:39:19 +03:00
return ( ( uris is not None ) and ( uri in uris ) )
2009-11-25 22:16:31 +03:00
def set_conn_autoconnect ( self , uri , val ) :
2012-10-29 02:49:48 +04:00
if self . test_first_run :
return
2012-05-14 17:24:56 +04:00
uris = self . get_string_list ( self . conf_dir + " /connections/autoconnect " )
2008-03-24 18:39:19 +03:00
if uris is None :
uris = [ ]
2009-11-25 22:16:31 +03:00
if not val and uri in uris :
2008-03-24 18:39:19 +03:00
uris . remove ( uri )
2009-11-25 22:16:31 +03:00
elif val and uri not in uris :
2008-03-24 18:39:19 +03:00
uris . append ( uri )
2009-11-25 22:16:31 +03:00
2012-05-14 17:24:56 +04:00
self . set_string_list ( self . conf_dir + " /connections/autoconnect " ,
uris )
2007-08-29 01:57:25 +04:00
2009-05-11 19:00:03 +04:00
2009-11-18 23:16:57 +03:00
# Default directory location dealings
2011-07-23 03:12:48 +04:00
def _get_default_dir_key ( self , typ ) :
if ( typ == self . CONFIG_DIR_ISO_MEDIA or
typ == self . CONFIG_DIR_FLOPPY_MEDIA ) :
return " media "
return typ
2009-11-18 23:16:57 +03:00
def get_default_directory ( self , conn , _type ) :
if not _type :
2012-01-17 07:04:40 +04:00
logging . error ( " Unknown type ' %s ' for get_default_directory " , _type )
2009-11-18 23:16:57 +03:00
return
2007-08-29 01:57:25 +04:00
2011-07-23 03:12:48 +04:00
key = self . _get_default_dir_key ( _type )
2009-11-18 23:16:57 +03:00
try :
2011-07-23 03:12:48 +04:00
path = self . conf . get_value ( self . conf_dir +
" /paths/default- %s -path " % key )
2009-11-18 23:16:57 +03:00
except :
path = None
if not path :
if ( _type == self . CONFIG_DIR_IMAGE or
2011-07-23 03:12:48 +04:00
_type == self . CONFIG_DIR_ISO_MEDIA or
_type == self . CONFIG_DIR_FLOPPY_MEDIA ) :
2009-11-18 23:16:57 +03:00
path = self . get_default_image_dir ( conn )
if ( _type == self . CONFIG_DIR_SAVE or
_type == self . CONFIG_DIR_RESTORE ) :
path = self . get_default_save_dir ( conn )
2012-01-17 07:04:40 +04:00
logging . debug ( " get_default_directory( %s ): returning %s " , _type , path )
2009-11-18 23:16:57 +03:00
return path
def set_default_directory ( self , folder , _type ) :
if not _type :
logging . error ( " Unknown type for set_default_directory " )
return
2012-01-17 07:04:40 +04:00
logging . debug ( " set_default_directory( %s ): saving %s " , _type , folder )
2010-01-30 20:41:31 +03:00
self . conf . set_string ( self . conf_dir + " /paths/default- %s -path " % _type ,
folder )
2007-04-12 19:46:51 +04:00
2011-07-23 00:43:26 +04:00
def get_default_image_dir ( self , conn ) :
if conn . is_xen ( ) :
2011-04-18 21:14:14 +04:00
return self . DEFAULT_XEN_IMAGE_DIR
2008-09-05 17:42:25 +04:00
2011-07-23 00:43:26 +04:00
if ( conn . is_qemu_session ( ) or
2011-04-18 21:14:14 +04:00
not os . access ( self . DEFAULT_VIRT_IMAGE_DIR , os . W_OK ) ) :
2008-10-10 20:06:41 +04:00
return os . getcwd ( )
2009-04-22 23:44:07 +04:00
2008-09-05 17:42:25 +04:00
# Just return the default dir since the intention is that it
# is a managed pool and the user will be able to install to it.
2011-04-18 21:14:14 +04:00
return self . DEFAULT_VIRT_IMAGE_DIR
2007-04-12 19:46:51 +04:00
2011-07-23 00:43:26 +04:00
def get_default_save_dir ( self , conn ) :
if conn . is_xen ( ) :
2011-04-18 21:14:14 +04:00
return self . DEFAULT_XEN_SAVE_DIR
elif os . access ( self . DEFAULT_VIRT_SAVE_DIR , os . W_OK ) :
return self . DEFAULT_VIRT_SAVE_DIR
2007-04-12 19:46:51 +04:00
else :
return os . getcwd ( )
2009-11-18 23:16:57 +03:00
# Keyring / VNC password dealings
def get_secret_name ( self , vm ) :
return " vm-console- " + vm . get_uuid ( )
def has_keyring ( self ) :
2012-11-08 17:15:02 +04:00
if self . keyring is None :
2009-11-18 23:16:57 +03:00
self . keyring = vmmKeyring ( )
return self . keyring . is_available ( )
2012-11-09 19:08:15 +04:00
def get_console_password ( self , vm ) :
keyid = self . conf . get_int ( self . conf_dir +
" /console/passwords/ " + vm . get_uuid ( ) )
username = self . conf . get_string ( self . conf_dir +
" /console/usernames/ " + vm . get_uuid ( ) )
if keyid is None or not self . has_keyring ( ) :
return ( " " , " " )
2009-11-18 23:16:57 +03:00
2012-11-09 19:08:15 +04:00
secret = self . keyring . get_secret ( keyid )
if secret is None or secret . get_name ( ) != self . get_secret_name ( vm ) :
return ( " " , " " )
2009-11-18 23:16:57 +03:00
2012-11-09 19:08:15 +04:00
if ( secret . attributes . get ( " hvuri " , None ) != vm . conn . get_uri ( ) or
secret . attributes . get ( " uuid " , None ) != vm . get_uuid ( ) ) :
return ( " " , " " )
return ( secret . get_secret ( ) , username or " " )
2009-11-18 23:16:57 +03:00
def set_console_password ( self , vm , password , username = " " ) :
2012-11-09 19:08:15 +04:00
if not self . has_keyring ( ) :
2009-11-18 23:16:57 +03:00
return
# Nb, we don't bother to check if there is an existing
# secret, because gnome-keyring auto-replaces an existing
# one if the attributes match - which they will since UUID
# is our unique key
2010-12-10 19:47:07 +03:00
secret = vmmSecret ( self . get_secret_name ( vm ) , password ,
{ " uuid " : vm . get_uuid ( ) ,
2011-07-23 00:43:26 +04:00
" hvuri " : vm . conn . get_uri ( ) } )
2012-11-09 19:08:15 +04:00
keyid = self . keyring . add_secret ( secret )
if keyid is None :
return
self . conf . set_int ( self . conf_dir +
" /console/passwords/ " + vm . get_uuid ( ) , keyid )
self . conf . set_string ( self . conf_dir +
" /console/usernames/ " + vm . get_uuid ( ) , username )