2015-02-24 13:21:24 +01:00
# Copyright (C) 2006, 2012-2015 Red Hat, Inc.
2006-06-28 15:50:17 -04:00
# Copyright (C) 2006 Daniel P. Berrange <berrange@redhat.com>
#
2018-04-04 14:35:41 +01:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 15:00:02 -04:00
# See the COPYING file in the top-level directory.
2013-04-17 17:39:25 -04:00
from gi . repository import Gio
from gi . repository import GLib
2012-05-14 14:24:56 +01:00
from gi . repository import Gtk
2011-01-07 14:59:31 -05:00
2018-03-20 15:10:04 -04:00
from virtinst import DomainCpu
2019-06-16 21:12:39 -04:00
from virtinst import log
2018-03-13 13:00:59 -04:00
2019-06-16 22:19:17 -04:00
from . lib . inspection import vmmInspection
2012-11-09 16:08:15 +01:00
2013-08-09 09:23:01 -04:00
2020-02-01 17:16:45 -05:00
CSSDATA = """
/ * Lighter colored text in some wizard summary fields * /
. vmm - lighter {
color : @insensitive_fg_color
}
/ * Text on the blue header in our wizards * /
. vmm - header - text {
color : white
}
/ * Subtext on the blue header in our wizards * /
. vmm - header - subtext {
color : #59B0E2
}
/ * The blue header * /
. vmm - header {
background - color : #0072A8
}
"""
2018-03-13 12:13:11 -04:00
class _SettingsWrapper ( object ) :
2015-11-02 16:19:31 -05:00
"""
2018-01-09 17:14:47 -05:00
Wrapper class to simplify interacting with gsettings APIs .
Basically it allows simple get / set of gconf style paths , and
we internally convert it to the settings nested hierarchy . Makes
client code much smaller .
2015-11-02 16:19:31 -05:00
"""
2020-08-21 13:34:10 -04:00
def __init__ ( self , settings_id , gsettings_keyfile ) :
2013-04-17 17:39:25 -04:00
self . _root = settings_id
2020-08-21 13:34:10 -04:00
if gsettings_keyfile :
backend = Gio . keyfile_settings_backend_new ( gsettings_keyfile , " / " )
else :
backend = Gio . SettingsBackend . get_default ( )
self . _settings = Gio . Settings . new_with_backend ( self . _root , backend )
2013-04-17 17:39:25 -04:00
self . _settingsmap = { " " : self . _settings }
self . _handler_map = { }
2015-11-02 16:19:31 -05:00
2013-04-17 17:39:25 -04:00
for child in self . _settings . list_children ( ) :
childschema = self . _root + " . " + child
2020-08-21 13:34:10 -04:00
self . _settingsmap [ child ] = Gio . Settings . new_with_backend (
childschema , backend )
2013-04-17 17:39:25 -04:00
2018-01-09 17:14:47 -05:00
###################
# Private helpers #
###################
2013-04-17 17:39:25 -04:00
def _parse_key ( self , key ) :
value = key . strip ( " / " )
settingskey = " "
if " / " in value :
settingskey , value = value . rsplit ( " / " , 1 )
return settingskey , value
2018-01-09 17:14:47 -05:00
def _find_settings ( self , key ) :
settingskey , value = self . _parse_key ( key )
return self . _settingsmap [ settingskey ] , value
###############
# Public APIs #
###############
2013-04-17 17:39:25 -04:00
def make_vm_settings ( self , key ) :
2015-04-11 13:39:25 -04:00
"""
Initialize per - VM relocatable schema if necessary
"""
2013-04-17 17:39:25 -04:00
settingskey = self . _parse_key ( key ) [ 0 ]
if settingskey in self . _settingsmap :
return True
schema = self . _root + " .vm "
path = " / " + self . _root . replace ( " . " , " / " ) + key . rsplit ( " / " , 1 ) [ 0 ] + " / "
2015-04-11 13:39:25 -04:00
self . _settingsmap [ settingskey ] = Gio . Settings . new_with_path (
schema , path )
return True
def make_conn_settings ( self , key ) :
"""
Initialize per - conn relocatable schema if necessary
"""
settingskey = self . _parse_key ( key ) [ 0 ]
if settingskey in self . _settingsmap :
return True
schema = self . _root + " .connection "
path = " / " + self . _root . replace ( " . " , " / " ) + key . rsplit ( " / " , 1 ) [ 0 ] + " / "
self . _settingsmap [ settingskey ] = Gio . Settings . new_with_path (
schema , path )
2013-04-17 17:39:25 -04:00
return True
def notify_add ( self , key , cb , * args , * * kwargs ) :
settings , key = self . _find_settings ( key )
def wrapcb ( * ignore ) :
return cb ( * args , * * kwargs )
ret = settings . connect ( " changed:: %s " % key , wrapcb , * args , * * kwargs )
self . _handler_map [ ret ] = settings
return ret
def notify_remove ( self , h ) :
settings = self . _handler_map . pop ( h )
return settings . disconnect ( h )
def get ( self , key ) :
2018-01-09 17:14:47 -05:00
settings , key = self . _find_settings ( key )
return settings . get_value ( key ) . unpack ( )
2013-04-17 17:39:25 -04:00
def set ( self , key , value , * args , * * kwargs ) :
2018-01-09 17:14:47 -05:00
settings , key = self . _find_settings ( key )
fmt = settings . get_value ( key ) . get_type_string ( )
return settings . set_value ( key , GLib . Variant ( fmt , value ) ,
* args , * * kwargs )
2009-02-23 18:50:47 -05:00
2013-04-17 17:39:25 -04:00
class vmmConfig ( object ) :
# key names for saving last used paths
2009-06-23 19:30:12 -04:00
CONFIG_DIR_IMAGE = " image "
2011-07-22 19:12:48 -04:00
CONFIG_DIR_ISO_MEDIA = " isomedia "
CONFIG_DIR_FLOPPY_MEDIA = " floppymedia "
2009-06-23 19:30:12 -04:00
CONFIG_DIR_SCREENSHOT = " screenshot "
2011-06-08 18:37:35 -04:00
CONFIG_DIR_FS = " fs "
2009-06-23 19:30:12 -04:00
2009-11-10 14:30:51 -05:00
# Metadata mapping for browse types. Prob shouldn't go here, but works
# for now.
browse_reason_data = {
2017-08-05 14:39:32 +08:00
CONFIG_DIR_IMAGE : {
" enable_create " : True ,
" storage_title " : _ ( " Locate or create storage volume " ) ,
" local_title " : _ ( " Locate existing storage " ) ,
" dialog_type " : Gtk . FileChooserAction . SAVE ,
" choose_button " : Gtk . STOCK_OPEN ,
2020-08-27 16:37:15 -04:00
" gsettings_key " : " image " ,
} ,
CONFIG_DIR_SCREENSHOT : {
" gsettings_key " : " screenshot " ,
2009-11-10 14:30:51 -05:00
} ,
2017-08-05 14:39:32 +08:00
CONFIG_DIR_ISO_MEDIA : {
" enable_create " : False ,
" storage_title " : _ ( " Locate ISO media volume " ) ,
" local_title " : _ ( " Locate ISO media " ) ,
2020-08-27 16:37:15 -04:00
" gsettings_key " : " media " ,
2011-06-08 18:37:35 -04:00
} ,
2017-08-05 14:39:32 +08:00
CONFIG_DIR_FLOPPY_MEDIA : {
" enable_create " : False ,
" storage_title " : _ ( " Locate floppy media volume " ) ,
" local_title " : _ ( " Locate floppy media " ) ,
2020-08-27 16:37:15 -04:00
" gsettings_key " : " media " ,
2011-07-22 19:12:48 -04:00
} ,
2017-08-05 14:39:32 +08:00
CONFIG_DIR_FS : {
" enable_create " : False ,
" storage_title " : _ ( " Locate directory volume " ) ,
" local_title " : _ ( " Locate directory volume " ) ,
" dialog_type " : Gtk . FileChooserAction . SELECT_FOLDER ,
2011-06-08 18:37:35 -04:00
} ,
2009-11-10 14:30:51 -05:00
}
2009-02-23 18:50:47 -05:00
CONSOLE_SCALE_NEVER = 0
CONSOLE_SCALE_FULLSCREEN = 1
CONSOLE_SCALE_ALWAYS = 2
2018-03-13 12:13:11 -04:00
_instance = None
@classmethod
def get_instance ( cls , * args , * * kwargs ) :
if not cls . _instance :
cls . _instance = vmmConfig ( * args , * * kwargs )
return cls . _instance
@classmethod
def is_initialized ( cls ) :
return bool ( cls . _instance )
2019-06-14 16:34:00 -04:00
def __init__ ( self , BuildConfig , CLITestOptions ) :
2018-03-13 12:13:11 -04:00
self . appname = " virt-manager "
2019-06-14 16:34:00 -04:00
self . appversion = BuildConfig . version
2013-04-17 17:39:25 -04:00
self . conf_dir = " /org/virt-manager/ %s / " % self . appname
2019-06-14 16:34:00 -04:00
self . ui_dir = BuildConfig . ui_dir
2011-07-13 18:48:02 -04:00
2020-08-21 13:34:10 -04:00
self . conf = _SettingsWrapper ( " org.virt-manager.virt-manager " ,
CLITestOptions . gsettings_keyfile )
2010-12-13 11:22:01 -05:00
2019-06-05 13:19:44 -04:00
self . CLITestOptions = CLITestOptions
2019-06-05 17:40:54 -04:00
if self . CLITestOptions . xmleditor_enabled :
self . set_xmleditor_enabled ( True )
2020-08-29 13:07:19 -04:00
if self . CLITestOptions . enable_libguestfs :
self . set_libguestfs_inspect_vms ( True )
if self . CLITestOptions . disable_libguestfs :
self . set_libguestfs_inspect_vms ( False )
2019-06-05 13:19:44 -04:00
2006-08-21 17:45:24 -04:00
# We don't create it straight away, since we don't want
2014-03-30 22:57:21 +08:00
# to block the app pending user authorization to access
2006-07-19 14:33:23 -04:00
# the keyring
2020-08-26 09:03:09 -04:00
self . _keyring = None
2006-06-14 10:59:40 -04:00
2019-06-14 16:34:00 -04:00
self . default_graphics_from_config = BuildConfig . default_graphics
self . default_hvs = BuildConfig . default_hvs
2014-01-31 09:13:53 -05:00
2013-10-02 15:17:15 -04:00
self . default_storage_format_from_config = " qcow2 "
2014-01-31 09:13:53 -05:00
self . default_console_resizeguest = 0
2010-12-13 14:31:27 -05:00
2011-04-11 12:54:47 -04:00
self . _objects = [ ]
2020-02-01 17:16:45 -05:00
self . color_insensitive = None
self . _init_css ( )
def _init_css ( self ) :
from gi . repository import Gdk
screen = Gdk . Screen . get_default ( )
css_provider = Gtk . CssProvider ( )
css_provider . load_from_data ( CSSDATA . encode ( " utf-8 " ) )
context = Gtk . StyleContext ( )
context . add_provider_for_screen ( screen , css_provider ,
Gtk . STYLE_PROVIDER_PRIORITY_USER )
found , color = context . lookup_color ( " insensitive_fg_color " )
2020-08-20 13:34:01 -04:00
if not found : # pragma: no cover
2020-02-01 17:16:45 -05:00
log . debug ( " Didn ' t find insensitive_fg_color in theme " )
return
self . color_insensitive = color . to_string ( )
2011-04-11 12:54:47 -04:00
2006-06-14 17:09:08 -04:00
2014-09-28 13:37:16 +02:00
# General app wide helpers (gsettings agnostic)
2009-07-20 15:09:32 -04:00
2006-06-14 10:59:40 -04:00
def get_appname ( self ) :
return self . appname
2006-08-04 15:46:06 -04:00
def get_appversion ( self ) :
return self . appversion
2012-02-01 17:26:46 -05:00
def get_ui_dir ( self ) :
return self . ui_dir
2006-06-14 10:59:40 -04:00
2011-01-07 14:59:31 -05:00
def embeddable_graphics ( self ) :
2012-05-14 14:24:56 +01:00
ret = [ " vnc " , " spice " ]
2011-01-07 14:59:31 -05:00
return ret
2018-03-13 13:00:59 -04:00
def inspection_supported ( self ) :
if not vmmInspection . libguestfs_installed ( ) :
2020-08-20 13:34:01 -04:00
return False # pragma: no cover
2018-03-13 13:00:59 -04:00
return self . get_libguestfs_inspect_vms ( )
2011-04-11 11:00:57 -04:00
def remove_notifier ( self , h ) :
self . conf . notify_remove ( h )
2011-04-11 12: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 [ : ]
2015-04-11 13:39:25 -04:00
#####################################
# Wrappers for setting per-VM value #
#####################################
2013-04-17 17:39:25 -04:00
def _make_pervm_key ( self , uuid , key ) :
return " /vms/ %s %s " % ( uuid . replace ( " - " , " " ) , key )
2009-05-11 12:37:47 -04:00
2013-04-17 17:39:25 -04:00
def listen_pervm ( self , uuid , key , * args , * * kwargs ) :
key = self . _make_pervm_key ( uuid , key )
self . conf . make_vm_settings ( key )
return self . conf . notify_add ( key , * args , * * kwargs )
2009-05-11 12:37:47 -04:00
2013-04-17 17:39:25 -04:00
def set_pervm ( self , uuid , key , * args , * * kwargs ) :
key = self . _make_pervm_key ( uuid , key )
self . conf . make_vm_settings ( key )
ret = self . conf . set ( key , * args , * * kwargs )
2009-05-11 12:37:47 -04:00
return ret
2013-04-17 17:39:25 -04:00
def get_pervm ( self , uuid , key ) :
key = self . _make_pervm_key ( uuid , key )
self . conf . make_vm_settings ( key )
return self . conf . get ( key )
2015-04-11 13:39:25 -04:00
########################################
# Wrappers for setting per-conn values #
########################################
def _make_perconn_key ( self , uri , key ) :
return " /conns/ %s %s " % ( uri . replace ( " / " , " " ) , key )
def listen_perconn ( self , uri , key , * args , * * kwargs ) :
key = self . _make_perconn_key ( uri , key )
self . conf . make_conn_settings ( key )
return self . conf . notify_add ( key , * args , * * kwargs )
def set_perconn ( self , uri , key , * args , * * kwargs ) :
key = self . _make_perconn_key ( uri , key )
self . conf . make_conn_settings ( key )
ret = self . conf . set ( key , * args , * * kwargs )
return ret
def get_perconn ( self , uri , key ) :
key = self . _make_perconn_key ( uri , key )
self . conf . make_conn_settings ( key )
return self . conf . get ( key )
2013-04-17 17:39:25 -04:00
###################
# General helpers #
###################
2009-11-18 15:16:57 -05:00
# Manager stats view preferences
2011-07-12 08:49:47 -04:00
def is_vmlist_guest_cpu_usage_visible ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /vmlist-fields/cpu-usage " )
2011-07-12 08:49:47 -04:00
def is_vmlist_host_cpu_usage_visible ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /vmlist-fields/host-cpu-usage " )
2013-12-18 14:42:42 +01:00
def is_vmlist_memory_usage_visible ( self ) :
return self . conf . get ( " /vmlist-fields/memory-usage " )
2009-11-11 11:02:57 -05:00
def is_vmlist_disk_io_visible ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /vmlist-fields/disk-usage " )
2009-11-11 11:02:57 -05:00
def is_vmlist_network_traffic_visible ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /vmlist-fields/network-traffic " )
2009-11-11 11:02:57 -05:00
2011-07-12 08:49:47 -04:00
def set_vmlist_guest_cpu_usage_visible ( self , state ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /vmlist-fields/cpu-usage " , state )
2011-07-12 08:49:47 -04:00
def set_vmlist_host_cpu_usage_visible ( self , state ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /vmlist-fields/host-cpu-usage " , state )
2013-12-18 14:42:42 +01:00
def set_vmlist_memory_usage_visible ( self , state ) :
self . conf . set ( " /vmlist-fields/memory-usage " , state )
2009-11-11 11:02:57 -05:00
def set_vmlist_disk_io_visible ( self , state ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /vmlist-fields/disk-usage " , state )
2009-11-11 11:02:57 -05:00
def set_vmlist_network_traffic_visible ( self , state ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /vmlist-fields/network-traffic " , state )
def on_vmlist_guest_cpu_usage_visible_changed ( self , cb ) :
return self . conf . notify_add ( " /vmlist-fields/cpu-usage " , cb )
def on_vmlist_host_cpu_usage_visible_changed ( self , cb ) :
return self . conf . notify_add ( " /vmlist-fields/host-cpu-usage " , cb )
2013-12-18 14:42:42 +01:00
def on_vmlist_memory_usage_visible_changed ( self , cb ) :
return self . conf . notify_add ( " /vmlist-fields/memory-usage " , cb )
2013-04-17 17:39:25 -04:00
def on_vmlist_disk_io_visible_changed ( self , cb ) :
return self . conf . notify_add ( " /vmlist-fields/disk-usage " , cb )
def on_vmlist_network_traffic_visible_changed ( self , cb ) :
return self . conf . notify_add ( " /vmlist-fields/network-traffic " , cb )
2009-06-23 19:30:12 -04:00
2010-08-23 11:50:36 -04:00
# Keys preferences
2012-01-29 21:51:20 -05:00
def get_keys_combination ( self ) :
2013-04-17 17:39:25 -04:00
ret = self . conf . get ( " /console/grab-keys " )
2012-01-29 21:51:20 -05:00
if not ret :
# Left Control + Left Alt
return " 65507,65513 "
return ret
2010-08-23 11:50:36 -04:00
def set_keys_combination ( self , val ) :
# Val have to be a list of integers
2013-04-11 16:32:00 -04:00
val = ' , ' . join ( [ str ( v ) for v in val ] )
2013-04-17 17:39:25 -04:00
self . conf . set ( " /console/grab-keys " , val )
def on_keys_combination_changed ( self , cb ) :
return self . conf . notify_add ( " /console/grab-keys " , cb )
2006-06-14 10:59:40 -04:00
2009-11-18 16:11:17 -05:00
# Confirmation preferences
def get_confirm_forcepoweroff ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /confirm/forcepoweroff " )
2009-11-18 16:11:17 -05:00
def get_confirm_poweroff ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /confirm/poweroff " )
2009-11-18 16:11:17 -05:00
def get_confirm_pause ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /confirm/pause " )
2009-11-18 16:46:36 -05:00
def get_confirm_removedev ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /confirm/removedev " )
2011-07-19 20:29:07 -04:00
def get_confirm_unapplied ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /confirm/unapplied-dev " )
2012-12-03 17:12:59 +01:00
def get_confirm_delstorage ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /confirm/delete-storage " )
2010-02-08 22:34:23 -05:00
2009-11-18 16:11:17 -05:00
def set_confirm_forcepoweroff ( self , val ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /confirm/forcepoweroff " , val )
2009-11-18 16:11:17 -05:00
def set_confirm_poweroff ( self , val ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /confirm/poweroff " , val )
2009-11-18 16:11:17 -05:00
def set_confirm_pause ( self , val ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /confirm/pause " , val )
2009-11-18 16:46:36 -05:00
def set_confirm_removedev ( self , val ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /confirm/removedev " , val )
2011-07-19 20:29:07 -04:00
def set_confirm_unapplied ( self , val ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /confirm/unapplied-dev " , val )
2012-12-03 17:12:59 +01:00
def set_confirm_delstorage ( self , val ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /confirm/delete-storage " , val )
2009-11-18 16:11:17 -05:00
2009-11-18 15:16:57 -05:00
# System tray visibility
2013-04-17 17:39:25 -04:00
def on_view_system_tray_changed ( self , cb ) :
return self . conf . notify_add ( " /system-tray " , cb )
2009-07-27 22:30:01 -04:00
def get_view_system_tray ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /system-tray " )
2009-07-27 22:30:01 -04:00
def set_view_system_tray ( self , val ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /system-tray " , val )
2009-07-27 22:30:01 -04:00
2019-06-05 17:40:54 -04:00
# XML editor enabled
def on_xmleditor_enabled_changed ( self , cb ) :
return self . conf . notify_add ( " /xmleditor-enabled " , cb )
def get_xmleditor_enabled ( self ) :
return self . conf . get ( " /xmleditor-enabled " )
def set_xmleditor_enabled ( self , val ) :
self . conf . set ( " /xmleditor-enabled " , val )
2018-03-13 13:00:59 -04:00
# Libguestfs VM inspection
def get_libguestfs_inspect_vms ( self ) :
return self . conf . get ( " /enable-libguestfs-vm-inspection " )
def set_libguestfs_inspect_vms ( self , val ) :
self . conf . set ( " /enable-libguestfs-vm-inspection " , val )
2006-06-14 10:59:40 -04:00
2009-11-18 15:16:57 -05:00
# Stats history and interval length
2013-04-23 13:18:21 -04:00
def get_stats_history_length ( self ) :
return 120
2006-06-14 10:59:40 -04:00
def get_stats_update_interval ( self ) :
2020-09-20 10:07:15 -04:00
if self . CLITestOptions . short_poll :
return .1
2013-04-17 17:39:25 -04:00
interval = self . conf . get ( " /stats/update-interval " )
2020-08-27 16:37:15 -04:00
return max ( interval , 1 )
2006-06-14 10:59:40 -04:00
def set_stats_update_interval ( self , interval ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /stats/update-interval " , interval )
def on_stats_update_interval_changed ( self , cb ) :
return self . conf . notify_add ( " /stats/update-interval " , cb )
2006-06-14 10:59:40 -04:00
2008-12-17 15:27:06 -05:00
# Disable/Enable different stats polling
2014-02-11 15:29:30 -05:00
def get_stats_enable_cpu_poll ( self ) :
return self . conf . get ( " /stats/enable-cpu-poll " )
2008-12-17 15:27:06 -05:00
def get_stats_enable_disk_poll ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /stats/enable-disk-poll " )
2008-12-17 15:27:06 -05:00
def get_stats_enable_net_poll ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /stats/enable-net-poll " )
2014-01-12 17:39:21 -05:00
def get_stats_enable_memory_poll ( self ) :
return self . conf . get ( " /stats/enable-memory-poll " )
2008-12-17 15:27:06 -05:00
2014-02-11 15:29:30 -05:00
def set_stats_enable_cpu_poll ( self , val ) :
self . conf . set ( " /stats/enable-cpu-poll " , val )
2008-12-17 15:27:06 -05:00
def set_stats_enable_disk_poll ( self , val ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /stats/enable-disk-poll " , val )
2008-12-17 15:27:06 -05:00
def set_stats_enable_net_poll ( self , val ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /stats/enable-net-poll " , val )
2014-01-12 17:39:21 -05:00
def set_stats_enable_memory_poll ( self , val ) :
self . conf . set ( " /stats/enable-memory-poll " , val )
2008-12-17 15:27:06 -05:00
2014-02-11 15:29:30 -05:00
def on_stats_enable_cpu_poll_changed ( self , cb , row = None ) :
return self . conf . notify_add ( " /stats/enable-cpu-poll " , cb , row )
2013-04-17 17:39:25 -04:00
def on_stats_enable_disk_poll_changed ( self , cb , row = None ) :
return self . conf . notify_add ( " /stats/enable-disk-poll " , cb , row )
def on_stats_enable_net_poll_changed ( self , cb , row = None ) :
return self . conf . notify_add ( " /stats/enable-net-poll " , cb , row )
2014-01-12 17:39:21 -05:00
def on_stats_enable_memory_poll_changed ( self , cb , row = None ) :
return self . conf . notify_add ( " /stats/enable-memory-poll " , cb , row )
2008-12-17 15:27:06 -05:00
2009-02-23 18:50:47 -05:00
def get_console_scaling ( self ) :
2013-04-17 17:39:25 -04:00
return self . conf . get ( " /console/scaling " )
2009-02-23 18:50:47 -05:00
def set_console_scaling ( self , pref ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /console/scaling " , pref )
2009-02-23 18:50:47 -05:00
2014-01-31 09:13:53 -05:00
def get_console_resizeguest ( self ) :
val = self . conf . get ( " /console/resize-guest " )
if val == - 1 :
val = self . default_console_resizeguest
return val
def set_console_resizeguest ( self , pref ) :
self . conf . set ( " /console/resize-guest " , pref )
2018-03-16 14:38:22 -04:00
def get_auto_usbredir ( self ) :
return bool ( self . conf . get ( " /console/auto-redirect " ) )
def set_auto_usbredir ( self , state ) :
2013-07-01 14:32:21 -04:00
self . conf . set ( " /console/auto-redirect " , state )
2020-09-09 19:04:44 -04:00
def get_console_autoconnect ( self ) :
return bool ( self . conf . get ( " /console/autoconnect " ) )
def set_console_autoconnect ( self , val ) :
return self . conf . set ( " /console/autoconnect " , val )
2009-11-18 15:16:57 -05:00
# Show VM details toolbar
2008-09-05 16:34:14 -04:00
def get_details_show_toolbar ( self ) :
2013-04-17 17:39:25 -04:00
res = self . conf . get ( " /details/show-toolbar " )
2012-11-08 14:15:02 +01:00
if res is None :
2020-08-27 16:37:15 -04:00
res = True # pragma: no cover
2008-09-07 18:43:33 -04:00
return res
2008-09-05 16:34:14 -04:00
def set_details_show_toolbar ( self , state ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /details/show-toolbar " , state )
2008-09-05 16:34:14 -04:00
2014-01-17 15:32:40 -05:00
# New VM preferences
2013-10-02 14:47:21 -04:00
def get_graphics_type ( self , raw = False ) :
2013-04-17 17:39:25 -04:00
ret = self . conf . get ( " /new-vm/graphics-type " )
2013-10-02 14:47:21 -04:00
if ret not in [ " system " , " vnc " , " spice " ] :
2020-08-27 16:37:15 -04:00
ret = " system " # pragma: no cover
2013-10-02 14:47:21 -04:00
if ret == " system " and not raw :
2013-03-16 21:32:29 -04:00
return self . default_graphics_from_config
2011-03-24 11:37:26 -04:00
return ret
2011-03-18 13:59:14 +01:00
def set_graphics_type ( self , gtype ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /new-vm/graphics-type " , gtype . lower ( ) )
2011-03-18 13:59:14 +01:00
2013-10-02 15:17:15 -04:00
def get_default_storage_format ( self , raw = False ) :
2013-04-17 17:39:25 -04:00
ret = self . conf . get ( " /new-vm/storage-format " )
2012-02-13 14:49:00 -05:00
if ret not in [ " default " , " raw " , " qcow2 " ] :
2020-08-27 16:37:15 -04:00
ret = " default " # pragma: no cover
2013-10-02 14:47:21 -04:00
if ret == " default " and not raw :
return self . default_storage_format_from_config
2012-02-13 14:49:00 -05:00
return ret
def set_storage_format ( self , typ ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /new-vm/storage-format " , typ . lower ( ) )
2012-02-13 14:49:00 -05:00
2018-10-04 14:19:32 -04:00
def get_default_cpu_setting ( self ) :
2014-01-17 15:32:40 -05:00
ret = self . conf . get ( " /new-vm/cpu-default " )
2014-02-05 13:51:53 -05:00
2018-10-04 14:19:32 -04:00
if ret not in DomainCpu . SPECIAL_MODES :
2020-08-27 16:37:15 -04:00
ret = DomainCpu . SPECIAL_MODE_APP_DEFAULT # pragma: no cover
2014-01-17 15:32:40 -05:00
return ret
def set_default_cpu_setting ( self , val ) :
self . conf . set ( " /new-vm/cpu-default " , val . lower ( ) )
2022-01-31 14:10:03 -05:00
def get_default_firmware_setting ( self ) :
2022-01-25 19:48:19 -05:00
ret = self . conf . get ( " /new-vm/firmware " )
2022-01-31 14:10:03 -05:00
if ret not in [ " default " , " uefi " ] :
2022-01-25 19:48:19 -05:00
ret = " default " # pragma: no cover
return ret
def set_firmware_setting ( self , val ) :
self . conf . set ( " /new-vm/firmware " , val . lower ( ) )
2006-10-11 09:07:45 -04:00
2009-11-18 15:16:57 -05:00
# URL/Media path history
2014-09-28 13:37:16 +02:00
def _url_add_helper ( self , gsettings_path , url ) :
2013-04-23 12:42:22 -04:00
maxlength = 10
2020-08-27 16:37:15 -04:00
urls = self . conf . get ( gsettings_path ) or [ ]
2009-05-11 11: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 14:06:43 -05:00
urls . insert ( 0 , url )
2013-04-23 12:42:22 -04:00
if len ( urls ) > maxlength :
2020-08-27 16:37:15 -04:00
del urls [ len ( urls ) - 1 ] # pragma: no cover
2014-09-28 13:37:16 +02:00
self . conf . set ( gsettings_path , urls )
2009-05-11 11:00:03 -04:00
2017-07-05 17:51:21 +01:00
def add_container_url ( self , url ) :
self . _url_add_helper ( " /urls/containers " , url )
2018-10-06 14:26:31 -04:00
def get_container_urls ( self ) :
return self . conf . get ( " /urls/containers " ) or [ ]
2009-05-11 11:00:03 -04:00
def add_media_url ( self , url ) :
2013-04-23 12:27:49 -04:00
self . _url_add_helper ( " /urls/urls " , url )
2018-10-06 14:26:31 -04:00
def get_media_urls ( self ) :
return self . conf . get ( " /urls/urls " ) or [ ]
2009-05-11 11:00:03 -04:00
def add_iso_path ( self , path ) :
2013-04-17 17:39:25 -04:00
self . _url_add_helper ( " /urls/isos " , path )
2009-11-18 15:16:57 -05:00
def get_iso_paths ( self ) :
2018-10-06 14:26:31 -04:00
return self . conf . get ( " /urls/isos " ) or [ ]
def on_iso_paths_changed ( self , cb ) :
return self . conf . notify_add ( " /urls/isos " , cb )
2009-11-18 15:16:57 -05:00
2009-12-01 12:23:19 -05: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 :
2020-08-27 16:37:15 -04:00
continue # pragma: no cover
2009-12-01 12:23:19 -05:00
current_list . append ( path )
2013-05-09 20:07:29 -04:00
self . conf . set ( " /paths/perms-fix-ignore " , current_list )
2009-12-01 12:23:19 -05:00
def get_perms_fix_ignore ( self ) :
2013-05-09 20:07:29 -04:00
return self . conf . get ( " /paths/perms-fix-ignore " )
2009-12-01 12:23:19 -05:00
2009-11-18 15:16:57 -05:00
# Manager view connection list
2018-03-14 13:13:22 -04:00
def get_conn_uris ( self ) :
return self . conf . get ( " /connections/uris " ) or [ ]
def add_conn_uri ( self , uri ) :
uris = self . get_conn_uris ( )
if uri not in uris :
2009-11-18 15:16:57 -05:00
uris . insert ( len ( uris ) - 1 , uri )
2013-04-17 17:39:25 -04:00
self . conf . set ( " /connections/uris " , uris )
2018-03-14 13:13:22 -04:00
def remove_conn_uri ( self , uri ) :
uris = self . get_conn_uris ( )
if uri in uris :
2007-08-28 17:57:25 -04:00
uris . remove ( uri )
2013-04-17 17:39:25 -04:00
self . conf . set ( " /connections/uris " , uris )
2009-11-18 15:16:57 -05:00
2008-03-24 11:39:19 -04:00
if self . get_conn_autoconnect ( uri ) :
2013-04-17 17:39:25 -04:00
uris = self . conf . get ( " /connections/autoconnect " )
2008-03-24 11:39:19 -04:00
uris . remove ( uri )
2013-04-17 17:39:25 -04:00
self . conf . set ( " /connections/autoconnect " , uris )
2008-03-24 11:39:19 -04:00
2009-11-28 21:00:46 -05:00
# Manager default window size
def get_manager_window_size ( self ) :
2013-04-17 17:39:25 -04:00
w = self . conf . get ( " /manager-window-width " )
h = self . conf . get ( " /manager-window-height " )
2009-11-28 21:00:46 -05:00
return ( w , h )
def set_manager_window_size ( self , w , h ) :
2013-04-17 17:39:25 -04:00
self . conf . set ( " /manager-window-width " , w )
self . conf . set ( " /manager-window-height " , h )
2009-11-18 15:16:57 -05:00
# URI autoconnect
2008-03-24 11:39:19 -04:00
def get_conn_autoconnect ( self , uri ) :
2013-04-17 17:39:25 -04:00
uris = self . conf . get ( " /connections/autoconnect " )
2008-03-24 11:39:19 -04:00
return ( ( uris is not None ) and ( uri in uris ) )
2009-11-25 14:16:31 -05:00
def set_conn_autoconnect ( self , uri , val ) :
2020-08-27 16:37:15 -04:00
uris = self . conf . get ( " /connections/autoconnect " ) or [ ]
2009-11-25 14:16:31 -05:00
if not val and uri in uris :
2008-03-24 11:39:19 -04:00
uris . remove ( uri )
2009-11-25 14:16:31 -05:00
elif val and uri not in uris :
2008-03-24 11:39:19 -04:00
uris . append ( uri )
2009-11-25 14:16:31 -05:00
2013-04-17 17:39:25 -04:00
self . conf . set ( " /connections/autoconnect " , uris )
2007-08-28 17:57:25 -04:00
2009-05-11 11:00:03 -04:00
2009-11-18 15:16:57 -05:00
# Default directory location dealings
def get_default_directory ( self , conn , _type ) :
2015-05-02 19:33:16 -04:00
ignore = conn
2020-08-27 16:37:15 -04:00
browsedata = self . browse_reason_data . get ( _type , { } )
key = browsedata . get ( " gsettings_key " , None )
2013-04-23 14:16:54 -04:00
path = None
if key :
path = self . conf . get ( " /paths/ %s -default " % key )
2009-11-18 15:16:57 -05:00
2019-06-16 21:12:39 -04:00
log . debug ( " directory for type= %s returning= %s " , _type , path )
2009-11-18 15:16:57 -05:00
return path
def set_default_directory ( self , folder , _type ) :
2020-08-27 16:37:15 -04:00
browsedata = self . browse_reason_data . get ( _type , { } )
key = browsedata . get ( " gsettings_key " , None )
2013-04-23 14:16:54 -04:00
if not key :
2020-08-27 16:37:15 -04:00
return # pragma: no cover
2009-11-18 15:16:57 -05:00
2019-06-16 21:12:39 -04:00
log . debug ( " saving directory for type= %s to %s " , key , folder )
2013-04-23 14:16:54 -04:00
self . conf . set ( " /paths/ %s -default " % key , folder )