2007-04-12 15:36:04 -04:00
#
# Copyright (C) 2006-2007 Red Hat, Inc.
# Copyright (C) 2006 Hugh O. Brock <hbrock@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 11:12:20 -05:00
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
2007-04-12 15:36:04 -04:00
#
2009-07-14 09:25:39 -04:00
import logging
import traceback
2013-04-11 17:16:33 -04:00
# pylint: disable=E0611
2012-05-14 14:24:56 +01:00
from gi . repository import Gtk
from gi . repository import Gdk
2013-04-11 17:16:33 -04:00
# pylint: enable=E0611
2009-07-14 09:25:39 -04:00
2007-04-12 15:36:04 -04:00
import virtinst
2013-04-10 19:48:07 -04:00
from virtinst import ( VirtualCharDevice ,
2011-06-23 17:42:03 +02:00
VirtualVideoDevice , VirtualWatchdog ,
2011-09-02 03:23:28 +02:00
VirtualFilesystem , VirtualSmartCardDevice ,
VirtualRedirDevice )
2012-12-07 18:21:38 +08:00
from virtinst . VirtualController import VirtualControllerSCSI
2007-04-12 15:36:04 -04:00
2009-12-14 16:45:55 -05:00
import virtManager . util as util
2009-11-24 13:14:55 -05:00
import virtManager . uihelpers as uihelpers
2007-04-12 15:36:04 -04:00
from virtManager . asyncjob import vmmAsyncJob
2009-03-09 16:19:39 -04:00
from virtManager . storagebrowse import vmmStorageBrowser
2010-12-08 17:26:19 -05:00
from virtManager . baseclass import vmmGObjectUI
2007-04-12 15:36:04 -04:00
2010-12-11 12:32:04 -05:00
PAGE_ERROR = 0
2007-04-12 15:36:04 -04:00
PAGE_DISK = 1
PAGE_NETWORK = 2
2007-09-25 20:05:45 -04:00
PAGE_INPUT = 3
2007-09-26 19:39:11 -04:00
PAGE_GRAPHICS = 4
2009-01-22 17:00:26 -05:00
PAGE_SOUND = 5
2009-03-09 16:20:23 -04:00
PAGE_HOSTDEV = 6
2009-07-14 09:25:39 -04:00
PAGE_CHAR = 7
2009-07-14 09:25:39 -04:00
PAGE_VIDEO = 8
2010-03-24 00:22:17 -04:00
PAGE_WATCHDOG = 9
2011-05-19 18:17:58 -04:00
PAGE_FILESYSTEM = 10
2011-06-23 17:42:03 +02:00
PAGE_SMARTCARD = 11
2011-09-02 03:23:28 +02:00
PAGE_USBREDIR = 12
2009-07-14 09:25:39 -04:00
char_widget_mappings = {
" source_path " : " char-path " ,
" source_mode " : " char-mode " ,
" source_host " : " char-host " ,
" source_port " : " char-port " ,
2010-12-10 11:47:07 -05:00
" bind_port " : " char-bind-port " ,
" bind_host " : " char-bind-host " ,
" protocol " : " char-use-telnet " ,
2011-04-05 01:35:31 +02:00
" target_name " : " char-target-name " ,
2009-07-14 09:25:39 -04:00
}
2007-04-12 15:36:04 -04:00
2012-02-02 11:32:29 -05:00
2010-12-08 17:26:19 -05:00
class vmmAddHardware ( vmmGObjectUI ) :
def __init__ ( self , vm ) :
2012-11-09 10:46:37 +01:00
vmmGObjectUI . __init__ ( self , " vmm-add-hardware.ui " , " vmm-add-hardware " )
2010-12-08 17:26:19 -05:00
2007-04-12 15:36:04 -04:00
self . vm = vm
2011-07-22 16:43:26 -04:00
self . conn = vm . conn
2008-11-18 17:01:22 -05:00
2009-03-09 16:19:39 -04:00
self . storage_browser = None
2010-03-04 15:35:34 -05:00
# Host space polling
self . host_storage_timer = None
2009-07-14 09:25:39 -04:00
self . _dev = None
2013-02-16 13:31:46 -05:00
self . builder . connect_signals ( {
2007-04-12 15:36:04 -04:00
" on_create_cancel_clicked " : self . close ,
" on_vmm_create_delete_event " : self . close ,
" on_create_finish_clicked " : self . finish ,
2009-11-24 13:14:55 -05:00
2010-03-04 15:35:34 -05:00
" on_config_storage_browse_clicked " : self . browse_storage ,
" on_config_storage_select_toggled " : self . toggle_storage_select ,
2009-11-24 13:14:55 -05:00
2007-05-24 15:51:32 -04:00
" on_mac_address_clicked " : self . change_macaddr_use ,
2009-11-24 13:14:55 -05:00
2007-09-26 19:39:11 -04:00
" on_graphics_type_changed " : self . change_graphics_type ,
" on_graphics_port_auto_toggled " : self . change_port_auto ,
2008-03-17 13:09:45 -04:00
" on_graphics_keymap_toggled " : self . change_keymap ,
2009-11-24 13:14:55 -05:00
2009-07-14 09:25:39 -04:00
" on_char_device_type_changed " : self . change_char_device_type ,
2011-05-19 18:17:58 -04:00
" on_fs_type_combo_changed " : self . change_fs_type ,
2012-01-12 20:28:26 -05:00
" on_fs_driver_combo_changed " : self . change_fs_driver ,
2011-06-08 18:38:03 -04:00
" on_fs_source_browse_clicked " : self . browse_fs_source ,
2011-05-19 18:17:58 -04:00
2011-09-02 03:23:28 +02:00
" on_usbredir_type_changed " : self . change_usbredir_type ,
2009-07-14 09:25:39 -04:00
# Char dev info signals
2013-01-12 16:13:53 -05:00
" char_device_type_focus " : self . update_doc_char_type ,
" char_path_focus_in " : self . update_doc_char_source_path ,
" char_mode_changed " : self . update_doc_char_source_mode ,
" char_mode_focus " : self . update_doc_char_source_mode ,
" char_host_focus_in " : self . update_doc_char_source_host ,
" char_bind_host_focus_in " : self . update_doc_char_bind_host ,
" char_telnet_focus_in " : self . update_doc_char_protocol ,
" char_name_focus_in " : self . update_doc_char_target_name ,
2012-11-08 14:15:02 +01:00
} )
2011-04-18 11:25:28 -04:00
self . bind_escape_key_close ( )
2007-04-12 15:36:04 -04:00
2012-05-14 14:24:56 +01:00
finish_img = Gtk . Image . new_from_stock ( Gtk . STOCK_QUIT ,
Gtk . IconSize . BUTTON )
2011-07-14 13:13:13 -04:00
self . widget ( " create-finish " ) . set_image ( finish_img )
2009-11-17 15:06:15 -05:00
2007-04-12 15:36:04 -04:00
self . set_initial_state ( )
2011-07-14 13:13:13 -04:00
hwlist = self . widget ( " hardware-list " )
2010-12-11 12:32:04 -05:00
hwlist . get_selection ( ) . connect ( " changed " , self . hw_selected )
2013-01-12 16:13:53 -05:00
def _update_doc ( self , param ) :
2009-07-14 09:25:39 -04:00
doc = self . _build_doc_str ( param )
2011-07-14 13:13:13 -04:00
self . widget ( " char-info " ) . set_markup ( doc )
2009-07-14 09:25:39 -04:00
2013-01-12 16:13:53 -05:00
def update_doc_char_type ( self , * ignore ) :
return self . _update_doc ( " char_type " )
def update_doc_char_source_path ( self , * ignore ) :
return self . _update_doc ( " source_path " )
def update_doc_char_source_mode ( self , * ignore ) :
return self . _update_doc ( " source_mode " )
def update_doc_char_source_host ( self , * ignore ) :
return self . _update_doc ( " source_host " )
def update_doc_char_bind_host ( self , * ignore ) :
return self . _update_doc ( " bind_host " )
def update_doc_char_protocol ( self , * ignore ) :
return self . _update_doc ( " protocol " )
def update_doc_char_target_name ( self , * ignore ) :
return self . _update_doc ( " target_name " )
2009-07-14 09:25:39 -04:00
def _build_doc_str ( self , param , docstr = None ) :
doc = " "
doctmpl = " <i> %s </i> "
if docstr :
doc = doctmpl % ( docstr )
elif self . _dev :
devclass = self . _dev . __class__
2010-09-02 18:37:20 -04:00
paramdoc = getattr ( devclass , param ) . __doc__
if paramdoc :
doc = doctmpl % paramdoc
2009-07-14 09:25:39 -04:00
return doc
2011-04-14 08:47:42 -04:00
def show ( self , parent ) :
2012-01-31 18:16:54 -05:00
logging . debug ( " Showing addhw " )
2007-04-12 15:36:04 -04:00
self . reset_state ( )
2011-04-14 08:47:42 -04:00
self . topwin . set_transient_for ( parent )
2007-04-12 15:36:04 -04:00
self . topwin . present ( )
2010-11-29 14:06:43 -05:00
def close ( self , ignore1 = None , ignore2 = None ) :
2012-01-31 18:16:54 -05:00
logging . debug ( " Closing addhw " )
2009-11-24 12:43:54 -05:00
self . topwin . hide ( )
2010-03-04 15:35:34 -05:00
self . remove_timers ( )
2011-04-11 18:35:21 -04:00
if self . storage_browser :
self . storage_browser . close ( )
2009-11-24 12:43:54 -05:00
return 1
2011-07-23 21:16:54 -04:00
def _cleanup ( self ) :
self . vm = None
self . conn = None
self . _dev = None
2011-04-11 18:35:21 -04:00
2011-07-23 21:16:54 -04:00
if self . storage_browser :
self . storage_browser . cleanup ( )
self . storage_browser = None
2011-04-11 18:35:21 -04:00
2010-03-04 15:35:34 -05:00
def remove_timers ( self ) :
try :
if self . host_storage_timer :
2012-11-08 14:15:02 +01:00
self . remove_gobject_timeout ( self . host_storage_timer )
2010-03-04 15:35:34 -05:00
self . host_storage_timer = None
except :
pass
2009-11-24 12:43:54 -05:00
def is_visible ( self ) :
2012-05-14 14:24:56 +01:00
return self . topwin . get_visible ( )
2009-11-24 12:43:54 -05:00
##########################
# Initialization methods #
##########################
2007-04-12 15:36:04 -04:00
def set_initial_state ( self ) :
2011-07-14 13:13:13 -04:00
notebook = self . widget ( " create-pages " )
2007-04-12 15:36:04 -04:00
notebook . set_show_tabs ( False )
2012-05-14 14:24:56 +01:00
black = Gdk . Color . parse ( " #000 " ) [ 1 ]
self . widget ( " page-title-box " ) . modify_bg ( Gtk . StateType . NORMAL , black )
2007-04-12 15:36:04 -04:00
2010-12-11 15:55:31 -05:00
# Name, icon name, page number, is sensitive, tooltip, icon size,
# device type (serial/parallel)...
2012-05-14 14:24:56 +01:00
model = Gtk . ListStore ( str , str , int , bool , str , str )
2011-07-14 13:13:13 -04:00
hw_list = self . widget ( " hardware-list " )
2009-07-08 18:49:25 -04:00
hw_list . set_model ( model )
2010-12-11 12:32:04 -05:00
2012-05-14 14:24:56 +01:00
hw_col = Gtk . TreeViewColumn ( " Hardware " )
2010-12-11 12:32:04 -05:00
hw_col . set_spacing ( 6 )
hw_col . set_min_width ( 165 )
2012-05-14 14:24:56 +01:00
icon = Gtk . CellRendererPixbuf ( )
icon . set_property ( " stock-size " , Gtk . IconSize . BUTTON )
text = Gtk . CellRendererText ( )
2009-07-20 15:09:32 -04:00
text . set_property ( " xpad " , 6 )
2010-12-11 12:32:04 -05:00
hw_col . pack_start ( icon , False )
hw_col . pack_start ( text , True )
hw_col . add_attribute ( icon , ' icon-name ' , 1 )
hw_col . add_attribute ( text , ' text ' , 0 )
hw_col . add_attribute ( text , ' sensitive ' , 3 )
hw_list . append_column ( hw_col )
2009-07-08 18:49:25 -04:00
# Virtual network list
2011-07-14 13:13:13 -04:00
net_list = self . widget ( " net-list " )
bridge_box = self . widget ( " net-bridge-box " )
2010-03-20 18:35:47 -04:00
uihelpers . init_network_list ( net_list , bridge_box )
2007-04-12 15:36:04 -04:00
2009-07-08 18:49:25 -04:00
# Network model list
2011-07-14 13:13:13 -04:00
netmodel_list = self . widget ( " net-model " )
2010-03-23 22:15:53 -04:00
uihelpers . build_netmodel_combo ( self . vm , netmodel_list )
2009-01-22 17:00:10 -05:00
2009-07-08 18:49:25 -04:00
# Disk device type / bus
2011-07-14 13:13:13 -04:00
target_list = self . widget ( " config-storage-devtype " )
2012-05-14 14:24:56 +01:00
target_model = Gtk . ListStore ( str , str , str , str , int )
2007-07-14 13:48:24 -04:00
target_list . set_model ( target_model )
2012-05-14 14:24:56 +01:00
icon = Gtk . CellRendererPixbuf ( )
icon . set_property ( " stock-size " , Gtk . IconSize . BUTTON )
2007-07-14 13:48:24 -04:00
target_list . pack_start ( icon , False )
2009-07-20 15:09:32 -04:00
target_list . add_attribute ( icon , ' icon-name ' , 2 )
2012-05-14 14:24:56 +01:00
text = Gtk . CellRendererText ( )
2009-07-20 15:09:32 -04:00
text . set_property ( " xpad " , 6 )
2007-07-14 13:48:24 -04:00
target_list . pack_start ( text , True )
2008-08-21 15:58:35 -04:00
target_list . add_attribute ( text , ' text ' , 3 )
2007-07-14 13:48:24 -04:00
2010-05-20 08:34:32 -04:00
# Disk cache mode
2011-07-14 13:13:13 -04:00
cache_list = self . widget ( " config-storage-cache " )
2010-05-20 08:34:32 -04:00
uihelpers . build_cache_combo ( self . vm , cache_list )
2010-12-10 19:20:14 -05:00
# Disk format mode
2011-07-14 13:13:13 -04:00
format_list = self . widget ( " config-storage-format " )
2010-12-10 19:20:14 -05:00
uihelpers . build_storage_format_combo ( self . vm , format_list )
2010-03-04 15:35:34 -05:00
# Sparse tooltip
2011-07-14 13:13:13 -04:00
sparse_info = self . widget ( " config-storage-nosparse-info " )
2010-03-04 15:35:34 -05:00
uihelpers . set_sparse_tooltip ( sparse_info )
2009-07-08 18:49:25 -04:00
# Input device type
2011-07-14 13:13:13 -04:00
input_list = self . widget ( " input-type " )
2012-05-14 14:24:56 +01:00
input_model = Gtk . ListStore ( str , str , str )
2007-09-25 20:05:45 -04:00
input_list . set_model ( input_model )
2012-05-14 14:24:56 +01:00
text = Gtk . CellRendererText ( )
2007-09-25 20:05:45 -04:00
input_list . pack_start ( text , True )
input_list . add_attribute ( text , ' text ' , 0 )
2009-07-08 18:49:25 -04:00
# Graphics type
2011-07-14 13:13:13 -04:00
graphics_list = self . widget ( " graphics-type " )
2012-05-14 14:24:56 +01:00
graphics_model = Gtk . ListStore ( str , str )
2007-09-26 19:39:11 -04:00
graphics_list . set_model ( graphics_model )
2012-05-14 14:24:56 +01:00
text = Gtk . CellRendererText ( )
2007-09-26 19:39:11 -04:00
graphics_list . pack_start ( text , True )
graphics_list . add_attribute ( text , ' text ' , 0 )
2009-07-08 18:49:25 -04:00
# Sound model list
2011-07-14 13:13:13 -04:00
sound_list = self . widget ( " sound-model " )
2010-03-23 22:15:53 -04:00
uihelpers . build_sound_combo ( self . vm , sound_list )
2009-01-22 17:00:26 -05:00
2010-12-11 16:09:30 -05:00
# Host device list
2010-12-11 15:12:22 -05:00
# model = [ Description, nodedev name ]
2011-07-14 13:13:13 -04:00
host_dev = self . widget ( " host-device " )
2012-05-14 14:24:56 +01:00
host_dev_model = Gtk . ListStore ( str , str )
2009-03-09 16:20:23 -04:00
host_dev . set_model ( host_dev_model )
2010-12-11 15:12:22 -05:00
2012-05-14 14:24:56 +01:00
host_col = Gtk . TreeViewColumn ( )
text = Gtk . CellRendererText ( )
2010-12-11 15:12:22 -05:00
host_col . pack_start ( text , True )
host_col . add_attribute ( text , ' text ' , 0 )
2012-05-14 14:24:56 +01:00
host_dev_model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
2010-12-11 15:12:22 -05:00
host_dev . append_column ( host_col )
2009-03-09 16:20:23 -04:00
2009-07-14 09:25:39 -04:00
# Video device
2011-07-14 13:13:13 -04:00
video_dev = self . widget ( " video-model " )
2010-03-23 22:15:53 -04:00
uihelpers . build_video_combo ( self . vm , video_dev )
2009-07-08 18:49:25 -04:00
2010-12-11 16:09:30 -05:00
# Character dev mode
2011-07-14 13:13:13 -04:00
char_mode = self . widget ( " char-mode " )
2009-07-14 09:25:39 -04:00
# Mode name, desc
2012-05-14 14:24:56 +01:00
char_mode_model = Gtk . ListStore ( str , str )
2009-07-14 09:25:39 -04:00
char_mode . set_model ( char_mode_model )
2012-05-14 14:24:56 +01:00
text = Gtk . CellRendererText ( )
2009-07-14 09:25:39 -04:00
char_mode . pack_start ( text , True )
char_mode . add_attribute ( text , ' text ' , 1 )
2012-05-14 14:24:56 +01:00
char_mode_model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
2009-07-14 09:25:39 -04:00
for t in VirtualCharDevice . char_modes :
desc = VirtualCharDevice . get_char_mode_desc ( t )
char_mode_model . append ( [ t , desc + " ( %s ) " % t ] )
2012-05-14 14:24:56 +01:00
self . widget ( " char-info-box " ) . modify_bg ( Gtk . StateType . NORMAL ,
Gdk . Color . parse ( " grey " ) [ 1 ] )
2009-07-14 09:25:39 -04:00
2010-03-24 00:22:17 -04:00
# Watchdog widgets
2011-07-14 13:13:13 -04:00
combo = self . widget ( " watchdog-model " )
2010-03-24 00:22:17 -04:00
uihelpers . build_watchdogmodel_combo ( self . vm , combo )
2011-07-14 13:13:13 -04:00
combo = self . widget ( " watchdog-action " )
2010-03-24 00:22:17 -04:00
uihelpers . build_watchdogaction_combo ( self . vm , combo )
2011-05-19 18:17:58 -04:00
def simple_store_set ( comboname , values ) :
2011-07-14 13:13:13 -04:00
combo = self . widget ( comboname )
2012-05-14 14:24:56 +01:00
model = Gtk . ListStore ( str , str )
2011-05-19 18:17:58 -04:00
combo . set_model ( model )
2012-05-14 14:24:56 +01:00
text = Gtk . CellRendererText ( )
2011-05-19 18:17:58 -04:00
combo . pack_start ( text , True )
combo . add_attribute ( text , ' text ' , 1 )
2012-05-14 14:24:56 +01:00
model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
2011-05-19 18:17:58 -04:00
for val in values :
model . append ( [ val , val . capitalize ( ) ] )
# Filesystem widgets
simple_store_set ( " fs-type-combo " ,
[ VirtualFilesystem . TYPE_MOUNT ,
VirtualFilesystem . TYPE_TEMPLATE ] )
simple_store_set ( " fs-mode-combo " , VirtualFilesystem . MOUNT_MODES )
2012-01-12 20:28:26 -05:00
simple_store_set ( " fs-driver-combo " , VirtualFilesystem . DRIVER_TYPES )
2012-01-19 00:22:02 +05:30
simple_store_set ( " fs-wrpolicy-combo " , VirtualFilesystem . WRPOLICIES )
2011-05-19 18:17:58 -04:00
self . show_pair_combo ( " fs-type " , self . conn . is_openvz ( ) )
2011-12-22 23:40:17 +05:30
self . show_check_button ( " fs-readonly " , self . conn . is_qemu ( ) )
2011-05-19 18:17:58 -04:00
2011-06-23 17:42:03 +02:00
# Smartcard widgets
2011-07-14 13:13:13 -04:00
combo = self . widget ( " smartcard-mode " )
2011-06-23 17:42:03 +02:00
uihelpers . build_smartcard_mode_combo ( self . vm , combo )
2011-09-02 03:23:28 +02:00
# Usbredir widgets
combo = self . widget ( " usbredir-list " )
uihelpers . build_redir_type_combo ( self . vm , combo )
2010-12-11 15:55:31 -05:00
# Available HW options
2010-03-04 15:35:34 -05:00
is_local = not self . conn . is_remote ( )
is_storage_capable = self . conn . is_storage_capable ( )
2010-12-11 15:55:31 -05:00
have_storage = ( is_local or is_storage_capable )
storage_tooltip = None
if not have_storage :
storage_tooltip = _ ( " Connection does not support storage "
" management. " )
2011-07-14 13:13:13 -04:00
hwlist = self . widget ( " hardware-list " )
2010-12-11 15:55:31 -05:00
model = hwlist . get_model ( )
model . clear ( )
def add_hw_option ( name , icon , page , sensitive , errortxt , devtype = None ) :
model . append ( [ name , icon , page , sensitive , errortxt , devtype ] )
add_hw_option ( " Storage " , " drive-harddisk " , PAGE_DISK , have_storage ,
have_storage and storage_tooltip or None )
add_hw_option ( " Network " , " network-idle " , PAGE_NETWORK , True , None )
add_hw_option ( " Input " , " input-mouse " , PAGE_INPUT , self . vm . is_hvm ( ) ,
_ ( " Not supported for this guest type. " ) )
add_hw_option ( " Graphics " , " video-display " , PAGE_GRAPHICS ,
True , None )
add_hw_option ( " Sound " , " audio-card " , PAGE_SOUND ,
self . vm . is_hvm ( ) ,
_ ( " Not supported for this guest type. " ) )
2012-05-14 14:24:56 +01:00
add_hw_option ( " Serial " , Gtk . STOCK_CONNECT , PAGE_CHAR ,
2010-12-11 15:55:31 -05:00
self . vm . is_hvm ( ) ,
_ ( " Not supported for this guest type. " ) ,
" serial " )
2012-05-14 14:24:56 +01:00
add_hw_option ( " Parallel " , Gtk . STOCK_CONNECT , PAGE_CHAR ,
2010-12-11 15:55:31 -05:00
self . vm . is_hvm ( ) ,
_ ( " Not supported for this guest type. " ) ,
" parallel " )
2012-05-14 14:24:56 +01:00
add_hw_option ( " Channel " , Gtk . STOCK_CONNECT , PAGE_CHAR ,
2011-04-05 01:35:32 +02:00
self . vm . is_hvm ( ) ,
_ ( " Not supported for this guest type. " ) ,
" channel " )
2010-12-11 15:55:31 -05:00
add_hw_option ( " USB Host Device " , " system-run " , PAGE_HOSTDEV ,
2011-04-11 18:35:21 -04:00
self . conn . is_nodedev_capable ( ) ,
2010-12-11 15:55:31 -05:00
_ ( " Connection does not support host device enumeration " ) ,
" usb " )
add_hw_option ( " PCI Host Device " , " system-run " , PAGE_HOSTDEV ,
2011-04-11 18:35:21 -04:00
self . conn . is_nodedev_capable ( ) ,
2010-12-11 15:55:31 -05:00
_ ( " Connection does not support host device enumeration " ) ,
" pci " )
add_hw_option ( " Video " , " video-display " , PAGE_VIDEO ,
virtinst . support . check_conn_support (
2011-04-11 18:35:21 -04:00
self . conn . vmm ,
2010-12-11 15:55:31 -05:00
virtinst . support . SUPPORT_CONN_DOMAIN_VIDEO ) ,
_ ( " Libvirt version does not support video devices. " ) )
add_hw_option ( " Watchdog " , " device_pci " , PAGE_WATCHDOG ,
self . vm . is_hvm ( ) ,
_ ( " Not supported for this guest type. " ) )
2012-05-14 14:24:56 +01:00
add_hw_option ( " Filesystem " , Gtk . STOCK_DIRECTORY , PAGE_FILESYSTEM ,
2011-05-19 18:17:58 -04:00
virtinst . support . check_conn_hv_support (
self . conn . vmm ,
virtinst . support . SUPPORT_CONN_HV_FILESYSTEM ,
self . vm . get_hv_type ( ) ) ,
_ ( " Not supported for this hypervisor/libvirt "
" combination. " ) )
2011-06-23 17:42:03 +02:00
add_hw_option ( " Smartcard " , " device_serial " , PAGE_SMARTCARD ,
True , None )
2011-09-02 03:23:28 +02:00
add_hw_option ( " USB Redirection " , " device_usb " , PAGE_USBREDIR ,
True , None )
2010-12-11 15:55:31 -05:00
def reset_state ( self ) :
2009-07-08 18:49:25 -04:00
# Storage init
2011-07-14 13:13:13 -04:00
label_widget = self . widget ( " phys-hd-label " )
2010-12-13 16:12:55 -05:00
label_widget . set_markup ( " " )
2010-03-04 15:35:34 -05:00
if not self . host_storage_timer :
2012-02-10 14:07:51 -05:00
self . host_storage_timer = self . timeout_add ( 3 * 1000 ,
2010-03-04 15:35:34 -05:00
uihelpers . host_space_tick ,
2010-12-09 14:06:00 -05:00
self . conn ,
2010-03-04 15:35:34 -05:00
label_widget )
2011-07-14 13:13:13 -04:00
self . widget ( " config-storage-create " ) . set_active ( True )
self . widget ( " config-storage-size " ) . set_value ( 8 )
self . widget ( " config-storage-entry " ) . set_text ( " " )
self . widget ( " config-storage-nosparse " ) . set_active ( True )
2010-12-10 19:20:14 -05:00
# Don't specify by default, so we don't overwrite possibly working
# libvirt detection
2012-05-14 14:24:56 +01:00
self . widget ( " config-storage-format " ) . get_child ( ) . set_text ( " " )
2011-07-14 13:13:13 -04:00
target_list = self . widget ( " config-storage-devtype " )
2009-07-08 18:49:25 -04:00
self . populate_target_device_model ( target_list . get_model ( ) )
if len ( target_list . get_model ( ) ) > 0 :
target_list . set_active ( 0 )
2007-04-12 15:36:04 -04:00
2009-07-08 18:49:25 -04:00
# Network init
2011-04-11 18:35:21 -04:00
newmac = uihelpers . generate_macaddr ( self . conn )
2011-07-14 13:13:13 -04:00
self . widget ( " mac-address " ) . set_active ( bool ( newmac ) )
self . widget ( " create-mac-address " ) . set_text ( newmac )
2009-07-08 18:49:25 -04:00
self . change_macaddr_use ( )
2009-11-24 13:14:55 -05:00
2011-07-14 13:13:13 -04:00
net_list = self . widget ( " net-list " )
net_warn = self . widget ( " net-list-warn " )
2011-04-11 18:35:21 -04:00
uihelpers . populate_network_list ( net_list , self . conn )
2007-04-12 15:36:04 -04:00
2011-04-11 18:35:21 -04:00
error = self . conn . netdev_error
2009-11-30 12:51:25 -05:00
if error :
net_warn . show ( )
2012-05-14 14:24:56 +01:00
net_warn . set_tooltip_text ( error )
2009-11-30 12:51:25 -05:00
else :
net_warn . hide ( )
2011-07-14 13:13:13 -04:00
netmodel = self . widget ( " net-model " )
2010-03-23 22:15:53 -04:00
uihelpers . populate_netmodel_combo ( self . vm , netmodel )
netmodel . set_active ( 0 )
2009-01-22 17:00:10 -05:00
2009-07-08 18:49:25 -04:00
# Input device init
2011-07-14 13:13:13 -04:00
input_box = self . widget ( " input-type " )
2007-09-25 20:05:45 -04:00
self . populate_input_model ( input_box . get_model ( ) )
input_box . set_active ( 0 )
2009-07-08 18:49:25 -04:00
# Graphics init
self . change_port_auto ( )
2011-07-14 13:13:13 -04:00
graphics_box = self . widget ( " graphics-type " )
2007-09-26 19:39:11 -04:00
self . populate_graphics_model ( graphics_box . get_model ( ) )
graphics_box . set_active ( 0 )
2011-07-14 13:13:13 -04:00
self . widget ( " graphics-address " ) . set_active ( False )
self . widget ( " graphics-port-auto " ) . set_active ( True )
self . widget ( " graphics-password " ) . set_text ( " " )
self . widget ( " graphics-keymap " ) . set_text ( " " )
self . widget ( " graphics-keymap-chk " ) . set_active ( True )
2007-09-26 19:39:11 -04:00
2009-07-08 18:49:25 -04:00
# Sound init
2011-07-14 13:13:13 -04:00
sound_box = self . widget ( " sound-model " )
2009-01-22 17:00:26 -05:00
sound_box . set_active ( 0 )
2010-12-10 11:47:07 -05:00
2009-07-14 09:25:39 -04:00
# Char parameters
2011-07-14 13:13:13 -04:00
self . widget ( " char-device-type " ) . set_active ( 0 )
self . widget ( " char-path " ) . set_text ( " " )
self . widget ( " char-host " ) . set_text ( " 127.0.0.1 " )
self . widget ( " char-port " ) . get_adjustment ( ) . value = 4555
self . widget ( " char-bind-host " ) . set_text ( " 127.0.0.1 " )
self . widget ( " char-bind-port " ) . get_adjustment ( ) . value = 4556
self . widget ( " char-use-telnet " ) . set_active ( False )
self . widget ( " char-target-name " ) . set_text ( " com.redhat.spice.0 " )
2009-07-14 09:25:39 -04:00
2011-05-19 18:17:58 -04:00
# FS params
2011-07-14 13:13:13 -04:00
self . widget ( " fs-type-combo " ) . set_active ( 0 )
self . widget ( " fs-mode-combo " ) . set_active ( 0 )
2012-01-12 20:28:26 -05:00
self . widget ( " fs-driver-combo " ) . set_active ( 0 )
2012-01-19 00:22:02 +05:30
self . widget ( " fs-wrpolicy-combo " ) . set_active ( 0 )
2011-07-14 13:13:13 -04:00
self . widget ( " fs-source " ) . set_text ( " " )
self . widget ( " fs-target " ) . set_text ( " " )
2011-12-22 23:40:17 +05:30
self . widget ( " fs-readonly " ) . set_active ( False )
2011-05-19 18:17:58 -04:00
2012-02-08 18:20:59 -05:00
# Video params
uihelpers . populate_video_combo ( self . vm , self . widget ( " video-model " ) )
2010-12-11 14:51:08 -05:00
# Hide all notebook pages, so the wizard isn't as big as the largest
# page
2011-07-14 13:13:13 -04:00
notebook = self . widget ( " create-pages " )
2010-12-11 14:51:08 -05:00
for page in range ( notebook . get_n_pages ( ) ) :
widget = notebook . get_nth_page ( page )
widget . hide ( )
2010-12-11 12:32:04 -05:00
self . set_hw_selection ( 0 )
2009-01-22 17:00:26 -05:00
2009-11-24 12:43:54 -05:00
#########################
# UI population methods #
#########################
2009-07-14 09:25:39 -04:00
2009-11-24 12:43:54 -05:00
def populate_target_device_model ( self , model ) :
model . clear ( )
#[bus, device, icon, desc, iconsize]
def add_dev ( bus , device , desc ) :
if device == virtinst . VirtualDisk . DEVICE_FLOPPY :
icon = " media-floppy "
elif device == virtinst . VirtualDisk . DEVICE_CDROM :
icon = " media-optical "
2008-02-14 17:33:52 -05:00
else :
2009-11-24 12:43:54 -05:00
icon = " drive-harddisk "
2012-05-14 14:24:56 +01:00
model . append ( [ bus , device , icon , desc , Gtk . IconSize . BUTTON ] )
2009-11-24 12:43:54 -05:00
if self . vm . is_hvm ( ) :
2012-11-27 10:42:35 -05:00
add_dev ( " ide " , virtinst . VirtualDisk . DEVICE_DISK , _ ( " IDE disk " ) )
add_dev ( " ide " , virtinst . VirtualDisk . DEVICE_CDROM , _ ( " IDE CDROM " ) )
add_dev ( " fdc " , virtinst . VirtualDisk . DEVICE_FLOPPY ,
_ ( " Floppy disk " ) )
2010-12-13 14:31:27 -05:00
2011-07-22 13:13:26 -04:00
if self . vm . rhel6_defaults ( ) :
2012-11-27 10:42:35 -05:00
add_dev ( " scsi " , virtinst . VirtualDisk . DEVICE_DISK ,
_ ( " SCSI disk " ) )
add_dev ( " usb " , virtinst . VirtualDisk . DEVICE_DISK ,
_ ( " USB disk " ) )
if self . vm . get_hv_type ( ) in [ " kvm " , " test " ] :
add_dev ( " sata " , virtinst . VirtualDisk . DEVICE_DISK ,
_ ( " SATA disk " ) )
add_dev ( " virtio " , virtinst . VirtualDisk . DEVICE_DISK ,
_ ( " Virtio disk " ) )
2012-12-11 17:06:38 +08:00
add_dev ( " virtio " , virtinst . VirtualDisk . DEVICE_LUN ,
_ ( " Virtio lun " ) )
2012-12-07 18:21:38 +08:00
add_dev ( " virtio-scsi " , virtinst . VirtualDisk . DEVICE_DISK ,
_ ( " Virtio SCSI disk " ) )
2012-12-11 17:06:38 +08:00
add_dev ( " virtio-scsi " , virtinst . VirtualDisk . DEVICE_LUN ,
_ ( " Virtio SCSI lun " ) )
2012-11-27 10:42:35 -05:00
if self . conn . is_xen ( ) or self . conn . is_test_conn ( ) :
add_dev ( " xen " , virtinst . VirtualDisk . DEVICE_DISK ,
_ ( " Xen virtual disk " ) )
2009-11-24 12:43:54 -05:00
def populate_input_model ( self , model ) :
model . clear ( )
2012-11-27 10:44:13 -05:00
model . append ( [ _ ( " EvTouch USB Graphics Tablet " ) , " tablet " , " usb " ] )
model . append ( [ _ ( " Generic USB Mouse " ) , " mouse " , " usb " ] )
2009-11-24 12:43:54 -05:00
def populate_graphics_model ( self , model ) :
model . clear ( )
model . append ( [ _ ( " VNC server " ) , " vnc " ] )
2011-03-24 10:09:42 -04:00
model . append ( [ _ ( " Spice server " ) , " spice " ] )
2009-11-24 12:43:54 -05:00
model . append ( [ _ ( " Local SDL window " ) , " sdl " ] )
2010-12-11 15:55:31 -05:00
def populate_host_device_model ( self , devtype , devcap , subtype , subcap ) :
2011-07-14 13:13:13 -04:00
devlist = self . widget ( " host-device " )
2010-12-11 15:55:31 -05:00
model = devlist . get_model ( )
2009-11-24 12:43:54 -05:00
model . clear ( )
subdevs = [ ]
if subtype :
2011-04-11 18:35:21 -04:00
subdevs = self . conn . get_nodedevs ( subtype , subcap )
2009-11-24 12:43:54 -05:00
2011-04-11 18:35:21 -04:00
devs = self . conn . get_nodedevs ( devtype , devcap )
2009-11-24 12:43:54 -05:00
for dev in devs :
prettyname = dev . pretty_name ( )
for subdev in subdevs :
if dev . name == subdev . parent :
prettyname = dev . pretty_name ( subdev )
model . append ( [ prettyname , dev . name ] )
if len ( model ) == 0 :
model . append ( [ _ ( " No Devices Available " ) , None ] )
2011-06-08 18:16:12 -04:00
util . set_list_selection ( devlist , 0 )
2009-11-24 12:43:54 -05:00
########################
# get_config_* methods #
########################
2007-04-12 15:36:04 -04:00
def get_config_hardware_type ( self ) :
2010-12-11 12:32:04 -05:00
row = self . get_hw_selection ( )
if not row :
2007-04-12 15:36:04 -04:00
return None
2010-12-11 12:32:04 -05:00
return row [ 2 ]
2007-04-12 15:36:04 -04:00
2009-11-24 12:43:54 -05:00
# Disk getters
2010-03-04 15:35:34 -05:00
def is_default_storage ( self ) :
2011-07-14 13:13:13 -04:00
return self . widget ( " config-storage-create " ) . get_active ( )
2010-03-04 15:35:34 -05:00
def get_storage_info ( self ) :
path = None
2011-07-14 13:13:13 -04:00
size = self . widget ( " config-storage-size " ) . get_value ( )
sparse = not self . widget ( " config-storage-nosparse " ) . get_active ( )
2010-03-04 15:35:34 -05:00
if self . is_default_storage ( ) :
2013-04-11 16:32:00 -04:00
pathlist = [ d . path for d in self . vm . get_disk_devices ( ) ]
2010-12-09 14:06:00 -05:00
path = util . get_default_path ( self . conn ,
2011-07-22 19:50:30 -04:00
self . vm . get_name ( ) ,
collidelist = pathlist )
2012-01-16 22:04:40 -05:00
logging . debug ( " Default storage path is: %s " , path )
2007-04-12 15:36:04 -04:00
else :
2011-07-14 13:13:13 -04:00
path = self . widget ( " config-storage-entry " ) . get_text ( )
2007-04-12 15:36:04 -04:00
2012-02-07 16:51:16 -05:00
return ( path or None , size , sparse )
2007-04-12 15:36:04 -04:00
2007-07-14 13:48:24 -04:00
def get_config_disk_target ( self ) :
2011-07-14 13:13:13 -04:00
target = self . widget ( " config-storage-devtype " )
2010-03-04 15:35:34 -05:00
model = target . get_model ( )
idx = target . get_active ( )
if idx == - 1 :
return None , None
bus = model [ idx ] [ 0 ]
device = model [ idx ] [ 1 ]
2008-08-21 15:58:35 -04:00
return bus , device
2007-07-14 13:48:24 -04:00
2010-05-20 08:34:32 -04:00
def get_config_disk_cache ( self , label = False ) :
2011-07-14 13:13:13 -04:00
cache = self . widget ( " config-storage-cache " )
2010-05-20 08:34:32 -04:00
idx = 0
if label :
idx = 1
return cache . get_model ( ) [ cache . get_active ( ) ] [ idx ]
2010-12-10 19:20:14 -05:00
def get_config_disk_format ( self ) :
2011-07-14 13:13:13 -04:00
fmt = self . widget ( " config-storage-format " )
2012-05-14 14:24:56 +01:00
return fmt . get_child ( ) . get_text ( )
2010-12-10 19:20:14 -05:00
2009-11-24 12:43:54 -05:00
# Input getters
2007-09-25 20:05:45 -04:00
def get_config_input ( self ) :
2011-07-14 13:13:13 -04:00
target = self . widget ( " input-type " )
2007-09-25 20:05:45 -04:00
label = target . get_model ( ) . get_value ( target . get_active_iter ( ) , 0 )
2008-11-18 15:42:51 -05:00
_type = target . get_model ( ) . get_value ( target . get_active_iter ( ) , 1 )
2007-09-25 20:05:45 -04:00
bus = target . get_model ( ) . get_value ( target . get_active_iter ( ) , 2 )
2008-11-18 15:42:51 -05:00
return label , _type , bus
2007-09-25 20:05:45 -04:00
2009-11-24 12:43:54 -05:00
# Graphics getters
2007-09-26 19:39:11 -04:00
def get_config_graphics ( self ) :
2011-07-14 13:13:13 -04:00
_type = self . widget ( " graphics-type " )
2008-11-18 15:42:51 -05:00
if _type . get_active_iter ( ) is None :
2007-11-16 15:03:28 -05:00
return None
2008-11-18 15:42:51 -05:00
return _type . get_model ( ) . get_value ( _type . get_active_iter ( ) , 1 )
2007-09-26 19:39:11 -04:00
2010-12-21 20:16:01 +01:00
def get_config_graphics_port ( self ) :
2011-07-14 13:13:13 -04:00
port = self . widget ( " graphics-port " )
portAuto = self . widget ( " graphics-port-auto " )
2007-09-26 19:39:11 -04:00
if portAuto . get_active ( ) :
return - 1
return int ( port . get_value ( ) )
2010-12-21 20:16:01 +01:00
def get_config_graphics_tls_port ( self ) :
2011-07-14 13:13:13 -04:00
port = self . widget ( " graphics-tls-port " )
portAuto = self . widget ( " graphics-port-auto " )
2010-12-21 20:16:01 +01:00
if portAuto . get_active ( ) :
return - 1
return int ( port . get_value ( ) )
def get_config_graphics_address ( self ) :
2011-07-14 13:13:13 -04:00
addr = self . widget ( " graphics-address " )
2007-09-27 20:08:49 -04:00
if addr . get_active ( ) :
return " 0.0.0.0 "
return " 127.0.0.1 "
2007-09-26 19:39:11 -04:00
2010-12-21 20:16:01 +01:00
def get_config_graphics_password ( self ) :
2011-07-14 13:13:13 -04:00
pw = self . widget ( " graphics-password " )
2007-09-26 19:39:11 -04:00
return pw . get_text ( )
2008-03-17 13:09:45 -04:00
def get_config_keymap ( self ) :
2011-07-14 13:13:13 -04:00
g = self . widget ( " graphics-keymap " )
2012-11-09 12:13:22 +01:00
if g . get_sensitive ( ) and g . get_text ( ) != " " :
2008-06-16 12:00:13 -04:00
return g . get_text ( )
2008-03-17 13:09:45 -04:00
else :
2008-06-16 12:00:13 -04:00
return None
2008-03-17 13:09:45 -04:00
2009-11-24 12:43:54 -05:00
# Network getters
2007-04-12 15:36:04 -04:00
def get_config_network ( self ) :
2011-07-14 13:13:13 -04:00
net_list = self . widget ( " net-list " )
bridge_ent = self . widget ( " net-bridge " )
2007-04-12 15:36:04 -04:00
2010-03-20 18:35:47 -04:00
net_type , net_src = uihelpers . get_network_selection ( net_list ,
bridge_ent )
2009-11-24 13:14:55 -05:00
2010-03-20 18:35:47 -04:00
return net_type , net_src
2007-04-12 15:36:04 -04:00
2009-01-22 17:00:10 -05:00
def get_config_net_model ( self ) :
2011-07-14 13:13:13 -04:00
model = self . widget ( " net-model " )
2009-06-17 11:56:45 -04:00
if model . get_active_iter ( ) :
modelxml = model . get_model ( ) . get_value ( model . get_active_iter ( ) , 0 )
modelstr = model . get_model ( ) . get_value ( model . get_active_iter ( ) , 1 )
else :
modelxml = modelstr = None
2009-01-22 17:00:10 -05:00
return modelxml , modelstr
2007-05-24 15:51:32 -04:00
def get_config_macaddr ( self ) :
macaddr = None
2011-07-14 13:13:13 -04:00
if self . widget ( " mac-address " ) . get_active ( ) :
macaddr = self . widget ( " create-mac-address " ) . get_text ( )
2007-05-24 15:51:32 -04:00
return macaddr
2009-11-24 12:43:54 -05:00
# Sound getters
2009-01-22 17:00:26 -05:00
def get_config_sound_model ( self ) :
2011-07-14 13:13:13 -04:00
model = self . widget ( " sound-model " )
2009-01-22 17:00:26 -05:00
modelstr = model . get_model ( ) . get_value ( model . get_active_iter ( ) , 0 )
return modelstr
2009-11-24 12:43:54 -05:00
# Host device getters
2009-03-09 16:20:23 -04:00
def get_config_host_device_type_info ( self ) :
2010-12-11 15:55:31 -05:00
pci_info = [ " PCI Device " , " pci " , None , " net " , " 80203 " ]
usb_info = [ " USB Device " , " usb_device " , None , None , None ]
row = self . get_hw_selection ( )
if row and row [ 5 ] == " pci " :
return pci_info
return usb_info
2009-03-09 16:20:23 -04:00
def get_config_host_device_info ( self ) :
2011-07-14 13:13:13 -04:00
devrow = util . get_list_selection ( self . widget ( " host-device " ) )
2010-12-11 15:12:22 -05:00
if not devrow :
return [ ]
return devrow
2009-03-09 16:20:23 -04:00
2009-11-24 12:43:54 -05:00
# Video Getters
2009-07-14 09:25:39 -04:00
def get_config_video_model ( self ) :
2011-07-14 13:13:13 -04:00
modbox = self . widget ( " video-model " )
2009-07-14 09:25:39 -04:00
return modbox . get_model ( ) [ modbox . get_active ( ) ] [ 0 ]
2010-03-24 00:22:17 -04:00
# Watchdog getters
def get_config_watchdog_model ( self ) :
2011-07-14 13:13:13 -04:00
modbox = self . widget ( " watchdog-model " )
2010-03-24 00:22:17 -04:00
return modbox . get_model ( ) [ modbox . get_active ( ) ] [ 0 ]
def get_config_watchdog_action ( self ) :
2011-07-14 13:13:13 -04:00
modbox = self . widget ( " watchdog-action " )
2010-03-24 00:22:17 -04:00
return modbox . get_model ( ) [ modbox . get_active ( ) ] [ 0 ]
2009-11-24 12:43:54 -05:00
2011-05-19 18:17:58 -04:00
# FS getters
def get_config_fs_mode ( self ) :
name = " fs-mode-combo "
2011-07-14 13:13:13 -04:00
combo = self . widget ( name )
2011-05-19 18:17:58 -04:00
if not combo . get_property ( " visible " ) :
return None
return combo . get_model ( ) [ combo . get_active ( ) ] [ 0 ]
2012-01-19 00:22:02 +05:30
def get_config_fs_wrpolicy ( self ) :
name = " fs-wrpolicy-combo "
combo = self . widget ( name )
if not combo . get_property ( " visible " ) :
return None
return combo . get_model ( ) [ combo . get_active ( ) ] [ 0 ]
2011-05-19 18:17:58 -04:00
def get_config_fs_type ( self ) :
name = " fs-type-combo "
2011-07-14 13:13:13 -04:00
combo = self . widget ( name )
2011-05-19 18:17:58 -04:00
if not combo . get_property ( " visible " ) :
return None
return combo . get_model ( ) [ combo . get_active ( ) ] [ 0 ]
2011-12-22 23:40:17 +05:30
def get_config_fs_readonly ( self ) :
name = " fs-readonly "
check = self . widget ( name )
if not check . get_property ( " visible " ) :
return None
return check . get_active ( )
2012-01-12 20:28:26 -05:00
def get_config_fs_driver ( self ) :
name = " fs-driver-combo "
combo = self . widget ( name )
if not combo . get_property ( " visible " ) :
return None
return combo . get_model ( ) [ combo . get_active ( ) ] [ 0 ]
2011-06-23 17:42:03 +02:00
# Smartcard getters
def get_config_smartcard_mode ( self ) :
2011-07-14 13:13:13 -04:00
mode = self . widget ( " smartcard-mode " )
2011-06-23 17:42:03 +02:00
modestr = mode . get_model ( ) . get_value ( mode . get_active_iter ( ) , 0 )
return modestr
2011-09-02 03:23:28 +02:00
# USB redir getters
def get_config_usbredir_host ( self ) :
host = self . widget ( " usbredir-host " )
2012-05-14 12:37:01 -03:00
if not host . props . sensitive :
2011-09-02 03:23:28 +02:00
return None
hoststr = host . get_text ( )
return hoststr
def get_config_usbredir_service ( self ) :
service = self . widget ( " usbredir-service " )
2012-05-14 12:37:01 -03:00
if not service . props . sensitive :
2011-09-02 03:23:28 +02:00
return None
return int ( service . get_value ( ) )
def get_config_usbredir_type ( self ) :
typebox = self . widget ( " usbredir-list " )
return typebox . get_model ( ) [ typebox . get_active ( ) ] [ 0 ]
2009-11-24 12:43:54 -05:00
################
# UI listeners #
################
2010-12-11 12:32:04 -05:00
def set_hw_selection ( self , page ) :
2011-07-14 13:13:13 -04:00
util . set_list_selection ( self . widget ( " hardware-list " ) , page )
2009-11-24 12:43:54 -05:00
2010-12-11 12:32:04 -05:00
def get_hw_selection ( self ) :
2011-07-14 13:13:13 -04:00
return util . get_list_selection ( self . widget ( " hardware-list " ) )
2009-11-24 12:43:54 -05:00
2011-04-05 01:35:32 +02:00
def update_char_device_type_model ( self ) :
2011-09-26 11:34:21 -04:00
rhel6_blacklist = [ " pipe " , " udp " ]
2011-04-05 01:35:32 +02:00
# Char device type
2011-07-14 13:13:13 -04:00
char_devtype = self . widget ( " char-device-type " )
2011-04-05 01:35:32 +02:00
dev_type = self . get_char_type ( )
# Type name, desc
2012-05-14 14:24:56 +01:00
char_devtype_model = Gtk . ListStore ( str , str )
2011-04-05 01:35:32 +02:00
char_devtype . clear ( )
char_devtype . set_model ( char_devtype_model )
2012-05-14 14:24:56 +01:00
text = Gtk . CellRendererText ( )
2011-04-05 01:35:32 +02:00
char_devtype . pack_start ( text , True )
char_devtype . add_attribute ( text , ' text ' , 1 )
2011-09-26 11:34:21 -04:00
2011-04-05 01:35:32 +02:00
for t in VirtualCharDevice . char_types_for_dev_type [ dev_type ] :
2011-09-26 11:34:21 -04:00
if ( t in rhel6_blacklist and
not self . vm . rhel6_defaults ( ) ) :
continue
2011-04-05 01:35:32 +02:00
desc = VirtualCharDevice . get_char_type_desc ( t )
row = [ t , desc + " ( %s ) " % t ]
char_devtype_model . append ( row )
char_devtype . set_active ( 0 )
2010-12-11 12:32:04 -05:00
def hw_selected ( self , src = None ) :
ignore = src
self . _dev = None
2011-07-14 13:13:13 -04:00
notebook = self . widget ( " create-pages " )
2009-11-24 12:43:54 -05:00
2010-12-11 12:32:04 -05:00
row = self . get_hw_selection ( )
if not row :
self . set_hw_selection ( 0 )
return
2009-11-24 13:32:14 -05:00
2010-12-11 12:32:04 -05:00
page = row [ 2 ]
sens = row [ 3 ]
msg = row [ 4 ] or " "
2009-11-24 12:43:54 -05:00
2010-12-11 12:32:04 -05:00
if not sens :
2010-12-11 14:51:08 -05:00
page = PAGE_ERROR
2011-07-14 13:13:13 -04:00
self . widget ( " hardware-info " ) . set_text ( msg )
2010-03-04 15:29:33 -05:00
2010-12-11 12:32:04 -05:00
if page == PAGE_CHAR :
2011-04-05 01:35:32 +02:00
self . update_char_device_type_model ( )
2011-07-14 13:13:13 -04:00
devtype = self . widget ( " char-device-type " )
2009-07-14 09:25:39 -04:00
self . change_char_device_type ( devtype )
2010-12-11 15:55:31 -05:00
if page == PAGE_HOSTDEV :
( ignore , devtype , devcap ,
subtype , subcap ) = self . get_config_host_device_type_info ( )
self . populate_host_device_model ( devtype , devcap ,
subtype , subcap )
2010-12-11 13:05:07 -05:00
self . set_page_title ( page )
2010-12-11 14:51:08 -05:00
notebook . get_nth_page ( page ) . show ( )
notebook . set_current_page ( page )
2007-04-12 15:36:04 -04:00
def finish ( self , ignore = None ) :
2011-07-14 13:13:13 -04:00
notebook = self . widget ( " create-pages " )
2010-12-11 12:32:04 -05:00
try :
2012-11-08 14:15:02 +01:00
if self . validate ( notebook . get_current_page ( ) ) is False :
2010-12-11 12:32:04 -05:00
return
except Exception , e :
self . err . show_err ( _ ( " Uncaught error validating hardware "
2011-04-06 11:22:03 -04:00
" input: %s " ) % str ( e ) )
2010-12-11 12:32:04 -05:00
return
2007-04-12 15:36:04 -04:00
self . topwin . set_sensitive ( False )
2012-05-14 14:24:56 +01:00
self . topwin . get_window ( ) . set_cursor ( Gdk . Cursor . new ( Gdk . CursorType . WATCH ) )
2007-04-12 15:36:04 -04:00
2009-03-09 16:20:23 -04:00
try :
2010-02-06 15:59:52 -05:00
failure , errinfo = self . add_device ( )
2009-04-03 14:15:15 -04:00
error , details = errinfo or ( None , None )
2009-03-09 16:20:23 -04:00
except Exception , e :
2010-02-06 15:59:52 -05:00
failure = True
2009-04-03 14:15:15 -04:00
error = _ ( " Unable to add device: %s " ) % str ( e )
details = " " . join ( traceback . format_exc ( ) )
2007-04-12 15:36:04 -04:00
2009-04-03 14:15:15 -04:00
if error is not None :
2011-04-06 11:22:03 -04:00
self . err . show_err ( error , details = details )
2007-04-12 15:36:04 -04:00
self . topwin . set_sensitive ( True )
2012-05-14 14:24:56 +01:00
self . topwin . get_window ( ) . set_cursor ( Gdk . Cursor . new ( Gdk . CursorType . TOP_LEFT_ARROW ) )
2009-04-03 14:15:15 -04:00
2010-12-11 12:32:04 -05:00
self . _dev = None
2010-02-06 15:59:52 -05:00
if not failure :
2009-04-03 14:15:15 -04:00
self . close ( )
2007-04-12 15:36:04 -04:00
2011-06-08 18:38:03 -04:00
def show_pair_combo ( self , basename , show_combo ) :
2011-07-14 13:13:13 -04:00
combo = self . widget ( basename + " -combo " )
label = self . widget ( basename + " -label " )
2011-06-08 18:38:03 -04:00
combo . set_property ( " visible " , show_combo )
label . set_property ( " visible " , not show_combo )
2011-12-22 23:40:17 +05:30
def show_check_button ( self , basename , show ) :
check = self . widget ( basename )
check . set_property ( " visible " , show )
2009-11-24 12:43:54 -05:00
# Storage listeners
2010-03-04 15:35:34 -05:00
def browse_storage ( self , ignore1 ) :
2011-07-14 13:13:13 -04:00
self . _browse_file ( self . widget ( " config-storage-entry " ) )
2010-03-04 15:35:34 -05:00
def toggle_storage_select ( self , src ) :
act = src . get_active ( )
2011-07-14 13:13:13 -04:00
self . widget ( " config-storage-browse-box " ) . set_sensitive ( act )
2010-03-04 15:35:34 -05:00
def set_disk_storage_path ( self , ignore , path ) :
2011-07-14 13:13:13 -04:00
self . widget ( " config-storage-entry " ) . set_text ( path )
2007-04-12 15:36:04 -04:00
2009-11-24 12:43:54 -05:00
# Network listeners
2007-05-24 15:51:32 -04:00
def change_macaddr_use ( self , ignore = None ) :
2011-07-14 13:13:13 -04:00
if self . widget ( " mac-address " ) . get_active ( ) :
self . widget ( " create-mac-address " ) . set_sensitive ( True )
2007-05-24 15:51:32 -04:00
else :
2011-07-14 13:13:13 -04:00
self . widget ( " create-mac-address " ) . set_sensitive ( False )
2007-05-24 15:51:32 -04:00
2009-11-24 12:43:54 -05:00
# Graphics listeners
2010-11-29 14:06:43 -05:00
def change_graphics_type ( self , ignore = None ) :
2007-09-26 19:39:11 -04:00
graphics = self . get_config_graphics ( )
2010-12-21 20:16:01 +01:00
if graphics in [ " vnc " , " spice " ] :
2011-07-14 13:13:13 -04:00
self . widget ( " graphics-port-auto " ) . set_sensitive ( True )
self . widget ( " graphics-address " ) . set_sensitive ( True )
self . widget ( " graphics-password " ) . set_sensitive ( True )
self . widget ( " graphics-keymap-chk " ) . set_sensitive ( True )
2007-09-26 19:39:11 -04:00
self . change_port_auto ( )
else :
2011-07-14 13:13:13 -04:00
self . widget ( " graphics-port " ) . set_sensitive ( False )
self . widget ( " graphics-tls-port " ) . set_sensitive ( False )
self . widget ( " graphics-port-auto " ) . set_sensitive ( False )
self . widget ( " graphics-address " ) . set_sensitive ( False )
self . widget ( " graphics-password " ) . set_sensitive ( False )
self . widget ( " graphics-keymap-chk " ) . set_sensitive ( False )
self . widget ( " graphics-keymap " ) . set_sensitive ( False )
2007-09-26 19:39:11 -04:00
2010-11-29 14:06:43 -05:00
def change_port_auto ( self , ignore = None ) :
2010-12-21 20:16:01 +01:00
graphics = self . get_config_graphics ( )
tls_enable = graphics == " spice "
2011-07-14 13:13:13 -04:00
if self . widget ( " graphics-port-auto " ) . get_active ( ) :
self . widget ( " graphics-port " ) . set_sensitive ( False )
self . widget ( " graphics-tls-port " ) . set_sensitive ( False )
2007-09-26 19:39:11 -04:00
else :
2011-07-14 13:13:13 -04:00
self . widget ( " graphics-port " ) . set_sensitive ( True )
self . widget ( " graphics-tls-port " ) . set_sensitive ( tls_enable )
2007-09-26 19:39:11 -04:00
2008-03-17 13:09:45 -04:00
def change_keymap ( self , ignore = None ) :
2011-07-14 13:13:13 -04:00
if self . widget ( " graphics-keymap-chk " ) . get_active ( ) :
self . widget ( " graphics-keymap " ) . set_sensitive ( False )
2008-03-17 13:09:45 -04:00
else :
2011-07-14 13:13:13 -04:00
self . widget ( " graphics-keymap " ) . set_sensitive ( True )
2008-03-17 13:09:45 -04:00
2009-11-24 12:43:54 -05:00
# Char device listeners
2009-07-14 09:25:39 -04:00
def get_char_type ( self ) :
2010-12-11 12:32:04 -05:00
row = self . get_hw_selection ( )
label = " serial "
if row :
2010-12-11 15:55:31 -05:00
label = row [ 5 ]
2009-07-14 09:25:39 -04:00
2010-12-11 15:55:31 -05:00
if label == " parallel " :
2013-04-10 19:48:07 -04:00
return VirtualCharDevice . VIRTUAL_DEV_PARALLEL
2011-04-05 01:35:32 +02:00
elif label == " channel " :
2013-04-10 19:48:07 -04:00
return VirtualCharDevice . VIRTUAL_DEV_CHANNEL
return VirtualCharDevice . VIRTUAL_DEV_SERIAL
2009-07-14 09:25:39 -04:00
2010-12-11 13:05:07 -05:00
def dev_to_title ( self , page ) :
if page == PAGE_ERROR :
return _ ( " Error " )
if page == PAGE_DISK :
return _ ( " Storage " )
if page == PAGE_NETWORK :
return _ ( " Network " )
if page == PAGE_INPUT :
return _ ( " Input " )
if page == PAGE_GRAPHICS :
return _ ( " Graphics " )
if page == PAGE_SOUND :
return _ ( " Sound " )
if page == PAGE_VIDEO :
return _ ( " Video Device " )
if page == PAGE_WATCHDOG :
return _ ( " Watchdog Device " )
2011-05-19 18:17:58 -04:00
if page == PAGE_FILESYSTEM :
return _ ( " Filesystem Passthrough " )
2011-06-23 17:42:03 +02:00
if page == PAGE_SMARTCARD :
return _ ( " Smartcard " )
2011-09-02 03:23:28 +02:00
if page == PAGE_USBREDIR :
return _ ( " USB Redirection " )
2010-12-11 13:05:07 -05:00
2010-12-11 15:55:31 -05:00
if page == PAGE_CHAR :
return self . get_char_type ( ) . capitalize ( ) + " Device "
if page == PAGE_HOSTDEV :
return self . get_config_host_device_type_info ( ) [ 0 ]
raise RuntimeError ( " Unknown page %s " % page )
2010-12-11 13:05:07 -05:00
def set_page_title ( self , page ) :
title = self . dev_to_title ( page )
markup = ( """ <span weight= " heavy " size= " xx-large " """
""" foreground= " #FFF " > %s </span> """ ) % title
2011-07-14 13:13:13 -04:00
self . widget ( " page-title-label " ) . set_markup ( markup )
2009-07-14 09:25:39 -04:00
def change_char_device_type ( self , src ) :
2013-01-12 16:13:53 -05:00
self . _update_doc ( " char_type " )
2011-04-05 01:35:32 +02:00
idx = src . get_active ( )
if idx < 0 :
return
2009-07-14 09:25:39 -04:00
chartype = self . get_char_type ( )
devtype = src . get_model ( ) [ src . get_active ( ) ] [ 0 ]
2011-04-11 18:35:21 -04:00
conn = self . conn . vmm
2009-07-14 09:25:39 -04:00
self . _dev = VirtualCharDevice . get_dev_instance ( conn ,
chartype ,
devtype )
2011-04-05 16:41:48 -04:00
show_something = False
2009-07-14 09:25:39 -04:00
for param_name , widget_name in char_widget_mappings . items ( ) :
2010-09-02 18:37:20 -04:00
make_visible = self . _dev . supports_property ( param_name )
2011-04-05 16:41:48 -04:00
if make_visible :
show_something = True
2011-07-14 13:13:13 -04:00
self . widget ( widget_name ) . set_property ( " visible " , make_visible )
self . widget ( widget_name + " -label " ) . set_property ( " visible " ,
2011-04-05 16:41:48 -04:00
make_visible )
2011-07-14 13:13:13 -04:00
self . widget ( " char-param-box " ) . set_property ( " visible " , show_something )
2009-07-14 09:25:39 -04:00
2010-09-02 18:37:20 -04:00
has_mode = self . _dev . supports_property ( " source_mode " )
2011-07-14 13:13:13 -04:00
if has_mode and self . widget ( " char-mode " ) . get_active ( ) == - 1 :
self . widget ( " char-mode " ) . set_active ( 0 )
2009-07-14 09:25:39 -04:00
2011-09-02 03:23:28 +02:00
def change_usbredir_type ( self , src ) :
idx = src . get_active ( )
if idx < 0 :
return
hostdetails = src . get_model ( ) [ src . get_active ( ) ] [ 2 ]
self . widget ( " usbredir-host " ) . set_sensitive ( hostdetails )
self . widget ( " usbredir-service " ) . set_sensitive ( hostdetails )
2011-06-08 18:38:03 -04:00
# FS listeners
def browse_fs_source ( self , ignore1 ) :
2011-07-14 13:13:13 -04:00
self . _browse_file ( self . widget ( " fs-source " ) , isdir = True )
2011-05-19 18:17:58 -04:00
def change_fs_type ( self , src ) :
idx = src . get_active ( )
fstype = None
show_mode_combo = False
2012-01-12 20:28:26 -05:00
show_driver_combo = False
2012-01-19 00:22:02 +05:30
show_wrpolicy_combo = self . conn . is_qemu ( )
2011-05-19 18:17:58 -04:00
if idx > = 0 and src . get_property ( " visible " ) :
fstype = src . get_model ( ) [ idx ] [ 0 ]
if fstype == virtinst . VirtualFilesystem . TYPE_TEMPLATE :
source_text = _ ( " Te_mplate: " )
else :
source_text = _ ( " _Source path: " )
show_mode_combo = self . conn . is_qemu ( )
2012-01-12 20:28:26 -05:00
show_driver_combo = self . conn . is_qemu ( )
2011-05-19 18:17:58 -04:00
2011-07-14 13:13:13 -04:00
self . widget ( " fs-source-title " ) . set_text ( source_text )
self . widget ( " fs-source-title " ) . set_use_underline ( True )
2011-05-19 18:17:58 -04:00
self . show_pair_combo ( " fs-mode " , show_mode_combo )
2012-01-12 20:28:26 -05:00
self . show_pair_combo ( " fs-driver " , show_driver_combo )
2012-01-19 00:22:02 +05:30
self . show_pair_combo ( " fs-wrpolicy " , show_wrpolicy_combo )
2012-01-12 20:28:26 -05:00
def change_fs_driver ( self , src ) :
idx = src . get_active ( )
fsdriver = None
2012-01-19 00:22:02 +05:30
modecombo = self . widget ( " fs-mode-combo " )
modelabel1 = self . widget ( " fs-mode-title " )
wrpcombo = self . widget ( " fs-wrpolicy-combo " )
wrplabel1 = self . widget ( " fs-wrpolicy-title " )
2012-01-12 20:28:26 -05:00
if idx > = 0 and src . get_property ( " visible " ) :
fsdriver = src . get_model ( ) [ idx ] [ 0 ]
if ( fsdriver == virtinst . VirtualFilesystem . DRIVER_PATH or
fsdriver == virtinst . VirtualFilesystem . DRIVER_DEFAULT ) :
2012-01-19 00:22:02 +05:30
modecombo . set_property ( " visible " , True )
modelabel1 . set_property ( " visible " , True )
2012-01-12 20:28:26 -05:00
else :
2012-01-19 00:22:02 +05:30
modecombo . set_property ( " visible " , False )
modelabel1 . set_property ( " visible " , False )
2012-01-12 20:28:26 -05:00
2012-01-19 00:22:02 +05:30
if ( fsdriver == virtinst . VirtualFilesystem . DRIVER_DEFAULT ) :
wrpcombo . set_property ( " visible " , False )
wrplabel1 . set_property ( " visible " , False )
else :
wrpcombo . set_property ( " visible " , True )
wrplabel1 . set_property ( " visible " , True )
2012-01-12 20:28:26 -05:00
2011-05-19 18:17:58 -04:00
2008-08-21 15:58:35 -04:00
2009-11-24 12:43:54 -05:00
######################
# Add device methods #
######################
2007-04-12 15:36:04 -04:00
2012-10-21 14:43:44 -04:00
def _storage_progress ( self ) :
2010-12-10 09:57:42 -05:00
def do_file_allocate ( asyncjob , disk ) :
2012-02-10 10:24:43 -05:00
meter = asyncjob . get_meter ( )
2010-12-10 09:57:42 -05:00
# If creating disk via storage API, we need to thread
# off a new connection
if disk . vol_install :
newconn = util . dup_lib_conn ( disk . conn )
disk . conn = newconn
logging . debug ( " Starting background file allocate process " )
disk . setup_dev ( self . conn . vmm , meter = meter )
logging . debug ( " Allocation completed " )
progWin = vmmAsyncJob ( do_file_allocate ,
[ self . _dev ] ,
2011-04-14 08:47:42 -04:00
_ ( " Creating Storage File " ) ,
_ ( " Allocation of disk storage may take "
" a few minutes to complete. " ) ,
self . topwin )
2010-12-10 09:57:42 -05:00
return progWin . run ( )
2007-04-12 15:36:04 -04:00
2012-10-21 14:43:44 -04:00
def setup_device ( self ) :
if ( self . _dev . virtual_device_type == self . _dev . VIRTUAL_DEV_DISK and
self . _dev . creating_storage ( ) ) :
return self . _storage_progress ( )
return self . _dev . setup_dev ( self . conn . vmm )
2008-03-14 13:18:44 -04:00
2010-02-06 15:59:52 -05:00
def add_device ( self ) :
ret = self . setup_device ( )
2010-12-10 09:57:42 -05:00
if ret and ret [ 0 ] :
2010-02-06 15:59:52 -05:00
# Encountered an error
return ( True , ret )
2010-02-07 12:10:41 -05:00
self . _dev . get_xml_config ( )
logging . debug ( " Adding device: \n " + self . _dev . get_xml_config ( ) )
2007-11-16 17:12:37 -05:00
2012-12-07 18:21:38 +08:00
controller = getattr ( self . _dev , " vmm_controller " , None )
if controller is not None :
logging . debug ( " Adding controller: \n %s " ,
self . _dev . vmm_controller . get_xml_config ( ) )
2009-11-24 12:43:54 -05:00
# Hotplug device
attach_err = False
try :
2012-12-07 18:21:38 +08:00
if controller is not None :
self . vm . attach_device ( self . _dev . vmm_controller )
2010-02-07 12:10:41 -05:00
self . vm . attach_device ( self . _dev )
2009-11-24 12:43:54 -05:00
except Exception , e :
2012-01-16 22:04:40 -05:00
logging . debug ( " Device could not be hotplugged: %s " , str ( e ) )
2010-12-01 17:48:07 -05:00
attach_err = ( str ( e ) , " " . join ( traceback . format_exc ( ) ) )
2007-11-16 17:12:37 -05:00
2009-11-24 12:43:54 -05:00
if attach_err :
2010-12-01 17:48:07 -05:00
res = self . err . show_err (
_ ( " Are you sure you want to add this device? " ) ,
2011-04-06 11:22:03 -04:00
details = ( attach_err [ 0 ] + " \n \n " + attach_err [ 1 ] ) ,
2010-12-01 17:48:07 -05:00
text2 = (
_ ( " This device could not be attached to the running machine. "
" Would you like to make the device available after the "
2011-07-14 17:16:57 -04:00
" next guest shutdown? " ) ) ,
2012-05-14 14:24:56 +01:00
dialog_type = Gtk . MessageType . WARNING ,
buttons = Gtk . ButtonsType . YES_NO ,
2011-04-05 16:15:05 -04:00
async = False )
2010-12-01 17:48:07 -05:00
if not res :
2010-02-06 15:59:52 -05:00
return ( False , None )
2008-03-14 10:55:12 -04:00
2009-11-24 12:43:54 -05:00
# Alter persistent config
try :
2012-12-07 18:21:38 +08:00
if controller is not None :
self . vm . add_device ( self . _dev . vmm_controller )
2010-02-07 12:10:41 -05:00
self . vm . add_device ( self . _dev )
2009-11-24 12:43:54 -05:00
except Exception , e :
2011-04-06 11:22:03 -04:00
self . err . show_err ( _ ( " Error adding device: %s " % str ( e ) ) )
2010-02-06 15:59:52 -05:00
return ( True , None )
return ( False , None )
2009-11-24 12:43:54 -05:00
2009-03-09 16:20:23 -04:00
2009-11-24 12:43:54 -05:00
###########################
# Page validation methods #
###########################
def validate ( self , page_num ) :
2010-12-11 12:32:04 -05:00
if page_num == PAGE_ERROR :
self . _dev = None
return True
2009-11-24 12:43:54 -05:00
elif page_num == PAGE_DISK :
return self . validate_page_storage ( )
elif page_num == PAGE_NETWORK :
return self . validate_page_network ( )
elif page_num == PAGE_INPUT :
2010-02-06 15:33:32 -05:00
return self . validate_page_input ( )
2009-11-24 12:43:54 -05:00
elif page_num == PAGE_GRAPHICS :
return self . validate_page_graphics ( )
elif page_num == PAGE_SOUND :
return self . validate_page_sound ( )
2009-03-09 16:20:23 -04:00
elif page_num == PAGE_HOSTDEV :
2009-11-24 12:43:54 -05:00
return self . validate_page_hostdev ( )
elif page_num == PAGE_CHAR :
return self . validate_page_char ( )
elif page_num == PAGE_VIDEO :
return self . validate_page_video ( )
2010-03-24 00:22:17 -04:00
elif page_num == PAGE_WATCHDOG :
return self . validate_page_watchdog ( )
2011-05-19 18:17:58 -04:00
elif page_num == PAGE_FILESYSTEM :
return self . validate_page_filesystem ( )
2011-06-23 17:42:03 +02:00
elif page_num == PAGE_SMARTCARD :
return self . validate_page_smartcard ( )
2011-09-02 03:23:28 +02:00
elif page_num == PAGE_USBREDIR :
return self . validate_page_usbredir ( )
2009-03-09 16:20:23 -04:00
2009-11-24 12:43:54 -05:00
def validate_page_storage ( self ) :
bus , device = self . get_config_disk_target ( )
2010-05-20 08:34:32 -04:00
cache = self . get_config_disk_cache ( )
2010-12-10 19:20:14 -05:00
fmt = self . get_config_disk_format ( )
2012-12-07 18:21:38 +08:00
controller_model = None
if bus == " virtio-scsi " :
2013-02-06 15:41:43 -05:00
bus = " scsi "
controller_model = " virtio-scsi "
2009-11-24 12:43:54 -05:00
2010-05-13 10:37:46 -04:00
# Make sure default pool is running
if self . is_default_storage ( ) :
ret = uihelpers . check_default_pool_active ( self . topwin , self . conn )
if not ret :
return False
2009-11-24 12:43:54 -05:00
readonly = False
if device == virtinst . VirtualDisk . DEVICE_CDROM :
2010-11-29 14:06:43 -05:00
readonly = True
2009-11-24 12:43:54 -05:00
try :
2010-03-04 15:35:34 -05:00
# This can error out
diskpath , disksize , sparse = self . get_storage_info ( )
if self . is_default_storage ( ) :
# See if the ideal disk path (/default/pool/vmname.img)
# exists, and if unused, prompt the use for using it
2010-12-09 14:06:00 -05:00
ideal = util . get_ideal_path ( self . conn ,
2010-03-04 15:35:34 -05:00
self . vm . get_name ( ) )
do_exist = False
ret = True
try :
do_exist = virtinst . VirtualDisk . path_exists (
self . conn . vmm , ideal )
ret = virtinst . VirtualDisk . path_in_use_by ( self . conn . vmm ,
ideal )
except :
logging . exception ( " Error checking default path usage " )
if do_exist and not ret :
do_use = self . err . yes_no (
2011-03-08 11:22:01 -05:00
_ ( " The following storage already exists, but is not \n "
2010-03-04 15:35:34 -05:00
" in use by any virtual machine: \n \n %s \n \n "
2011-03-08 11:22:01 -05:00
" Would you like to reuse this storage? " ) % ideal )
2010-03-04 15:35:34 -05:00
if do_use :
diskpath = ideal
2010-12-10 11:47:07 -05:00
disk = virtinst . VirtualDisk ( conn = self . conn . vmm ,
path = diskpath ,
size = disksize ,
sparse = sparse ,
readOnly = readonly ,
device = device ,
bus = bus ,
2010-12-10 19:20:14 -05:00
driverCache = cache ,
format = fmt )
2010-03-04 15:35:34 -05:00
2012-02-13 15:18:43 -05:00
if not fmt :
fmt = self . config . get_storage_format ( )
if ( self . is_default_storage ( ) and
disk . vol_install and
fmt in disk . vol_install . formats ) :
logging . debug ( " Setting disk format from prefs: %s " , fmt )
disk . vol_install . format = fmt
2010-03-04 15:35:34 -05:00
if ( disk . type == virtinst . VirtualDisk . TYPE_FILE and
not self . vm . is_hvm ( ) and
virtinst . util . is_blktap_capable ( ) ) :
disk . driver_name = virtinst . VirtualDisk . DRIVER_TAP
2009-11-24 12:43:54 -05:00
2010-03-04 15:35:34 -05:00
except Exception , e :
2011-08-30 14:50:50 -04:00
return self . err . val_err ( _ ( " Storage parameter error. " ) , e )
2009-12-01 12:35:04 -05:00
2010-02-06 15:59:52 -05:00
# Generate target
used = [ ]
disks = ( self . vm . get_disk_devices ( ) +
self . vm . get_disk_devices ( inactive = True ) )
for d in disks :
2010-09-03 14:10:04 -04:00
used . append ( d . target )
2010-02-06 15:59:52 -05:00
2010-03-04 15:35:34 -05:00
disk . generate_target ( used )
isfatal , errmsg = disk . is_size_conflict ( )
if not isfatal and errmsg :
# Fatal errors are reported when setting 'size'
res = self . err . ok_cancel ( _ ( " Not Enough Free Space " ) , errmsg )
if not res :
return False
# Disk collision
if disk . is_conflict_disk ( self . conn . vmm ) :
res = self . err . yes_no ( _ ( ' Disk " %s " is already in use by another '
2010-12-10 11:47:07 -05:00
' guest! ' % disk . path ) ,
2010-03-04 15:35:34 -05:00
_ ( " Do you really want to use the disk? " ) )
if not res :
return False
2010-02-06 15:59:52 -05:00
2010-12-09 14:06:00 -05:00
uihelpers . check_path_search_for_qemu ( self . topwin ,
2010-03-04 15:35:34 -05:00
self . conn , disk . path )
2012-12-07 18:21:38 +08:00
# Add a SCSI controller with model virtio-scsi if needed
disk . vmm_controller = None
if ( controller_model == " virtio-scsi " ) and ( bus == " scsi " ) :
controllers = self . vm . get_controller_devices ( )
2012-11-08 14:15:02 +01:00
controller = VirtualControllerSCSI ( conn = self . conn . vmm )
2012-12-07 18:21:38 +08:00
controller . set_model ( controller_model )
disk . vmm_controller = controller
for d in controllers :
if controller_model == d . model :
2013-02-06 15:41:43 -05:00
disk . vmm_controller = None
2012-12-07 18:21:38 +08:00
2010-03-04 15:35:34 -05:00
self . _dev = disk
return True
2009-12-01 12:35:04 -05:00
2009-11-24 12:43:54 -05:00
def validate_page_network ( self ) :
2009-11-24 13:14:55 -05:00
nettype , devname = self . get_config_network ( )
2009-11-24 12:43:54 -05:00
mac = self . get_config_macaddr ( )
2009-11-24 13:14:55 -05:00
model = self . get_config_net_model ( ) [ 0 ]
2009-11-24 12:43:54 -05:00
2009-11-24 13:14:55 -05:00
if not nettype :
return self . err . val_err ( _ ( " Network selection error. " ) ,
_ ( " A network source must be selected. " ) )
2009-03-09 16:20:23 -04:00
2009-11-24 13:14:55 -05:00
if not mac :
return self . err . val_err ( _ ( " Invalid MAC address " ) ,
_ ( " A MAC address must be entered. " ) )
2009-01-22 17:00:26 -05:00
2011-04-11 18:35:21 -04:00
ret = uihelpers . validate_network ( self . topwin , self . conn ,
2009-11-24 13:14:55 -05:00
nettype , devname , mac , model )
2012-11-08 14:15:02 +01:00
if ret is False :
2009-11-24 13:14:55 -05:00
return False
2009-07-14 09:25:39 -04:00
2009-11-24 13:14:55 -05:00
self . _dev = ret
2009-07-14 09:25:39 -04:00
2010-02-06 15:33:32 -05:00
def validate_page_input ( self ) :
ignore , inp_type , inp_bus = self . get_config_input ( )
dev = virtinst . VirtualInputDevice ( self . conn . vmm )
dev . type = inp_type
dev . bus = inp_bus
self . _dev = dev
2009-11-24 12:43:54 -05:00
def validate_page_graphics ( self ) :
graphics = self . get_config_graphics ( )
2010-12-21 20:16:01 +01:00
_type = { " vnc " : virtinst . VirtualGraphics . TYPE_VNC ,
" spice " : virtinst . VirtualGraphics . TYPE_SPICE ,
" sdl " : virtinst . VirtualGraphics . TYPE_SDL } [ graphics ]
2009-07-14 09:25:39 -04:00
2010-05-05 15:57:00 -04:00
self . _dev = virtinst . VirtualGraphics ( type = _type ,
2011-04-11 18:35:21 -04:00
conn = self . conn . vmm )
2009-11-24 12:43:54 -05:00
try :
2010-12-21 20:16:01 +01:00
self . _dev . port = self . get_config_graphics_port ( )
self . _dev . tlsPort = self . get_config_graphics_tls_port ( )
self . _dev . passwd = self . get_config_graphics_password ( )
self . _dev . listen = self . get_config_graphics_address ( )
2009-11-24 12:43:54 -05:00
self . _dev . keymap = self . get_config_keymap ( )
except ValueError , e :
2011-08-30 14:50:50 -04:00
self . err . val_err ( _ ( " Graphics device parameter error " ) , e )
2009-11-24 12:43:54 -05:00
def validate_page_sound ( self ) :
smodel = self . get_config_sound_model ( )
try :
2010-05-05 16:06:46 -04:00
self . _dev = virtinst . VirtualAudio ( conn = self . conn . vmm ,
model = smodel )
2009-11-24 12:43:54 -05:00
except Exception , e :
2011-08-30 14:50:50 -04:00
return self . err . val_err ( _ ( " Sound device parameter error " ) , e )
2009-07-14 09:25:39 -04:00
2009-11-24 12:43:54 -05:00
def validate_page_hostdev ( self ) :
2010-12-11 15:12:22 -05:00
ret = self . get_config_host_device_info ( )
nodedev_name = ret and ret [ 1 ] or None
2009-07-14 09:25:39 -04:00
2012-11-08 14:15:02 +01:00
if nodedev_name is None :
2010-04-05 12:21:03 -04:00
return self . err . val_err ( _ ( " Physical Device Required " ) ,
2009-11-24 12:43:54 -05:00
_ ( " A device must be selected. " ) )
2007-04-12 15:36:04 -04:00
2009-11-24 12:43:54 -05:00
try :
self . _dev = virtinst . VirtualHostDevice . device_from_node (
2011-04-11 18:35:21 -04:00
conn = self . conn . vmm ,
2010-12-10 11:47:07 -05:00
name = nodedev_name )
2009-11-24 12:43:54 -05:00
except Exception , e :
2011-08-30 14:50:50 -04:00
return self . err . val_err ( _ ( " Host device parameter error " ) , e )
2007-04-12 15:36:04 -04:00
2009-11-24 12:43:54 -05:00
def validate_page_char ( self ) :
chartype = self . get_char_type ( )
2011-08-30 21:03:27 +02:00
modebox = self . widget ( " char-mode " )
2011-07-14 13:13:13 -04:00
devbox = self . widget ( " char-device-type " )
2009-11-24 12:43:54 -05:00
devtype = devbox . get_model ( ) [ devbox . get_active ( ) ] [ 0 ]
2011-04-11 18:35:21 -04:00
conn = self . conn . vmm
2007-04-12 15:36:04 -04:00
2009-11-24 12:43:54 -05:00
devclass = VirtualCharDevice . get_dev_instance ( conn , chartype , devtype )
2009-01-22 17:00:10 -05:00
2011-07-14 13:13:13 -04:00
source_path = self . widget ( " char-path " ) . get_text ( )
2011-08-30 21:03:27 +02:00
source_mode = modebox . get_model ( ) [ modebox . get_active ( ) ] [ 0 ]
2011-07-14 13:13:13 -04:00
source_host = self . widget ( " char-host " ) . get_text ( )
bind_host = self . widget ( " char-bind-host " ) . get_text ( )
source_port = self . widget ( " char-port " ) . get_adjustment ( ) . value
bind_port = self . widget ( " char-bind-port " ) . get_adjustment ( ) . value
target_name = self . widget ( " char-target-name " ) . get_text ( )
2009-01-22 17:00:10 -05:00
2011-07-14 13:13:13 -04:00
if self . widget ( " char-use-telnet " ) . get_active ( ) :
2009-11-24 12:43:54 -05:00
protocol = VirtualCharDevice . CHAR_PROTOCOL_TELNET
else :
protocol = VirtualCharDevice . CHAR_PROTOCOL_RAW
value_mappings = {
" source_path " : source_path ,
2011-08-30 21:03:27 +02:00
" source_mode " : source_mode ,
2009-11-24 12:43:54 -05:00
" source_host " : source_host ,
" source_port " : source_port ,
" bind_port " : bind_port ,
" bind_host " : bind_host ,
" protocol " : protocol ,
2011-04-05 01:35:31 +02:00
" target_name " : target_name ,
2009-11-24 12:43:54 -05:00
}
2009-01-22 17:00:10 -05:00
2009-11-24 12:43:54 -05:00
try :
self . _dev = devclass
2009-07-20 15:09:32 -04:00
2009-11-24 12:43:54 -05:00
for param_name , val in value_mappings . items ( ) :
2010-09-02 18:37:20 -04:00
if self . _dev . supports_property ( param_name ) :
2009-11-24 12:43:54 -05:00
setattr ( self . _dev , param_name , val )
2007-07-14 13:48:24 -04:00
2009-11-24 12:43:54 -05:00
# Dump XML for sanity checking
self . _dev . get_xml_config ( )
except Exception , e :
2010-03-24 00:22:17 -04:00
return self . err . val_err ( _ ( " %s device parameter error " ) %
2011-08-30 14:50:50 -04:00
chartype . capitalize ( ) , e )
2007-09-25 20:05:45 -04:00
2009-11-24 12:43:54 -05:00
def validate_page_video ( self ) :
2011-04-11 18:35:21 -04:00
conn = self . conn . vmm
2009-11-24 12:43:54 -05:00
model = self . get_config_video_model ( )
2007-09-26 19:39:11 -04:00
2009-11-24 12:43:54 -05:00
try :
self . _dev = VirtualVideoDevice ( conn = conn )
self . _dev . model_type = model
except Exception , e :
2011-08-30 14:50:50 -04:00
return self . err . val_err ( _ ( " Video device parameter error " ) , e )
2010-03-24 00:22:17 -04:00
def validate_page_watchdog ( self ) :
2011-04-11 18:35:21 -04:00
conn = self . conn . vmm
2010-03-24 00:22:17 -04:00
model = self . get_config_watchdog_model ( )
action = self . get_config_watchdog_action ( )
try :
self . _dev = VirtualWatchdog ( conn = conn )
self . _dev . model = model
self . _dev . action = action
except Exception , e :
2011-08-30 14:50:50 -04:00
return self . err . val_err ( _ ( " Watchdog parameter error " ) , e )
2009-01-22 17:00:26 -05:00
2011-05-19 18:17:58 -04:00
def validate_page_filesystem ( self ) :
conn = self . conn . vmm
2011-07-14 13:13:13 -04:00
source = self . widget ( " fs-source " ) . get_text ( )
target = self . widget ( " fs-target " ) . get_text ( )
2011-05-19 18:17:58 -04:00
mode = self . get_config_fs_mode ( )
fstype = self . get_config_fs_type ( )
2011-12-22 23:40:17 +05:30
readonly = self . get_config_fs_readonly ( )
2012-01-12 20:28:26 -05:00
driver = self . get_config_fs_driver ( )
2012-01-19 00:22:02 +05:30
wrpolicy = self . get_config_fs_wrpolicy ( )
2011-05-19 18:17:58 -04:00
if not source :
return self . err . val_err ( _ ( " A filesystem source must be specified " ) )
if not target :
return self . err . val_err ( _ ( " A filesystem target must be specified " ) )
2011-12-21 11:28:54 +05:30
if self . conn . is_qemu ( ) and self . filesystem_target_present ( target ) :
return self . err . val_err ( _ ( ' Invalid target path. A filesystem with '
' that target already exists ' ) )
2011-05-19 18:17:58 -04:00
try :
self . _dev = virtinst . VirtualFilesystem ( conn = conn )
self . _dev . source = source
self . _dev . target = target
if mode :
self . _dev . mode = mode
if fstype :
self . _dev . type = fstype
2011-12-22 23:40:17 +05:30
if readonly :
self . _dev . readonly = readonly
2012-01-12 20:28:26 -05:00
if driver :
self . _dev . driver = driver
2012-01-19 00:22:02 +05:30
if wrpolicy :
self . _dev . wrpolicy = wrpolicy
2011-05-19 18:17:58 -04:00
except Exception , e :
2011-08-30 14:50:50 -04:00
return self . err . val_err ( _ ( " Filesystem parameter error " ) , e )
2009-03-09 16:20:23 -04:00
2011-12-21 11:28:54 +05:30
def filesystem_target_present ( self , target ) :
fsdevs = self . vm . get_filesystem_devices ( )
for fs in fsdevs :
if ( fs . target == target ) :
return True
return False
2011-06-23 17:42:03 +02:00
def validate_page_smartcard ( self ) :
conn = self . conn . vmm
mode = self . get_config_smartcard_mode ( )
try :
self . _dev = VirtualSmartCardDevice ( conn , mode )
except Exception , e :
2011-09-02 03:23:28 +02:00
return self . err . val_err ( _ ( " Smartcard device parameter error " ) , e )
def validate_page_usbredir ( self ) :
conn = self . conn . vmm
stype = self . get_config_usbredir_type ( )
host = self . get_config_usbredir_host ( )
service = self . get_config_usbredir_service ( )
try :
self . _dev = VirtualRedirDevice ( conn = conn , bus = " usb " , stype = stype )
if host :
self . _dev . host = host
if service :
self . _dev . service = service
except Exception , e :
return self . err . val_err ( _ ( " USB redirected device parameter error " ) ,
str ( e ) )
2011-06-23 17:42:03 +02:00
2009-03-09 16:20:23 -04:00
2009-11-24 12:43:54 -05:00
####################
# Unsorted helpers #
####################
2009-03-09 16:20:23 -04:00
2011-06-08 18:38:03 -04:00
def _browse_file ( self , textent , isdir = False ) :
2009-11-24 12:43:54 -05:00
def set_storage_cb ( src , path ) :
if path :
textent . set_text ( path )
2009-03-09 16:20:23 -04:00
2011-04-11 18:35:21 -04:00
conn = self . conn
2011-06-08 18:38:03 -04:00
reason = ( isdir and
self . config . CONFIG_DIR_FS or
self . config . CONFIG_DIR_IMAGE )
2012-11-08 14:15:02 +01:00
if self . storage_browser is None :
2010-12-08 17:26:19 -05:00
self . storage_browser = vmmStorageBrowser ( conn )
2009-03-09 16:20:23 -04:00
2011-07-22 13:13:26 -04:00
rhel6 = self . vm . rhel6_defaults ( )
self . storage_browser . rhel6_defaults = rhel6
2011-07-22 12:22:09 -04:00
2009-11-24 12:43:54 -05:00
self . storage_browser . set_finish_cb ( set_storage_cb )
2011-06-08 18:38:03 -04:00
self . storage_browser . set_browse_reason ( reason )
2009-11-24 12:43:54 -05:00
2011-04-14 08:47:42 -04:00
self . storage_browser . show ( self . topwin , conn )