2007-04-12 23:36:04 +04:00
#
2015-03-26 16:44:24 +03:00
# Copyright (C) 2006-2007, 2012-2015 Red Hat, Inc.
2007-04-12 23:36:04 +04:00
# 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 19:12:20 +03:00
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
2007-04-12 23:36:04 +04:00
#
2009-07-14 17:25:39 +04:00
import logging
import traceback
2014-02-12 18:58:40 +04:00
import collections
2009-07-14 17:25:39 +04:00
2012-05-14 17:24:56 +04:00
from gi . repository import Gtk
from gi . repository import Gdk
2009-07-14 17:25:39 +04:00
2007-04-12 23:36:04 +04:00
import virtinst
2013-07-16 17:14:37 +04:00
from virtinst import ( VirtualChannelDevice , VirtualParallelDevice ,
2013-10-05 19:28:41 +04:00
VirtualSerialDevice , VirtualConsoleDevice ,
2011-06-23 19:42:03 +04:00
VirtualVideoDevice , VirtualWatchdog ,
2014-01-21 13:05:30 +04:00
VirtualSmartCardDevice , VirtualRedirDevice ,
VirtualTPMDevice , VirtualPanicDevice )
2013-07-16 05:52:18 +04:00
from virtinst import VirtualController
2007-04-12 23:36:04 +04:00
2014-09-13 00:10:45 +04:00
from . import uiutil
from . fsdetails import vmmFSDetails
from . gfxdetails import vmmGraphicsDetails
from . netlist import vmmNetworkList
from . asyncjob import vmmAsyncJob
from . storagebrowse import vmmStorageBrowser
from . baseclass import vmmGObjectUI
from . addstorage import vmmAddStorage
2007-04-12 23:36:04 +04:00
2014-04-16 19:39:06 +04:00
( PAGE_ERROR ,
PAGE_DISK ,
2014-04-26 18:40:17 +04:00
PAGE_CONTROLLER ,
2014-04-16 19:39:06 +04:00
PAGE_NETWORK ,
PAGE_INPUT ,
PAGE_GRAPHICS ,
PAGE_SOUND ,
PAGE_HOSTDEV ,
PAGE_CHAR ,
PAGE_VIDEO ,
PAGE_WATCHDOG ,
PAGE_FILESYSTEM ,
PAGE_SMARTCARD ,
PAGE_USBREDIR ,
PAGE_TPM ,
PAGE_RNG ,
PAGE_PANIC ,
2014-04-26 18:40:17 +04:00
) = range ( 0 , 17 )
2009-07-14 17:25:39 +04:00
2013-06-26 05:45:09 +04:00
2010-12-09 01:26:19 +03:00
class vmmAddHardware ( vmmGObjectUI ) :
2013-07-25 22:11:09 +04:00
def __init__ ( self , vm , is_customize_dialog ) :
2013-09-23 00:10:16 +04:00
vmmGObjectUI . __init__ ( self , " addhardware.ui " , " vmm-add-hardware " )
2010-12-09 01:26:19 +03:00
2007-04-12 23:36:04 +04:00
self . vm = vm
2011-07-23 00:43:26 +04:00
self . conn = vm . conn
2013-07-25 22:11:09 +04:00
self . is_customize_dialog = is_customize_dialog
2008-11-19 01:01:22 +03:00
2015-05-19 22:18:30 +03:00
self . _storagebrowser = None
2009-03-09 23:19:39 +03:00
2009-07-14 17:25:39 +04:00
self . _dev = None
2014-06-16 07:48:22 +04:00
self . _remove_usb_controller = None
self . _selected_model = None
2009-07-14 17:25:39 +04:00
2015-05-19 22:18:30 +03:00
self . _gfxdetails = vmmGraphicsDetails (
2014-01-29 03:44:40 +04:00
self . vm , self . builder , self . topwin )
2015-05-19 22:18:30 +03:00
self . widget ( " graphics-align " ) . add ( self . _gfxdetails . top_box )
2014-01-29 03:44:40 +04:00
2015-05-19 22:18:30 +03:00
self . _fsdetails = vmmFSDetails ( self . vm , self . builder , self . topwin )
self . widget ( " fs-box " ) . add ( self . _fsdetails . top_box )
2014-01-29 01:53:11 +04:00
2015-05-19 22:18:30 +03:00
self . _netlist = vmmNetworkList ( self . conn , self . builder , self . topwin )
self . widget ( " network-source-label-align " ) . add ( self . _netlist . top_label )
self . widget ( " network-source-ui-align " ) . add ( self . _netlist . top_box )
self . widget ( " network-vport-align " ) . add ( self . _netlist . top_vport )
2014-01-27 20:03:59 +04:00
2014-01-29 01:53:11 +04:00
self . addstorage = vmmAddStorage ( self . conn , self . builder , self . topwin )
2015-09-14 01:01:39 +03:00
self . widget ( " storage-align " ) . add ( self . addstorage . top_box )
2014-01-29 01:53:11 +04:00
self . addstorage . connect ( " browse-clicked " , self . _browse_storage_cb )
2013-02-16 22:31:46 +04:00
self . builder . connect_signals ( {
2007-04-12 23:36:04 +04:00
" on_create_cancel_clicked " : self . close ,
" on_vmm_create_delete_event " : self . close ,
2015-05-19 22:18:30 +03:00
" on_create_finish_clicked " : self . _finish ,
" on_hw_list_changed " : self . _hw_selected ,
2009-11-24 21:14:55 +03:00
2015-09-14 01:01:39 +03:00
" on_storage_devtype_changed " : self . _change_storage_devtype ,
2009-11-24 21:14:55 +03:00
2015-05-19 22:18:30 +03:00
" on_mac_address_clicked " : self . _change_macaddr_use ,
2009-11-24 21:14:55 +03:00
2015-05-19 22:18:30 +03:00
" on_char_device_type_changed " : self . _change_char_device_type ,
" on_char_target_name_changed " : self . _change_char_target_name ,
" on_char_auto_socket_toggled " : self . _change_char_auto_socket ,
2009-07-14 17:25:39 +04:00
2015-05-19 22:18:30 +03:00
" on_tpm_device_type_changed " : self . _change_tpm_device_type ,
2013-06-26 05:45:09 +04:00
2015-05-19 22:18:30 +03:00
" on_usbredir_type_changed " : self . _change_usbredir_type ,
2013-09-23 17:39:57 +04:00
2015-05-19 22:18:30 +03:00
" on_rng_type_changed " : self . _change_rng ,
" on_rng_backend_mode_changed " : self . _change_rng ,
" on_rng_backend_type_changed " : self . _change_rng ,
2014-04-26 18:41:31 +04:00
2015-05-19 22:18:30 +03:00
" on_controller_type_changed " : self . _populate_controller_model ,
2012-11-08 17:15:02 +04:00
} )
2011-04-18 19:25:28 +04:00
self . bind_escape_key_close ( )
2007-04-12 23:36:04 +04:00
2015-05-19 22:18:30 +03:00
self . _set_initial_state ( )
2013-09-22 20:18:49 +04:00
2011-04-14 16:47:42 +04:00
def show ( self , parent ) :
2012-02-01 03:16:54 +04:00
logging . debug ( " Showing addhw " )
2015-05-19 22:18:30 +03:00
self . _reset_state ( )
2011-04-14 16:47:42 +04:00
self . topwin . set_transient_for ( parent )
2007-04-12 23:36:04 +04:00
self . topwin . present ( )
2013-07-07 19:06:15 +04:00
self . conn . schedule_priority_tick ( pollnet = True ,
pollpool = True , polliface = True ,
2015-04-07 20:56:48 +03:00
pollnodedev = True )
2007-04-12 23:36:04 +04:00
2010-11-29 22:06:43 +03:00
def close ( self , ignore1 = None , ignore2 = None ) :
2015-05-03 23:56:45 +03:00
if self . topwin . is_visible ( ) :
logging . debug ( " Closing addhw " )
self . topwin . hide ( )
2015-05-19 22:18:30 +03:00
if self . _storagebrowser :
self . _storagebrowser . close ( )
2011-04-12 02:35:21 +04:00
2009-11-24 20:43:54 +03:00
return 1
2011-07-24 05:16:54 +04:00
def _cleanup ( self ) :
self . vm = None
self . conn = None
self . _dev = None
2011-04-12 02:35:21 +04:00
2015-05-19 22:18:30 +03:00
if self . _storagebrowser :
self . _storagebrowser . cleanup ( )
self . _storagebrowser = None
2011-04-12 02:35:21 +04:00
2015-05-19 22:18:30 +03:00
self . _gfxdetails . cleanup ( )
self . _gfxdetails = None
self . _fsdetails . cleanup ( )
self . _fsdetails = None
self . _netlist . cleanup ( )
self . _netlist = None
2014-01-29 01:53:11 +04:00
self . addstorage . cleanup ( )
self . addstorage = None
2014-01-21 13:05:30 +04:00
2009-11-24 20:43:54 +03:00
def is_visible ( self ) :
2012-05-14 17:24:56 +04:00
return self . topwin . get_visible ( )
2009-11-24 20:43:54 +03:00
##########################
# Initialization methods #
##########################
2015-05-19 22:18:30 +03:00
def _set_initial_state ( self ) :
2011-07-14 21:13:13 +04:00
notebook = self . widget ( " create-pages " )
2007-04-12 23:36:04 +04:00
notebook . set_show_tabs ( False )
2013-09-27 19:18:52 +04:00
blue = Gdk . color_parse ( " #0072A8 " )
self . widget ( " page-title-box " ) . modify_bg ( Gtk . StateType . NORMAL , blue )
2007-04-12 23:36:04 +04:00
2010-12-11 23:55:31 +03:00
# Name, icon name, page number, is sensitive, tooltip, icon size,
# device type (serial/parallel)...
2012-05-14 17:24:56 +04:00
model = Gtk . ListStore ( str , str , int , bool , str , str )
2013-09-23 00:29:58 +04:00
hw_list = self . widget ( " hw-list " )
2009-07-09 02:49:25 +04:00
hw_list . set_model ( model )
2010-12-11 20:32:04 +03:00
2016-02-05 18:18:16 +03:00
hw_col = Gtk . TreeViewColumn ( _ ( " Hardware " ) )
2010-12-11 20:32:04 +03:00
hw_col . set_spacing ( 6 )
hw_col . set_min_width ( 165 )
2012-05-14 17:24:56 +04:00
icon = Gtk . CellRendererPixbuf ( )
icon . set_property ( " stock-size " , Gtk . IconSize . BUTTON )
text = Gtk . CellRendererText ( )
2009-07-20 23:09:32 +04:00
text . set_property ( " xpad " , 6 )
2010-12-11 20:32:04 +03: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-09 02:49:25 +04:00
# Network model list
2014-01-28 01:58:45 +04:00
netmodel_list = self . widget ( " net-model " )
2014-01-27 02:09:07 +04:00
self . build_network_model_combo ( self . vm , netmodel_list )
2009-01-23 01:00:10 +03:00
2014-01-13 01:52:26 +04:00
# Disk bus type
2015-04-08 02:31:30 +03:00
self . build_disk_bus_combo ( self . vm ,
2015-09-14 01:01:39 +03:00
self . widget ( " storage-bustype " ) )
2014-01-13 01:52:26 +04:00
# Disk device type
2015-09-14 01:01:39 +03:00
target_list = self . widget ( " storage-devtype " )
2014-01-13 01:52:26 +04:00
# [device, icon, label]
target_model = Gtk . ListStore ( str , str , str )
2007-07-14 21:48:24 +04:00
target_list . set_model ( target_model )
2012-05-14 17:24:56 +04:00
icon = Gtk . CellRendererPixbuf ( )
icon . set_property ( " stock-size " , Gtk . IconSize . BUTTON )
2007-07-14 21:48:24 +04:00
target_list . pack_start ( icon , False )
2014-01-13 01:52:26 +04:00
target_list . add_attribute ( icon , ' icon-name ' , 1 )
2012-05-14 17:24:56 +04:00
text = Gtk . CellRendererText ( )
2009-07-20 23:09:32 +04:00
text . set_property ( " xpad " , 6 )
2007-07-14 21:48:24 +04:00
target_list . pack_start ( text , True )
2014-01-13 01:52:26 +04:00
target_list . add_attribute ( text , ' text ' , 2 )
2015-04-08 02:31:30 +03:00
target_model . append ( [ virtinst . VirtualDisk . DEVICE_DISK ,
" drive-harddisk " , _ ( " Disk device " ) ] )
target_model . append ( [ virtinst . VirtualDisk . DEVICE_CDROM ,
" media-cdrom " , _ ( " CDROM device " ) ] )
target_model . append ( [ virtinst . VirtualDisk . DEVICE_FLOPPY ,
" media-floppy " , _ ( " Floppy device " ) ] )
if self . conn . is_qemu ( ) or self . conn . is_test_conn ( ) :
target_model . append ( [ virtinst . VirtualDisk . DEVICE_LUN ,
" drive-harddisk " , _ ( " LUN Passthrough " ) ] )
target_list . set_active ( 0 )
2007-07-14 21:48:24 +04:00
2010-05-20 16:34:32 +04:00
# Disk cache mode
2015-09-14 01:01:39 +03:00
cache_list = self . widget ( " storage-cache " )
2014-01-27 02:09:07 +04:00
self . build_disk_cache_combo ( self . vm , cache_list )
2010-05-20 16:34:32 +04:00
2009-07-09 02:49:25 +04:00
# Input device type
2011-07-14 21:13:13 +04:00
input_list = self . widget ( " input-type " )
2012-05-14 17:24:56 +04:00
input_model = Gtk . ListStore ( str , str , str )
2007-09-26 04:05:45 +04:00
input_list . set_model ( input_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( input_list , 0 )
2007-09-26 04:05:45 +04:00
2009-07-09 02:49:25 +04:00
# Sound model list
2011-07-14 21:13:13 +04:00
sound_list = self . widget ( " sound-model " )
2014-01-27 02:09:07 +04:00
self . build_sound_combo ( self . vm , sound_list )
2009-01-23 01:00:26 +03:00
2010-12-12 00:09:30 +03:00
# Host device list
2011-07-14 21:13:13 +04:00
host_dev = self . widget ( " host-device " )
2015-08-10 21:18:43 +03:00
# [ prettyname, xmlobj ]
host_dev_model = Gtk . ListStore ( str , object )
2009-03-09 23:20:23 +03:00
host_dev . set_model ( host_dev_model )
2012-05-14 17:24:56 +04:00
host_col = Gtk . TreeViewColumn ( )
text = Gtk . CellRendererText ( )
2010-12-11 23:12:22 +03:00
host_col . pack_start ( text , True )
host_col . add_attribute ( text , ' text ' , 0 )
2012-05-14 17:24:56 +04:00
host_dev_model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
2010-12-11 23:12:22 +03:00
host_dev . append_column ( host_col )
2009-03-09 23:20:23 +03:00
2009-07-14 17:25:39 +04:00
# Video device
2011-07-14 21:13:13 +04:00
video_dev = self . widget ( " video-model " )
2014-01-27 02:09:07 +04:00
self . build_video_combo ( self . vm , video_dev )
2009-07-09 02:49:25 +04:00
2010-12-12 00:09:30 +03:00
# Character dev mode
2011-07-14 21:13:13 +04:00
char_mode = self . widget ( " char-mode " )
2009-07-14 17:25:39 +04:00
# Mode name, desc
2012-05-14 17:24:56 +04:00
char_mode_model = Gtk . ListStore ( str , str )
2009-07-14 17:25:39 +04:00
char_mode . set_model ( char_mode_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( char_mode , 1 )
2012-05-14 17:24:56 +04:00
char_mode_model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
2013-07-16 17:14:37 +04:00
for t in VirtualSerialDevice . MODES :
desc = VirtualSerialDevice . pretty_mode ( t )
2009-07-14 17:25:39 +04:00
char_mode_model . append ( [ t , desc + " ( %s ) " % t ] )
2013-10-05 19:28:41 +04:00
# Char target type
lst = self . widget ( " char-target-type " )
model = Gtk . ListStore ( str , str )
lst . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( lst , 1 )
2013-10-05 19:28:41 +04:00
if self . conn . is_qemu ( ) :
2016-04-30 09:24:42 +03:00
model . append ( [ " virtio " , " VirtIO " ] )
2013-10-05 19:28:41 +04:00
else :
2015-04-08 01:08:29 +03:00
model . append ( [ None , _ ( " Hypervisor default " ) ] )
2013-10-05 19:28:41 +04:00
2013-10-05 21:27:11 +04:00
# Char target name
lst = self . widget ( " char-target-name " )
model = Gtk . ListStore ( str )
lst . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( lst , 0 )
2013-10-05 21:27:11 +04:00
for n in VirtualChannelDevice . CHANNEL_NAMES :
model . append ( [ n ] )
# Char device type
lst = self . widget ( " char-device-type " )
model = Gtk . ListStore ( str , str )
lst . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( lst , 1 )
2013-10-05 21:27:11 +04:00
2010-03-24 07:22:17 +03:00
# Watchdog widgets
2011-07-14 21:13:13 +04:00
combo = self . widget ( " watchdog-model " )
2014-01-27 02:09:07 +04:00
self . build_watchdogmodel_combo ( self . vm , combo )
2011-07-14 21:13:13 +04:00
combo = self . widget ( " watchdog-action " )
2014-01-27 02:09:07 +04:00
self . build_watchdogaction_combo ( self . vm , combo )
2010-03-24 07:22:17 +03:00
2011-06-23 19:42:03 +04:00
# Smartcard widgets
2011-07-14 21:13:13 +04:00
combo = self . widget ( " smartcard-mode " )
2014-01-27 02:09:07 +04:00
self . build_smartcard_mode_combo ( self . vm , combo )
2011-06-23 19:42:03 +04:00
2011-09-02 05:23:28 +04:00
# Usbredir widgets
combo = self . widget ( " usbredir-list " )
2014-01-27 02:09:07 +04:00
self . build_redir_type_combo ( self . vm , combo )
2011-09-02 05:23:28 +04:00
2013-06-26 05:45:09 +04:00
# TPM widgets
combo = self . widget ( " tpm-type " )
2014-01-27 02:09:07 +04:00
self . build_tpm_type_combo ( self . vm , combo )
2013-06-26 05:45:09 +04:00
2013-09-23 17:39:57 +04:00
# RNG widgets
combo = self . widget ( " rng-type " )
2015-05-19 22:18:30 +03:00
self . _build_rng_type_combo ( combo )
2013-09-23 17:39:57 +04:00
combo = self . widget ( " rng-backend-type " )
2015-05-19 22:18:30 +03:00
self . _build_rng_backend_type_combo ( combo )
2013-09-23 17:39:57 +04:00
combo = self . widget ( " rng-backend-mode " )
2015-05-19 22:18:30 +03:00
self . _build_rng_backend_mode_combo ( combo )
2013-09-23 17:39:57 +04:00
2014-01-10 13:37:56 +04:00
# Panic widgets
combo = self . widget ( " panic-type " )
2015-05-19 22:18:30 +03:00
self . _build_panic_address_type ( combo )
2014-01-10 13:37:56 +04:00
2014-04-26 18:40:17 +04:00
# Controller widgets
combo = self . widget ( " controller-type " )
target_model = Gtk . ListStore ( str , str )
combo . set_model ( target_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 1 )
2014-04-26 18:40:17 +04:00
combo = self . widget ( " controller-model " )
target_model = Gtk . ListStore ( str , str )
combo . set_model ( target_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 1 )
2014-04-26 18:40:17 +04:00
2010-12-11 23:55:31 +03:00
# Available HW options
2010-03-04 23:35:34 +03:00
is_local = not self . conn . is_remote ( )
is_storage_capable = self . conn . is_storage_capable ( )
2010-12-11 23:55:31 +03:00
have_storage = ( is_local or is_storage_capable )
storage_tooltip = None
if not have_storage :
storage_tooltip = _ ( " Connection does not support storage "
" management. " )
2013-09-23 00:29:58 +04:00
hwlist = self . widget ( " hw-list " )
2010-12-11 23:55:31 +03: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 ] )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " Storage " ) , " drive-harddisk " , PAGE_DISK , have_storage ,
2010-12-11 23:55:31 +03:00
have_storage and storage_tooltip or None )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " Controller " ) , " device_pci " , PAGE_CONTROLLER , True , None )
add_hw_option ( _ ( " Network " ) , " network-idle " , PAGE_NETWORK , True , None )
add_hw_option ( _ ( " Input " ) , " input-mouse " , PAGE_INPUT , self . vm . is_hvm ( ) ,
2010-12-11 23:55:31 +03:00
_ ( " Not supported for this guest type. " ) )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " Graphics " ) , " video-display " , PAGE_GRAPHICS ,
2010-12-11 23:55:31 +03:00
True , None )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " Sound " ) , " audio-card " , PAGE_SOUND ,
2010-12-11 23:55:31 +03:00
self . vm . is_hvm ( ) ,
_ ( " Not supported for this guest type. " ) )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " Serial " ) , Gtk . STOCK_CONNECT , PAGE_CHAR ,
2010-12-11 23:55:31 +03:00
self . vm . is_hvm ( ) ,
_ ( " Not supported for this guest type. " ) ,
" serial " )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " Parallel " ) , Gtk . STOCK_CONNECT , PAGE_CHAR ,
2010-12-11 23:55:31 +03:00
self . vm . is_hvm ( ) ,
_ ( " Not supported for this guest type. " ) ,
" parallel " )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " Console " ) , Gtk . STOCK_CONNECT , PAGE_CHAR ,
2013-10-05 19:28:41 +04:00
True , None , " console " )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " Channel " ) , Gtk . STOCK_CONNECT , PAGE_CHAR ,
2011-04-05 03:35:32 +04:00
self . vm . is_hvm ( ) ,
_ ( " Not supported for this guest type. " ) ,
" channel " )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " USB Host Device " ) , " system-run " , PAGE_HOSTDEV ,
2011-04-12 02:35:21 +04:00
self . conn . is_nodedev_capable ( ) ,
2010-12-11 23:55:31 +03:00
_ ( " Connection does not support host device enumeration " ) ,
" usb " )
2015-12-23 15:01:29 +03:00
nodedev_enabled = self . conn . is_nodedev_capable ( )
nodedev_errstr = _ ( " Connection does not support "
" host device enumeration " )
if self . vm . is_container ( ) :
nodedev_enabled = False
nodedev_errstr = _ ( " Not supported for containers " )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " PCI Host Device " ) , " system-run " , PAGE_HOSTDEV ,
2015-12-23 15:01:29 +03:00
nodedev_enabled , nodedev_errstr , " pci " )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " Video " ) , " video-display " , PAGE_VIDEO , True ,
2010-12-11 23:55:31 +03:00
_ ( " Libvirt version does not support video devices. " ) )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " Watchdog " ) , " device_pci " , PAGE_WATCHDOG ,
2010-12-11 23:55:31 +03:00
self . vm . is_hvm ( ) ,
_ ( " Not supported for this guest type. " ) )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " Filesystem " ) , " folder " , PAGE_FILESYSTEM ,
2013-10-06 18:08:04 +04:00
self . conn . check_support (
2014-03-19 16:52:10 +04:00
self . conn . SUPPORT_CONN_FILESYSTEM ) and
not self . vm . stable_defaults ( ) ,
2011-05-20 02:17:58 +04:00
_ ( " Not supported for this hypervisor/libvirt "
" combination. " ) )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " Smartcard " ) , " device_serial " , PAGE_SMARTCARD ,
2011-06-23 19:42:03 +04:00
True , None )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " USB Redirection " ) , " device_usb " , PAGE_USBREDIR ,
2011-09-02 05:23:28 +04:00
True , None )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " TPM " ) , " device_cpu " , PAGE_TPM ,
2013-06-26 05:45:09 +04:00
True , None )
2016-02-05 18:18:16 +03:00
add_hw_option ( _ ( " RNG " ) , " system-run " , PAGE_RNG , True , None )
add_hw_option ( _ ( " Panic Notifier " ) , " system-run " , PAGE_PANIC ,
2014-01-13 00:16:06 +04:00
self . conn . check_support ( self . conn . SUPPORT_CONN_PANIC_DEVICE ) ,
_ ( " Not supported for this hypervisor/libvirt combination. " ) )
2010-12-11 23:55:31 +03:00
2015-05-19 22:18:30 +03:00
def _reset_state ( self ) :
2009-07-09 02:49:25 +04:00
# Storage init
2015-09-14 01:01:39 +03:00
self . widget ( " storage-devtype " ) . set_active ( 0 )
self . widget ( " storage-devtype " ) . emit ( " changed " )
2014-01-29 01:53:11 +04:00
self . addstorage . reset_state ( )
2007-04-12 23:36:04 +04:00
2009-07-09 02:49:25 +04:00
# Network init
2013-07-15 22:14:05 +04:00
newmac = virtinst . VirtualNetworkInterface . generate_mac (
self . conn . get_backend ( ) )
2011-07-14 21:13:13 +04:00
self . widget ( " mac-address " ) . set_active ( bool ( newmac ) )
self . widget ( " create-mac-address " ) . set_text ( newmac )
2015-05-19 22:18:30 +03:00
self . _change_macaddr_use ( )
2009-11-24 21:14:55 +03:00
2015-05-19 22:18:30 +03:00
self . _netlist . reset_state ( )
2009-11-30 20:51:25 +03:00
2011-07-14 21:13:13 +04:00
netmodel = self . widget ( " net-model " )
2014-01-27 02:09:07 +04:00
self . populate_network_model_combo ( self . vm , netmodel )
2010-03-24 05:15:53 +03:00
netmodel . set_active ( 0 )
2009-01-23 01:00:10 +03:00
2009-07-09 02:49:25 +04:00
# Input device init
2011-07-14 21:13:13 +04:00
input_box = self . widget ( " input-type " )
2015-05-19 22:18:30 +03:00
self . _populate_input_model ( input_box . get_model ( ) )
2007-09-26 04:05:45 +04:00
input_box . set_active ( 0 )
2009-07-09 02:49:25 +04:00
# Graphics init
2015-05-19 22:18:30 +03:00
self . _gfxdetails . reset_state ( )
2007-09-27 03:39:11 +04:00
2009-07-09 02:49:25 +04:00
# Sound init
2011-07-14 21:13:13 +04:00
sound_box = self . widget ( " sound-model " )
2009-01-23 01:00:26 +03:00
sound_box . set_active ( 0 )
2010-12-10 19:47:07 +03:00
2009-07-14 17:25:39 +04:00
# Char parameters
2011-07-14 21:13:13 +04:00
self . widget ( " char-device-type " ) . set_active ( 0 )
2013-10-05 19:28:41 +04:00
self . widget ( " char-target-type " ) . set_active ( 0 )
2013-10-05 21:27:11 +04:00
self . widget ( " char-target-name " ) . set_active ( 0 )
2011-07-14 21:13:13 +04:00
self . widget ( " char-path " ) . set_text ( " " )
2014-03-25 18:42:34 +04:00
self . widget ( " char-channel " ) . set_text ( " " )
2011-07-14 21:13:13 +04:00
self . widget ( " char-host " ) . set_text ( " 127.0.0.1 " )
2013-04-17 02:37:00 +04:00
self . widget ( " char-port " ) . set_value ( 4555 )
2011-07-14 21:13:13 +04:00
self . widget ( " char-bind-host " ) . set_text ( " 127.0.0.1 " )
2013-04-17 02:37:00 +04:00
self . widget ( " char-bind-port " ) . set_value ( 4556 )
2011-07-14 21:13:13 +04:00
self . widget ( " char-use-telnet " ) . set_active ( False )
2013-10-05 21:54:28 +04:00
self . widget ( " char-auto-socket " ) . set_active ( True )
2009-07-14 17:25:39 +04:00
2011-05-20 02:17:58 +04:00
# FS params
2015-05-19 22:18:30 +03:00
self . _fsdetails . reset_state ( )
2011-05-20 02:17:58 +04:00
2014-02-23 09:29:08 +04:00
# TPM params
2013-07-15 20:18:23 +04:00
self . widget ( " tpm-device-path " ) . set_text ( " /dev/tpm0 " )
2010-12-11 22:51:08 +03:00
# Hide all notebook pages, so the wizard isn't as big as the largest
# page
2011-07-14 21:13:13 +04:00
notebook = self . widget ( " create-pages " )
2010-12-11 22:51:08 +03:00
for page in range ( notebook . get_n_pages ( ) ) :
widget = notebook . get_nth_page ( page )
widget . hide ( )
2013-09-23 17:39:57 +04:00
# RNG params
self . widget ( " rng-device " ) . set_text ( " /dev/random " )
2013-10-25 19:13:28 +04:00
for i in [ " rng-bind-host " , " rng-connect-host " ] :
self . widget ( i ) . set_text ( " localhost " )
for i in [ " rng-bind-service " , " rng-connect-service " ] :
self . widget ( i ) . set_text ( " 708 " )
2013-09-23 17:39:57 +04:00
2014-01-10 13:37:56 +04:00
# Panic device params
self . widget ( " panic-iobase " ) . set_text ( " 0x505 " )
2014-04-26 18:40:17 +04:00
# Controller device params
2015-05-19 22:18:30 +03:00
self . _populate_controller_type ( )
2014-04-26 18:40:17 +04:00
2015-05-19 22:18:30 +03:00
self . _set_hw_selection ( 0 )
2009-01-23 01:00:26 +03:00
2014-01-13 01:52:26 +04:00
2014-01-27 02:09:07 +04:00
#####################
# Shared UI helpers #
#####################
@staticmethod
2016-05-20 18:51:02 +03:00
def build_video_combo ( vm , combo ) :
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
uiutil . init_combo_text_column ( combo , 1 )
combo . get_model ( ) . set_sort_column_id ( 1 , Gtk . SortType . ASCENDING )
2014-01-27 02:09:07 +04:00
tmpdev = virtinst . VirtualVideoDevice ( vm . conn . get_backend ( ) )
for m in tmpdev . MODELS :
model . append ( [ m , tmpdev . pretty_model ( m ) ] )
if len ( model ) > 0 :
combo . set_active ( 0 )
@staticmethod
2015-05-19 23:44:08 +03:00
def build_sound_combo ( vm , combo ) :
2014-01-27 02:09:07 +04:00
model = Gtk . ListStore ( str )
combo . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 0 )
2014-01-27 02:09:07 +04:00
model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
stable_defaults = vm . stable_defaults ( )
2014-09-15 14:42:22 +04:00
stable_soundmodels = [ " ich6 " , " ich9 " , " ac97 " ]
2014-01-27 02:09:07 +04:00
for m in virtinst . VirtualAudio . MODELS :
if ( stable_defaults and m not in stable_soundmodels ) :
continue
model . append ( [ m ] )
if len ( model ) > 0 :
combo . set_active ( 0 )
@staticmethod
2015-05-19 23:44:08 +03:00
def build_watchdogmodel_combo ( vm , combo ) :
2014-01-27 02:09:07 +04:00
ignore = vm
model = Gtk . ListStore ( str )
combo . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 0 )
2014-01-27 02:09:07 +04:00
for m in virtinst . VirtualWatchdog . MODELS :
model . append ( [ m ] )
if len ( model ) > 0 :
combo . set_active ( 0 )
@staticmethod
2015-05-19 23:44:08 +03:00
def build_watchdogaction_combo ( vm , combo ) :
2014-01-27 02:09:07 +04:00
ignore = vm
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 1 )
2014-01-27 02:09:07 +04:00
for m in virtinst . VirtualWatchdog . ACTIONS :
model . append ( [ m , virtinst . VirtualWatchdog . get_action_desc ( m ) ] )
if len ( model ) > 0 :
combo . set_active ( 0 )
@staticmethod
def populate_network_model_combo ( vm , combo ) :
model = combo . get_model ( )
model . clear ( )
# [xml value, label]
model . append ( [ None , _ ( " Hypervisor default " ) ] )
if vm . is_hvm ( ) :
2015-04-08 02:31:30 +03:00
mod_list = [ ]
2017-03-13 15:01:53 +03:00
if vm . get_hv_type ( ) in [ " kvm " , " qemu " , " vz " , " test " ] :
2014-01-27 02:09:07 +04:00
mod_list . append ( " virtio " )
2015-04-08 02:31:30 +03:00
mod_list . append ( " rtl8139 " )
mod_list . append ( " e1000 " )
2015-04-08 16:30:09 +03:00
if vm . xmlobj . os . is_pseries ( ) :
2014-01-27 02:09:07 +04:00
mod_list . append ( " spapr-vlan " )
if vm . get_hv_type ( ) in [ " xen " , " test " ] :
mod_list . append ( " netfront " )
mod_list . sort ( )
for m in mod_list :
model . append ( [ m , m ] )
@staticmethod
def build_network_model_combo ( vm , combo ) :
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 1 )
2014-01-27 02:09:07 +04:00
model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
vmmAddHardware . populate_network_model_combo ( vm , combo )
combo . set_active ( 0 )
@staticmethod
def populate_smartcard_mode_combo ( vm , combo ) :
ignore = vm
model = combo . get_model ( )
model . clear ( )
# [xml value, label]
2016-02-05 18:18:16 +03:00
model . append ( [ " passthrough " , _ ( " Passthrough " ) ] )
model . append ( [ " host " , _ ( " Host " ) ] )
2014-01-27 02:09:07 +04:00
@staticmethod
def build_smartcard_mode_combo ( vm , combo ) :
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 1 )
2014-01-27 02:09:07 +04:00
model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
vmmAddHardware . populate_smartcard_mode_combo ( vm , combo )
idx = - 1
for rowid in range ( len ( combo . get_model ( ) ) ) :
idx = 0
row = combo . get_model ( ) [ rowid ]
if row [ 0 ] == virtinst . VirtualSmartCardDevice . MODE_DEFAULT :
idx = rowid
break
combo . set_active ( idx )
@staticmethod
def populate_redir_type_combo ( vm , combo ) :
ignore = vm
model = combo . get_model ( )
model . clear ( )
# [xml value, label, conn details]
2016-02-05 18:18:16 +03:00
model . append ( [ " spicevmc " , _ ( " Spice channel " ) , False ] )
2014-01-27 02:09:07 +04:00
model . append ( [ " tcp " , " TCP " , True ] )
@staticmethod
def build_redir_type_combo ( vm , combo ) :
model = Gtk . ListStore ( str , str , bool )
combo . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 1 )
2014-01-27 02:09:07 +04:00
vmmAddHardware . populate_redir_type_combo ( vm , combo )
combo . set_active ( 0 )
@staticmethod
def populate_tpm_type_combo ( vm , combo ) :
ignore = vm
types = combo . get_model ( )
types . clear ( )
# [xml value, label]
for t in virtinst . VirtualTPMDevice . TYPES :
types . append ( [ t , virtinst . VirtualTPMDevice . get_pretty_type ( t ) ] )
@staticmethod
def build_tpm_type_combo ( vm , combo ) :
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 1 )
2014-01-27 02:09:07 +04:00
model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
vmmAddHardware . populate_tpm_type_combo ( vm , combo )
idx = - 1
for rowid in range ( len ( combo . get_model ( ) ) ) :
idx = 0
row = combo . get_model ( ) [ rowid ]
if row [ 0 ] == virtinst . VirtualTPMDevice . TYPE_DEFAULT :
idx = rowid
break
combo . set_active ( idx )
@staticmethod
def build_disk_cache_combo ( vm , combo ) :
ignore = vm
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 1 )
2014-01-27 02:09:07 +04:00
combo . set_active ( - 1 )
for m in virtinst . VirtualDisk . cache_types :
model . append ( [ m , m ] )
2015-04-08 01:08:29 +03:00
_iter = model . insert ( 0 , [ None , _ ( " Hypervisor default " ) ] )
2014-01-27 02:09:07 +04:00
combo . set_active_iter ( _iter )
@staticmethod
def build_disk_io_combo ( vm , combo , no_default = False ) :
ignore = vm
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 1 )
2014-01-27 02:09:07 +04:00
model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
combo . set_active ( - 1 )
for m in virtinst . VirtualDisk . io_modes :
model . append ( [ m , m ] )
if not no_default :
2015-04-08 01:08:29 +03:00
model . append ( [ None , _ ( " Hypervisor default " ) ] )
2014-01-27 02:09:07 +04:00
combo . set_active ( 0 )
@staticmethod
2015-04-08 02:31:30 +03:00
def build_disk_bus_combo ( vm , combo ) :
2014-01-27 02:09:07 +04:00
ignore = vm
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 1 )
2014-01-27 02:09:07 +04:00
model . set_sort_column_id ( 1 , Gtk . SortType . ASCENDING )
combo . set_active ( - 1 )
2015-04-08 02:31:30 +03:00
@staticmethod
2015-08-03 19:52:06 +03:00
def populate_disk_bus_combo ( vm , devtype , model ) :
2017-01-20 18:07:53 +03:00
# try to get supported disk bus types from domain capabilities
domcaps = vm . get_domain_capabilities ( )
disk_bus_types = None
if " bus " in domcaps . devices . disk . enum_names ( ) :
disk_bus_types = domcaps . devices . disk . get_enum ( " bus " ) . get_values ( )
# if there are no disk bus types in domain capabilities fallback to
# old code
if not disk_bus_types :
disk_bus_types = [ ]
if vm . is_hvm ( ) :
if not vm . get_xmlobj ( ) . os . is_q35 ( ) :
disk_bus_types . append ( " ide " )
disk_bus_types . append ( " sata " )
disk_bus_types . append ( " fdc " )
if not vm . stable_defaults ( ) :
disk_bus_types . append ( " scsi " )
disk_bus_types . append ( " usb " )
if vm . get_hv_type ( ) in [ " qemu " , " kvm " , " test " ] :
disk_bus_types . append ( " sd " )
disk_bus_types . append ( " virtio " )
if " scsi " not in disk_bus_types :
disk_bus_types . append ( " scsi " )
if vm . conn . is_xen ( ) or vm . conn . is_test_conn ( ) :
disk_bus_types . append ( " xen " )
2015-04-08 02:31:30 +03:00
rows = [ ]
2017-01-20 18:07:53 +03:00
for bus in disk_bus_types :
rows . append ( [ bus , virtinst . VirtualDisk . pretty_disk_bus ( bus ) ] )
2015-04-08 02:31:30 +03:00
model . clear ( )
bus_map = {
2015-08-03 19:52:07 +03:00
" disk " : [ " ide " , " sata " , " scsi " , " sd " , " usb " , " virtio " , " xen " ] ,
2015-04-08 02:31:30 +03:00
" floppy " : [ " fdc " ] ,
" cdrom " : [ " ide " , " sata " , " scsi " ] ,
2015-08-03 19:52:07 +03:00
" lun " : [ " scsi " ] ,
2015-04-08 02:31:30 +03:00
}
for row in rows :
if row [ 0 ] in bus_map [ devtype ] :
model . append ( row )
2014-04-26 18:41:31 +04:00
@staticmethod
2015-05-19 19:50:39 +03:00
def populate_controller_model_combo ( combo , controller_type ) :
2014-04-26 18:41:31 +04:00
model = combo . get_model ( )
model . clear ( )
2015-05-19 19:50:39 +03:00
model . append ( [ None , _ ( " Hypervisor default " ) ] )
2014-04-26 18:41:31 +04:00
if controller_type == virtinst . VirtualController . TYPE_USB :
model . append ( [ " ich9-ehci1 " , " USB 2 " ] )
model . append ( [ " nec-xhci " , " USB 3 " ] )
elif controller_type == virtinst . VirtualController . TYPE_SCSI :
model . append ( [ " virtio-scsi " , " VirtIO SCSI " ] )
2015-05-19 19:50:39 +03:00
combo . set_active ( 0 )
2014-04-26 18:41:31 +04:00
2015-04-09 20:36:40 +03:00
@staticmethod
def label_for_input_device ( typ , bus ) :
if typ == " tablet " and bus == " usb " :
return _ ( " EvTouch USB Graphics Tablet " )
if bus in [ " usb " , " ps2 " ] :
return _ ( " Generic " ) + ( " %s %s " %
( bus . upper ( ) , str ( typ ) . capitalize ( ) ) )
return " %s %s " % ( str ( bus ) . capitalize ( ) , str ( typ ) . capitalize ( ) )
2015-05-19 22:18:30 +03:00
@staticmethod
def change_config_helper ( define_func , define_args , vm , err ,
devobj = None , hotplug_args = None ) :
"""
UI helper that handles the logic and reports errors for the
requested VM define and hotplug changes
Used here and in details . py
"""
hotplug_args = hotplug_args or { }
# Persistent config change
try :
if devobj :
# Device XML editing
define_func ( devobj = devobj , do_hotplug = False , * * define_args )
else :
# Guest XML editing
define_func ( * * define_args )
2017-05-05 19:47:21 +03:00
except Exception as e :
2015-05-19 22:18:30 +03:00
err . show_err ( ( _ ( " Error changing VM configuration: %s " ) %
str ( e ) ) )
return False
if not vm . is_active ( ) :
return True
# Hotplug change
hotplug_err = None
did_hotplug = False
try :
if devobj :
define_func ( devobj = devobj , do_hotplug = True , * * define_args )
did_hotplug = True
elif hotplug_args :
did_hotplug = True
vm . hotplug ( * * hotplug_args )
2017-05-05 19:47:21 +03:00
except Exception as e :
2015-05-19 22:18:30 +03:00
did_hotplug = True
logging . debug ( " Hotplug failed: %s " , str ( e ) )
hotplug_err = ( ( str ( e ) , " " . join ( traceback . format_exc ( ) ) ) )
if did_hotplug and not hotplug_err :
return True
if len ( define_args ) > 1 :
msg = _ ( " Some changes may require a guest shutdown "
" to take effect. " )
else :
msg = _ ( " These changes will take effect after "
" the next guest shutdown. " )
dtype = ( hotplug_err and
Gtk . MessageType . WARNING or Gtk . MessageType . INFO )
hotplug_msg = " "
if hotplug_err :
hotplug_msg + = ( hotplug_err [ 0 ] + " \n \n " +
hotplug_err [ 1 ] + " \n " )
err . show_err ( msg ,
details = hotplug_msg ,
buttons = Gtk . ButtonsType . OK ,
dialog_type = dtype )
return True
2014-01-27 02:09:07 +04:00
2009-11-24 20:43:54 +03:00
#########################
# UI population methods #
#########################
2009-07-14 17:25:39 +04:00
2015-05-19 22:18:30 +03:00
def _refresh_disk_bus ( self , devtype ) :
2015-09-14 01:01:39 +03:00
widget = self . widget ( " storage-bustype " )
2014-01-13 01:52:26 +04:00
model = widget . get_model ( )
2015-04-08 02:31:30 +03:00
self . populate_disk_bus_combo ( self . vm , devtype , model )
2014-01-13 01:52:26 +04:00
2015-04-06 20:36:54 +03:00
# By default, select bus of the first disk assigned to the VM
2015-03-26 16:44:24 +03:00
default_bus = None
for i in self . vm . get_disk_devices ( ) :
2015-04-08 02:31:30 +03:00
if i . device == devtype :
2015-03-26 16:44:24 +03:00
default_bus = i . bus
break
if default_bus :
2015-05-20 01:13:33 +03:00
uiutil . set_list_selection ( widget , default_bus )
2015-03-26 16:44:24 +03:00
elif len ( model ) > 0 :
2014-01-13 01:52:26 +04:00
widget . set_active ( 0 )
2015-05-19 22:18:30 +03:00
def _populate_input_model ( self , model ) :
2009-11-24 20:43:54 +03:00
model . clear ( )
2015-04-09 20:36:40 +03:00
def _add_row ( typ , bus ) :
model . append ( [ self . label_for_input_device ( typ , bus ) , typ , bus ] )
_add_row ( " tablet " , " usb " )
_add_row ( " mouse " , " usb " )
_add_row ( " keyboard " , " usb " )
2017-06-27 19:39:17 +03:00
_add_row ( " keyboard " , " virtio " )
_add_row ( " tablet " , " virtio " )
2009-11-24 20:43:54 +03:00
2015-05-19 22:18:30 +03:00
def _populate_host_device_model ( self , devtype , devcap , subtype , subcap ) :
2011-07-14 21:13:13 +04:00
devlist = self . widget ( " host-device " )
2010-12-11 23:55:31 +03:00
model = devlist . get_model ( )
2009-11-24 20:43:54 +03:00
model . clear ( )
subdevs = [ ]
if subtype :
2015-04-10 16:37:03 +03:00
subdevs = self . conn . filter_nodedevs ( subtype , subcap )
2009-11-24 20:43:54 +03:00
2015-04-10 16:37:03 +03:00
devs = self . conn . filter_nodedevs ( devtype , devcap )
2009-11-24 20:43:54 +03:00
for dev in devs :
2015-04-07 21:12:00 +03:00
prettyname = dev . xmlobj . pretty_name ( )
2009-11-24 20:43:54 +03:00
for subdev in subdevs :
2015-04-07 21:12:00 +03:00
if dev . xmlobj . name == subdev . xmlobj . parent :
prettyname + = " ( %s ) " % subdev . xmlobj . pretty_name ( )
2009-11-24 20:43:54 +03:00
2015-08-10 21:18:43 +03:00
model . append ( [ prettyname , dev . xmlobj ] )
2009-11-24 20:43:54 +03:00
if len ( model ) == 0 :
2015-08-10 21:18:43 +03:00
model . append ( [ _ ( " No Devices Available " ) , None ] )
2015-05-20 01:13:33 +03:00
uiutil . set_list_selection_by_number ( devlist , 0 )
2009-11-24 20:43:54 +03:00
2015-05-19 22:18:30 +03:00
def _populate_controller_type ( self ) :
2014-04-26 18:40:17 +04:00
widget = self . widget ( " controller-type " )
model = widget . get_model ( )
model . clear ( )
for t in VirtualController . TYPES :
if t == VirtualController . TYPE_PCI :
continue
model . append ( [ t , VirtualController . pretty_type ( t ) ] )
if len ( model ) > 0 :
widget . set_active ( 0 )
2015-05-19 22:18:30 +03:00
def _populate_controller_model ( self , src ) :
2014-04-26 18:41:31 +04:00
ignore = src
2014-06-16 07:50:04 +04:00
def show_tooltip ( model_tooltip , show ) :
vmname = self . vm . get_name ( )
tooltip = ( _ ( " %s already has a USB controller attached. \n "
" Adding more than one USB controller is not supported. \n "
" You can change the USB controller type in the VM details screen. " )
% vmname )
model_tooltip . set_visible ( show )
model_tooltip . set_tooltip_text ( tooltip )
2015-05-19 22:18:30 +03:00
controller_type = uiutil . get_list_selection (
2015-05-20 00:17:53 +03:00
self . widget ( " controller-type " ) )
2015-05-19 19:50:39 +03:00
combo = self . widget ( " controller-model " )
combo . set_sensitive ( True )
2014-06-16 07:50:04 +04:00
model_tooltip = self . widget ( " controller-tooltip " )
show_tooltip ( model_tooltip , False )
2014-06-16 07:48:22 +04:00
controllers = self . vm . get_controller_devices ( )
if controller_type == VirtualController . TYPE_USB :
usb_controllers = [ x for x in controllers if
( x . type == VirtualController . TYPE_USB ) ]
if ( len ( usb_controllers ) == 0 ) :
self . widget ( " create-finish " ) . set_sensitive ( True )
2015-05-19 19:50:39 +03:00
elif ( len ( usb_controllers ) == 1 and
usb_controllers [ 0 ] . model == " none " ) :
2014-06-16 07:48:22 +04:00
self . _remove_usb_controller = usb_controllers [ 0 ]
self . widget ( " create-finish " ) . set_sensitive ( True )
else :
2014-06-16 07:50:04 +04:00
show_tooltip ( model_tooltip , True )
2014-06-16 07:48:22 +04:00
self . widget ( " create-finish " ) . set_sensitive ( False )
else :
self . widget ( " create-finish " ) . set_sensitive ( True )
2014-04-26 18:41:31 +04:00
2015-05-19 19:50:39 +03:00
self . populate_controller_model_combo ( combo , controller_type )
uiutil . set_grid_row_visible ( combo , len ( combo . get_model ( ) ) > 1 )
2014-04-26 18:41:31 +04:00
2014-01-29 01:53:11 +04:00
2015-05-19 22:18:30 +03:00
def _build_combo_with_values ( self , combo , values , default = None ) :
2013-09-23 17:39:57 +04:00
# [xml value, label]
2015-05-19 22:18:30 +03:00
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
uiutil . init_combo_text_column ( combo , 1 )
model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
2013-09-23 17:39:57 +04:00
2015-05-19 22:18:30 +03:00
for xmlval , label in values :
model . append ( [ xmlval , label ] )
2013-09-23 17:39:57 +04:00
if default :
2015-05-20 01:13:33 +03:00
uiutil . set_list_selection ( combo , default )
2013-09-23 17:39:57 +04:00
2015-05-19 22:18:30 +03:00
def _build_rng_type_combo ( self , combo ) :
2013-09-23 17:39:57 +04:00
types = [ ]
for t in virtinst . VirtualRNGDevice . TYPES :
types . append ( [ t , virtinst . VirtualRNGDevice . get_pretty_type ( t ) ] )
2015-05-19 22:18:30 +03:00
self . _build_combo_with_values ( combo , types ,
2013-09-23 17:39:57 +04:00
virtinst . VirtualRNGDevice . TYPE_RANDOM )
2015-05-19 22:18:30 +03:00
def _build_rng_backend_type_combo ( self , combo ) :
2013-09-23 17:39:57 +04:00
default = virtinst . VirtualRNGDevice . BACKEND_TYPE_TCP
types = [ ]
for t in virtinst . VirtualRNGDevice . BACKEND_TYPES :
pprint = virtinst . VirtualRNGDevice . get_pretty_backend_type ( t )
types . append ( [ t , pprint ] )
2015-05-19 22:18:30 +03:00
self . _build_combo_with_values ( combo , types , default )
2013-09-23 17:39:57 +04:00
2015-05-19 22:18:30 +03:00
def _build_rng_backend_mode_combo ( self , combo ) :
2013-09-23 17:39:57 +04:00
default = virtinst . VirtualRNGDevice . BACKEND_MODE_CONNECT
types = [ ]
for t in virtinst . VirtualRNGDevice . BACKEND_MODES :
pprint = virtinst . VirtualRNGDevice . get_pretty_backend_type ( t )
types . append ( [ t , pprint ] )
2015-05-19 22:18:30 +03:00
self . _build_combo_with_values ( combo , types , default )
2013-09-23 17:39:57 +04:00
2015-05-19 22:18:30 +03:00
def _build_panic_address_type ( self , combo ) :
2014-01-10 13:37:56 +04:00
types = [ ]
for t in virtinst . VirtualPanicDevice . TYPES :
types . append ( [ t , virtinst . VirtualPanicDevice . get_pretty_type ( t ) ] )
2015-05-19 22:18:30 +03:00
self . _build_combo_with_values ( combo , types ,
2014-01-10 13:37:56 +04:00
virtinst . VirtualPanicDevice . ADDRESS_TYPE_ISA )
2007-09-26 04:05:45 +04:00
2015-05-19 22:18:30 +03:00
#########################
# Internal misc helpers #
#########################
2009-01-23 01:00:10 +03:00
2015-05-19 22:18:30 +03:00
def _get_char_class ( self ) :
row = self . _get_hw_selection ( )
label = " serial "
2013-09-23 17:39:57 +04:00
2015-05-19 22:18:30 +03:00
if row :
label = row [ 5 ]
2013-09-23 17:39:57 +04:00
2015-05-19 22:18:30 +03:00
if label == " parallel " :
return VirtualParallelDevice
elif label == " channel " :
return VirtualChannelDevice
elif label == " console " :
return VirtualConsoleDevice
return VirtualSerialDevice
2013-09-23 17:39:57 +04:00
2015-05-19 22:18:30 +03:00
def _set_hw_selection ( self , page ) :
2015-05-20 01:13:33 +03:00
uiutil . set_list_selection_by_number ( self . widget ( " hw-list " ) , page )
2013-09-23 17:39:57 +04:00
2015-05-19 22:18:30 +03:00
def _get_hw_selection ( self ) :
2015-05-20 00:17:53 +03:00
return uiutil . get_list_selected_row ( self . widget ( " hw-list " ) )
2014-04-26 18:40:17 +04:00
2009-11-24 20:43:54 +03:00
################
# UI listeners #
################
2015-05-19 22:18:30 +03:00
def _update_char_device_type_model ( self ) :
2014-01-20 20:09:13 +04:00
stable_blacklist = [ " pipe " , " udp " ]
2011-09-26 19:34:21 +04:00
2011-04-05 03:35:32 +04:00
# Char device type
2011-07-14 21:13:13 +04:00
char_devtype = self . widget ( " char-device-type " )
2013-10-05 21:27:11 +04:00
char_devtype_model = char_devtype . get_model ( )
char_devtype_model . clear ( )
2015-05-19 22:18:30 +03:00
char_class = self . _get_char_class ( )
2013-07-16 17:14:37 +04:00
2011-04-05 03:35:32 +04:00
# Type name, desc
2013-07-16 17:14:37 +04:00
for t in char_class . TYPES :
2014-01-20 20:09:13 +04:00
if ( t in stable_blacklist and
self . vm . stable_defaults ( ) ) :
2011-09-26 19:34:21 +04:00
continue
2013-07-16 17:14:37 +04:00
desc = char_class . pretty_type ( t )
2011-04-05 03:35:32 +04:00
row = [ t , desc + " ( %s ) " % t ]
char_devtype_model . append ( row )
char_devtype . set_active ( 0 )
2015-05-19 22:18:30 +03:00
def _hw_selected ( self , src = None ) :
2010-12-11 20:32:04 +03:00
ignore = src
self . _dev = None
2011-07-14 21:13:13 +04:00
notebook = self . widget ( " create-pages " )
2009-11-24 20:43:54 +03:00
2015-05-19 22:18:30 +03:00
row = self . _get_hw_selection ( )
2010-12-11 20:32:04 +03:00
if not row :
2015-05-19 22:18:30 +03:00
self . _set_hw_selection ( 0 )
2010-12-11 20:32:04 +03:00
return
2009-11-24 21:32:14 +03:00
2010-12-11 20:32:04 +03:00
page = row [ 2 ]
sens = row [ 3 ]
msg = row [ 4 ] or " "
2009-11-24 20:43:54 +03:00
2014-04-17 13:25:01 +04:00
self . widget ( " create-finish " ) . set_sensitive ( sens )
2010-12-11 20:32:04 +03:00
if not sens :
2010-12-11 22:51:08 +03:00
page = PAGE_ERROR
2011-07-14 21:13:13 +04:00
self . widget ( " hardware-info " ) . set_text ( msg )
2010-03-04 23:29:33 +03:00
2010-12-11 20:32:04 +03:00
if page == PAGE_CHAR :
2015-05-19 22:18:30 +03:00
# Need to do this here, since we share the char page between
# multiple different HW options
self . _update_char_device_type_model ( )
2013-10-05 21:27:11 +04:00
self . widget ( " char-device-type " ) . emit ( " changed " )
self . widget ( " char-target-name " ) . emit ( " changed " )
2009-07-14 17:25:39 +04:00
2010-12-11 23:55:31 +03:00
if page == PAGE_HOSTDEV :
2015-05-19 22:18:30 +03:00
# Need to do this here, since we share the hostdev page
# between two different HW options
pci_info = [ " pci " , None , " net " , " 80203 " ]
usb_info = [ " usb_device " , None , None , None ]
row = self . _get_hw_selection ( )
if row and row [ 5 ] == " pci " :
info = pci_info
else :
info = usb_info
( devtype , devcap , subtype , subcap ) = info
self . _populate_host_device_model ( devtype , devcap , subtype , subcap )
2010-12-11 23:55:31 +03:00
2015-05-19 22:18:30 +03:00
self . _set_page_title ( page )
2010-12-11 22:51:08 +03:00
notebook . get_nth_page ( page ) . show ( )
notebook . set_current_page ( page )
2007-04-12 23:36:04 +04:00
2015-05-19 22:18:30 +03:00
def _dev_to_title ( self , page ) :
2010-12-11 21:05:07 +03:00
if page == PAGE_ERROR :
return _ ( " Error " )
if page == PAGE_DISK :
return _ ( " Storage " )
2014-04-26 18:40:17 +04:00
if page == PAGE_CONTROLLER :
return _ ( " Controller " )
2010-12-11 21:05:07 +03:00
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-20 02:17:58 +04:00
if page == PAGE_FILESYSTEM :
return _ ( " Filesystem Passthrough " )
2011-06-23 19:42:03 +04:00
if page == PAGE_SMARTCARD :
return _ ( " Smartcard " )
2011-09-02 05:23:28 +04:00
if page == PAGE_USBREDIR :
return _ ( " USB Redirection " )
2013-06-26 05:45:09 +04:00
if page == PAGE_TPM :
return _ ( " TPM " )
2013-09-23 17:39:57 +04:00
if page == PAGE_RNG :
return _ ( " Random Number Generator " )
2014-01-10 13:37:56 +04:00
if page == PAGE_PANIC :
return _ ( " Panic Notifier " )
2010-12-11 21:05:07 +03:00
2010-12-11 23:55:31 +03:00
if page == PAGE_CHAR :
2015-05-19 22:18:30 +03:00
char_class = self . _get_char_class ( )
2016-02-05 18:18:16 +03:00
return _ ( " %s Device " ) % char_class . virtual_device_type . capitalize ( )
2010-12-11 23:55:31 +03:00
if page == PAGE_HOSTDEV :
2015-05-19 22:18:30 +03:00
row = self . _get_hw_selection ( )
if row and row [ 5 ] == " pci " :
return _ ( " PCI Device " )
return _ ( " USB Device " )
2010-12-11 23:55:31 +03:00
raise RuntimeError ( " Unknown page %s " % page )
2010-12-11 21:05:07 +03:00
2015-05-19 22:18:30 +03:00
def _set_page_title ( self , page ) :
title = self . _dev_to_title ( page )
2013-09-27 19:18:52 +04:00
markup = " <span size= ' large ' color= ' white ' > %s </span> " % title
2011-07-14 21:13:13 +04:00
self . widget ( " page-title-label " ) . set_markup ( markup )
2009-07-14 17:25:39 +04:00
2015-05-19 22:18:30 +03:00
#########################
# Device page listeners #
#########################
def _change_storage_devtype ( self , ignore ) :
devtype = uiutil . get_list_selection (
2015-09-14 01:01:39 +03:00
self . widget ( " storage-devtype " ) )
2015-05-19 22:18:30 +03:00
self . _refresh_disk_bus ( devtype )
allow_create = devtype not in [ " cdrom " , " floppy " ]
2015-09-14 01:01:39 +03:00
self . addstorage . widget ( " storage-create-box " ) . set_sensitive (
2015-05-19 22:18:30 +03:00
allow_create )
if not allow_create :
2015-09-14 01:01:39 +03:00
self . addstorage . widget ( " storage-select " ) . set_active ( True )
2015-05-19 22:18:30 +03:00
def _change_macaddr_use ( self , ignore = None ) :
if self . widget ( " mac-address " ) . get_active ( ) :
self . widget ( " create-mac-address " ) . set_sensitive ( True )
else :
self . widget ( " create-mac-address " ) . set_sensitive ( False )
def _change_tpm_device_type ( self , src ) :
2015-05-20 00:17:53 +03:00
devtype = uiutil . get_list_selection ( src )
2014-01-27 05:21:12 +04:00
if devtype is None :
2013-06-26 05:45:09 +04:00
return
2013-10-05 19:28:41 +04:00
tpm_widget_mappings = {
" device_path " : " tpm-device-path " ,
}
2014-01-27 05:21:12 +04:00
self . _dev = VirtualTPMDevice ( self . conn . get_backend ( ) )
2013-07-15 20:18:23 +04:00
self . _dev . type = devtype
2013-06-26 05:45:09 +04:00
for param_name , widget_name in tpm_widget_mappings . items ( ) :
make_visible = self . _dev . supports_property ( param_name )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( widget_name + " -label " ) ,
2013-09-09 21:06:37 +04:00
make_visible )
2013-06-26 05:45:09 +04:00
2015-05-19 22:18:30 +03:00
def _change_char_auto_socket ( self , src ) :
2013-10-05 21:54:28 +04:00
if not src . get_visible ( ) :
return
doshow = not src . get_active ( )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( " char-path-label " ) , doshow )
uiutil . set_grid_row_visible ( self . widget ( " char-mode-label " ) , doshow )
2013-10-05 21:54:28 +04:00
2015-05-19 22:18:30 +03:00
def _change_char_target_name ( self , src ) :
2013-10-05 21:27:11 +04:00
if not src . get_visible ( ) :
return
text = src . get_child ( ) . get_text ( )
settype = None
if text == VirtualChannelDevice . CHANNEL_NAME_SPICE :
settype = " spicevmc "
2014-03-25 18:42:34 +04:00
elif text == VirtualChannelDevice . CHANNEL_NAME_SPICE_WEBDAV :
settype = " spiceport "
self . widget ( " char-channel " ) . set_text ( text )
2013-10-05 21:27:11 +04:00
elif ( text == VirtualChannelDevice . CHANNEL_NAME_QEMUGA or
text == VirtualChannelDevice . CHANNEL_NAME_LIBGUESTFS ) :
settype = " unix "
2015-05-20 01:11:00 +03:00
if settype :
2015-05-20 01:13:33 +03:00
uiutil . set_list_selection (
2015-05-20 01:11:00 +03:00
self . widget ( " char-device-type " ) , settype )
2013-10-05 21:27:11 +04:00
2015-05-19 22:18:30 +03:00
def _change_char_device_type ( self , src ) :
2015-05-20 00:17:53 +03:00
devtype = uiutil . get_list_selection ( src )
2014-01-27 05:21:12 +04:00
if devtype is None :
2011-04-05 03:35:32 +04:00
return
2009-07-14 17:25:39 +04:00
2013-10-05 19:28:41 +04:00
char_widget_mappings = {
" source_path " : " char-path " ,
2014-03-25 18:42:34 +04:00
" source_channel " : " char-channel " ,
2013-10-05 19:28:41 +04:00
" source_mode " : " char-mode " ,
" source_host " : " char-host " ,
" bind_host " : " char-bind-host " ,
" protocol " : " char-use-telnet " ,
}
2015-05-19 22:18:30 +03:00
char_class = self . _get_char_class ( )
2013-10-05 21:33:55 +04:00
ischan = char_class . virtual_device_type == " channel "
iscon = char_class . virtual_device_type == " console "
2013-10-05 21:54:28 +04:00
show_auto = ( devtype == " unix " and ischan and
2013-10-06 18:08:04 +04:00
self . conn . check_support ( self . conn . SUPPORT_CONN_AUTOSOCKET ) )
2009-07-14 17:25:39 +04:00
2014-01-27 05:21:12 +04:00
self . _dev = char_class ( self . conn . get_backend ( ) )
2013-07-16 17:14:37 +04:00
self . _dev . type = devtype
2009-07-14 17:25:39 +04:00
for param_name , widget_name in char_widget_mappings . items ( ) :
2010-09-03 02:37:20 +04:00
make_visible = self . _dev . supports_property ( param_name )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( widget_name + " -label " ) ,
2013-09-09 20:48:17 +04:00
make_visible )
2009-07-14 17:25:39 +04:00
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible (
2013-10-05 21:33:55 +04:00
self . widget ( " char-target-name-label " ) , ischan )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible (
2013-10-05 21:33:55 +04:00
self . widget ( " char-target-type-label " ) , iscon )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible (
2013-10-05 21:54:28 +04:00
self . widget ( " char-auto-socket-label " ) , show_auto )
self . widget ( " char-auto-socket " ) . emit ( " toggled " )
2013-10-05 21:33:55 +04:00
2010-09-03 02:37:20 +04:00
has_mode = self . _dev . supports_property ( " source_mode " )
2011-07-14 21: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 17:25:39 +04:00
2015-05-19 22:18:30 +03:00
def _change_usbredir_type ( self , src ) :
2015-05-20 00:17:53 +03:00
showhost = uiutil . get_list_selection ( src , column = 2 )
2014-01-27 05:21:12 +04:00
if showhost is None :
2011-09-02 05:23:28 +04:00
return
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( " usbredir-host-box " ) ,
2013-09-09 19:17:01 +04:00
showhost )
2011-09-02 05:23:28 +04:00
2015-05-19 22:18:30 +03:00
def _change_rng ( self , ignore1 ) :
2015-05-20 00:17:53 +03:00
rtype = uiutil . get_list_selection ( self . widget ( " rng-type " ) )
2015-05-19 22:18:30 +03:00
is_egd = rtype == virtinst . VirtualRNGDevice . TYPE_EGD
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( " rng-device " ) , not is_egd )
uiutil . set_grid_row_visible ( self . widget ( " rng-backend-type " ) , is_egd )
2013-09-23 17:39:57 +04:00
2015-05-19 22:18:30 +03:00
backend_type = uiutil . get_list_selection (
2015-05-20 00:17:53 +03:00
self . widget ( " rng-backend-type " ) )
2015-05-19 22:18:30 +03:00
backend_mode = uiutil . get_list_selection (
2015-05-20 00:17:53 +03:00
self . widget ( " rng-backend-mode " ) )
2013-10-25 19:13:28 +04:00
udp = backend_type == virtinst . VirtualRNGDevice . BACKEND_TYPE_UDP
bind = backend_mode == virtinst . VirtualRNGDevice . BACKEND_MODE_BIND
v = is_egd and ( udp or bind )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( " rng-bind-host-box " ) , v )
2013-10-25 19:13:28 +04:00
v = is_egd and ( udp or not bind )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( " rng-connect-host-box " ) , v )
2013-10-25 19:13:28 +04:00
v = is_egd and not udp
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( " rng-backend-mode " ) , v )
2013-10-25 19:13:28 +04:00
2008-08-21 23:58:35 +04:00
2009-11-24 20:43:54 +03:00
######################
# Add device methods #
######################
2007-04-12 23:36:04 +04:00
2015-05-19 22:18:30 +03:00
def _setup_device ( self , asyncjob ) :
2015-03-27 02:08:04 +03:00
poolname = None
if ( self . _dev . virtual_device_type == " disk " and
self . _dev . wants_storage_creation ( ) and
self . _dev . get_parent_pool ( ) ) :
poolname = self . _dev . get_parent_pool ( ) . name ( )
logging . debug ( " Running setup() for device= %s " , self . _dev )
2013-09-07 04:59:01 +04:00
self . _dev . setup ( meter = asyncjob . get_meter ( ) )
2015-03-27 02:08:04 +03:00
logging . debug ( " Device setup() complete " )
if poolname :
try :
pool = self . conn . get_pool ( poolname )
self . idle_add ( pool . refresh )
except :
logging . debug ( " Error looking up pool= %s for refresh after "
" storage creation. " , poolname , exc_info = True )
2008-03-14 20:18:44 +03:00
2015-05-19 22:18:30 +03:00
def _add_device ( self ) :
2010-02-07 20:10:41 +03:00
self . _dev . get_xml_config ( )
logging . debug ( " Adding device: \n " + self . _dev . get_xml_config ( ) )
2007-11-17 01:12:37 +03:00
2014-06-16 07:48:22 +04:00
if self . _remove_usb_controller :
kwargs = { }
kwargs [ " model " ] = self . _selected_model
self . change_config_helper ( self . vm . define_controller ,
2015-04-11 00:14:08 +03:00
kwargs , self . vm , self . err ,
devobj = self . _remove_usb_controller )
2014-06-16 07:48:22 +04:00
self . _remove_usb_controller = None
self . _selected_model = None
return
2012-12-07 14:21:38 +04:00
controller = getattr ( self . _dev , " vmm_controller " , None )
if controller is not None :
logging . debug ( " Adding controller: \n %s " ,
2014-01-29 01:53:11 +04:00
controller . get_xml_config ( ) )
2009-11-24 20:43:54 +03:00
# Hotplug device
attach_err = False
try :
2012-12-07 14:21:38 +04:00
if controller is not None :
2014-01-29 01:53:11 +04:00
self . vm . attach_device ( controller )
2010-02-07 20:10:41 +03:00
self . vm . attach_device ( self . _dev )
2017-05-05 19:47:21 +03:00
except Exception as e :
2012-01-17 07:04:40 +04:00
logging . debug ( " Device could not be hotplugged: %s " , str ( e ) )
2010-12-02 01:48:07 +03:00
attach_err = ( str ( e ) , " " . join ( traceback . format_exc ( ) ) )
2007-11-17 01:12:37 +03:00
2009-11-24 20:43:54 +03:00
if attach_err :
2010-12-02 01:48:07 +03:00
res = self . err . show_err (
_ ( " Are you sure you want to add this device? " ) ,
2011-04-06 19:22:03 +04:00
details = ( attach_err [ 0 ] + " \n \n " + attach_err [ 1 ] ) ,
2010-12-02 01:48:07 +03:00
text2 = (
_ ( " This device could not be attached to the running machine. "
" Would you like to make the device available after the "
2011-07-15 01:16:57 +04:00
" next guest shutdown? " ) ) ,
2012-05-14 17:24:56 +04:00
dialog_type = Gtk . MessageType . WARNING ,
buttons = Gtk . ButtonsType . YES_NO ,
2013-09-07 04:16:37 +04:00
modal = True )
2010-12-02 01:48:07 +03:00
if not res :
2013-09-07 04:59:01 +04:00
return False
2008-03-14 17:55:12 +03:00
2009-11-24 20:43:54 +03:00
# Alter persistent config
try :
2012-12-07 14:21:38 +04:00
if controller is not None :
2014-01-29 01:53:11 +04:00
self . vm . add_device ( controller )
2010-02-07 20:10:41 +03:00
self . vm . add_device ( self . _dev )
2017-05-05 19:47:21 +03:00
except Exception as e :
2015-06-02 15:21:58 +03:00
self . err . show_err ( _ ( " Error adding device: %s " ) % str ( e ) )
2013-09-07 04:59:01 +04:00
return True
return False
def _finish_cb ( self , error , details ) :
failure = True
if not error :
try :
2015-05-19 22:18:30 +03:00
failure = self . _add_device ( )
2017-05-05 19:47:21 +03:00
except Exception as e :
2013-09-07 04:59:01 +04:00
failure = True
error = _ ( " Unable to add device: %s " ) % str ( e )
details = " " . join ( traceback . format_exc ( ) )
if error is not None :
self . err . show_err ( error , details = details )
2017-04-27 22:00:17 +03:00
self . reset_finish_cursor ( )
2013-09-07 04:59:01 +04:00
self . _dev = None
if not failure :
self . close ( )
2010-02-06 23:59:52 +03:00
2015-05-19 22:18:30 +03:00
def _finish ( self , ignore = None ) :
2013-09-07 04:59:01 +04:00
try :
2015-05-19 22:18:30 +03:00
if self . _validate ( ) is False :
2013-09-07 04:59:01 +04:00
return
2017-05-05 19:47:21 +03:00
except Exception as e :
2013-09-07 04:59:01 +04:00
self . err . show_err ( _ ( " Uncaught error validating hardware "
" input: %s " ) % str ( e ) )
return
2017-04-27 22:00:17 +03:00
self . set_finish_cursor ( )
2015-05-19 22:18:30 +03:00
progWin = vmmAsyncJob ( self . _setup_device , [ ] ,
2013-09-07 04:59:01 +04:00
self . _finish_cb , [ ] ,
_ ( " Creating device " ) ,
_ ( " Depending on the device, this may take "
" a few minutes to complete. " ) ,
self . topwin )
progWin . run ( )
2009-11-24 20:43:54 +03:00
2009-03-09 23:20:23 +03:00
2009-11-24 20:43:54 +03:00
###########################
# Page validation methods #
###########################
2015-05-19 22:18:30 +03:00
def _validate ( self ) :
page_num = self . widget ( " create-pages " ) . get_current_page ( )
2010-12-11 20:32:04 +03:00
if page_num == PAGE_ERROR :
self . _dev = None
2015-05-19 22:18:30 +03:00
ret = True
2009-11-24 20:43:54 +03:00
elif page_num == PAGE_DISK :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_storage ( )
2014-04-26 18:40:17 +04:00
elif page_num == PAGE_CONTROLLER :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_controller ( )
2009-11-24 20:43:54 +03:00
elif page_num == PAGE_NETWORK :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_network ( )
2009-11-24 20:43:54 +03:00
elif page_num == PAGE_INPUT :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_input ( )
2009-11-24 20:43:54 +03:00
elif page_num == PAGE_GRAPHICS :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_graphics ( )
2009-11-24 20:43:54 +03:00
elif page_num == PAGE_SOUND :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_sound ( )
2009-03-09 23:20:23 +03:00
elif page_num == PAGE_HOSTDEV :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_hostdev ( )
2009-11-24 20:43:54 +03:00
elif page_num == PAGE_CHAR :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_char ( )
2009-11-24 20:43:54 +03:00
elif page_num == PAGE_VIDEO :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_video ( )
2010-03-24 07:22:17 +03:00
elif page_num == PAGE_WATCHDOG :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_watchdog ( )
2011-05-20 02:17:58 +04:00
elif page_num == PAGE_FILESYSTEM :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_filesystem ( )
2011-06-23 19:42:03 +04:00
elif page_num == PAGE_SMARTCARD :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_smartcard ( )
2011-09-02 05:23:28 +04:00
elif page_num == PAGE_USBREDIR :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_usbredir ( )
2013-06-26 05:45:09 +04:00
elif page_num == PAGE_TPM :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_tpm ( )
2013-09-23 17:39:57 +04:00
elif page_num == PAGE_RNG :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_rng ( )
2014-01-10 13:37:56 +04:00
elif page_num == PAGE_PANIC :
2015-05-19 22:18:30 +03:00
ret = self . _validate_page_panic ( )
2009-03-09 23:20:23 +03:00
2013-10-06 20:55:21 +04:00
if ret is not False and self . _dev :
2013-10-06 21:17:35 +04:00
self . _dev . set_defaults ( self . vm . get_xmlobj ( ) )
2013-10-06 20:55:21 +04:00
self . _dev . validate ( )
return ret
2014-02-12 18:58:40 +04:00
def _set_disk_controller ( self , disk , controller_model , used_disks ) :
2014-01-29 01:53:11 +04:00
# Add a SCSI controller with model virtio-scsi if needed
disk . vmm_controller = None
if controller_model != " virtio-scsi " :
2014-02-12 18:58:40 +04:00
return None
2014-01-29 01:53:11 +04:00
2014-02-12 18:58:40 +04:00
# Get SCSI controllers
2014-01-29 01:53:11 +04:00
controllers = self . vm . get_controller_devices ( )
ctrls_scsi = [ x for x in controllers if
( x . type == VirtualController . TYPE_SCSI ) ]
2014-02-12 18:58:40 +04:00
# Create possible new controller
2014-01-29 01:53:11 +04:00
controller = VirtualController ( self . conn . get_backend ( ) )
controller . type = " scsi "
controller . model = controller_model
2014-02-12 18:58:40 +04:00
# And set its index
controller . index = 0
if ctrls_scsi :
controller . index = max ( [ x . index for x in ctrls_scsi ] ) + 1
# Take only virtio-scsi ones
ctrls_scsi = [ x for x in ctrls_scsi
if x . model == controller_model ]
# Save occupied places per controller
occupied = collections . defaultdict ( int )
for d in used_disks :
2014-02-18 15:02:37 +04:00
if d . get_target_prefix ( ) == disk . get_target_prefix ( ) :
2014-02-12 18:58:40 +04:00
num = virtinst . VirtualDisk . target_to_num ( d . target )
occupied [ num / 7 ] + = 1
for c in ctrls_scsi :
if occupied [ c . index ] < 7 :
controller = c
2014-01-29 01:53:11 +04:00
break
2014-02-12 18:58:40 +04:00
else :
disk . vmm_controller = controller
2014-01-29 01:53:11 +04:00
2014-02-12 18:58:40 +04:00
return controller . index
2014-01-29 01:53:11 +04:00
2015-05-19 22:18:30 +03:00
def _validate_page_storage ( self ) :
bus = uiutil . get_list_selection (
2015-09-14 01:01:39 +03:00
self . widget ( " storage-bustype " ) )
2015-05-19 22:18:30 +03:00
device = uiutil . get_list_selection (
2015-09-14 01:01:39 +03:00
self . widget ( " storage-devtype " ) )
2015-05-19 22:18:30 +03:00
cache = uiutil . get_list_selection (
2015-09-14 01:01:39 +03:00
self . widget ( " storage-cache " ) )
2013-07-05 16:59:58 +04:00
2014-01-29 01:53:11 +04:00
controller_model = None
2015-08-03 19:52:07 +03:00
if ( bus == " scsi " and
self . vm . get_hv_type ( ) in [ " qemu " , " kvm " , " test " ] and
not self . vm . xmlobj . os . is_pseries ( ) ) :
2013-02-07 00:41:43 +04:00
controller_model = " virtio-scsi "
2009-11-24 20:43:54 +03:00
2014-01-29 01:53:11 +04:00
collidelist = [ d . path for d in self . vm . get_disk_devices ( ) ]
2015-09-13 23:02:35 +03:00
try :
disk = self . addstorage . validate_storage ( self . vm . get_name ( ) ,
2015-09-14 02:05:02 +03:00
collidelist = collidelist , device = device )
2017-05-05 19:47:21 +03:00
except Exception as e :
2015-09-13 23:02:35 +03:00
return self . err . val_err ( _ ( " Storage parameter error. " ) , e )
2015-09-14 01:42:10 +03:00
if disk is False :
return False
2009-11-24 20:43:54 +03:00
try :
2014-02-18 14:38:56 +04:00
used = [ ]
2013-07-13 18:09:00 +04:00
disk . bus = bus
2013-10-06 21:17:35 +04:00
if cache :
disk . driver_cache = cache
2010-03-04 23:35:34 +03:00
2014-01-29 01:53:11 +04:00
# Generate target
2015-05-04 00:17:53 +03:00
disks = ( self . vm . get_disk_devices ( ) +
self . vm . get_disk_devices ( inactive = True ) )
for d in disks :
if d . target not in used :
used . append ( d . target )
2010-02-06 23:59:52 +03:00
2014-03-07 18:37:08 +04:00
prefer_ctrl = self . _set_disk_controller (
disk , controller_model , disks )
2014-02-18 14:38:56 +04:00
2015-05-04 00:17:53 +03:00
disk . generate_target ( used , prefer_ctrl )
2017-05-05 19:47:21 +03:00
except Exception as e :
2014-01-29 01:53:11 +04:00
return self . err . val_err ( _ ( " Storage parameter error. " ) , e )
2013-06-18 18:12:39 +04:00
2014-01-29 01:53:11 +04:00
if self . addstorage . validate_disk_object ( disk ) is False :
return False
2012-12-07 14:21:38 +04:00
2010-03-04 23:35:34 +03:00
self . _dev = disk
return True
2009-12-01 20:35:04 +03:00
2015-05-19 22:18:30 +03:00
def _validate_page_network ( self ) :
nettype = self . _netlist . get_network_selection ( ) [ 0 ]
2015-05-20 00:54:53 +03:00
model = uiutil . get_list_selection ( self . widget ( " net-model " ) )
2015-05-19 22:18:30 +03:00
mac = None
if self . widget ( " mac-address " ) . get_active ( ) :
mac = self . widget ( " create-mac-address " ) . get_text ( )
2009-11-24 20:43:54 +03:00
2009-11-24 21:14:55 +03:00
if not nettype :
return self . err . val_err ( _ ( " Network selection error. " ) ,
_ ( " A network source must be selected. " ) )
2009-03-09 23:20:23 +03:00
2009-11-24 21:14:55 +03:00
if not mac :
return self . err . val_err ( _ ( " Invalid MAC address " ) ,
_ ( " A MAC address must be entered. " ) )
2009-01-23 01:00:26 +03:00
2015-05-19 22:18:30 +03:00
ret = self . _netlist . validate_network ( mac , model )
2012-11-08 17:15:02 +04:00
if ret is False :
2009-11-24 21:14:55 +03:00
return False
2009-07-14 17:25:39 +04:00
2009-11-24 21:14:55 +03:00
self . _dev = ret
2009-07-14 17:25:39 +04:00
2015-05-19 22:18:30 +03:00
def _validate_page_input ( self ) :
2015-05-20 00:17:53 +03:00
row = uiutil . get_list_selected_row ( self . widget ( " input-type " ) )
2013-07-05 16:59:58 +04:00
dev = virtinst . VirtualInputDevice ( self . conn . get_backend ( ) )
2015-05-19 22:18:30 +03:00
dev . type = row [ 1 ]
dev . bus = row [ 2 ]
2010-02-06 23:33:32 +03:00
self . _dev = dev
2015-05-19 22:18:30 +03:00
def _validate_page_graphics ( self ) :
2009-11-24 20:43:54 +03:00
try :
2017-02-21 16:00:59 +03:00
( gtype , port , tlsport , listen ,
2017-02-21 16:01:01 +03:00
addr , passwd , keymap , gl , rendernode ) = self . _gfxdetails . get_values ( )
2014-01-29 03:44:40 +04:00
2013-07-16 04:43:41 +04:00
self . _dev = virtinst . VirtualGraphics ( self . conn . get_backend ( ) )
self . _dev . type = gtype
2014-01-29 03:44:40 +04:00
self . _dev . passwd = passwd
2017-02-21 16:00:56 +03:00
self . _dev . gl = gl
2017-02-21 16:01:01 +03:00
self . _dev . rendernode = rendernode
2017-02-21 16:00:59 +03:00
if not listen or listen == " none " :
self . _dev . set_listen_none ( )
elif listen == " address " :
self . _dev . listen = addr
self . _dev . port = port
self . _dev . tlsPort = tlsport
else :
raise ValueError ( _ ( " invalid listen type " ) )
2014-01-29 03:44:40 +04:00
if keymap :
self . _dev . keymap = keymap
2017-05-05 19:47:21 +03:00
except ValueError as e :
2011-08-30 22:50:50 +04:00
self . err . val_err ( _ ( " Graphics device parameter error " ) , e )
2009-11-24 20:43:54 +03:00
2015-05-19 22:18:30 +03:00
def _validate_page_sound ( self ) :
2015-05-20 00:17:53 +03:00
smodel = uiutil . get_list_selection ( self . widget ( " sound-model " ) )
2015-05-19 22:18:30 +03:00
2009-11-24 20:43:54 +03:00
try :
2013-07-16 06:00:08 +04:00
self . _dev = virtinst . VirtualAudio ( self . conn . get_backend ( ) )
self . _dev . model = smodel
2017-05-05 19:47:21 +03:00
except Exception as e :
2011-08-30 22:50:50 +04:00
return self . err . val_err ( _ ( " Sound device parameter error " ) , e )
2009-07-14 17:25:39 +04:00
2015-05-19 22:18:30 +03:00
def _validate_page_hostdev ( self ) :
2015-08-10 21:18:43 +03:00
nodedev = uiutil . get_list_selection ( self . widget ( " host-device " ) , 1 )
if nodedev is None :
2010-04-05 20:21:03 +04:00
return self . err . val_err ( _ ( " Physical Device Required " ) ,
2009-11-24 20:43:54 +03:00
_ ( " A device must be selected. " ) )
2007-04-12 23:36:04 +04:00
2009-11-24 20:43:54 +03:00
try :
2013-09-28 02:06:39 +04:00
dev = virtinst . VirtualHostDevice ( self . conn . get_backend ( ) )
2014-09-16 19:44:22 +04:00
# Hostdev collision
names = [ ]
2014-09-20 21:04:47 +04:00
for vm in self . conn . list_vms ( ) :
for hostdev in vm . get_hostdev_devices ( ) :
2014-09-16 19:44:22 +04:00
if nodedev . compare_to_hostdev ( hostdev ) :
2014-09-25 04:12:38 +04:00
names . append ( vm . get_name ( ) )
2014-09-16 19:44:22 +04:00
if names :
res = self . err . yes_no (
_ ( ' The device is already in use by other guests %s ' ) %
( names ) ,
_ ( " Do you really want to use the device? " ) )
if not res :
return False
2015-07-23 14:15:26 +03:00
dev . set_from_nodedev ( nodedev )
2013-09-28 02:06:39 +04:00
self . _dev = dev
2017-05-05 19:47:21 +03:00
except Exception as e :
2011-08-30 22:50:50 +04:00
return self . err . val_err ( _ ( " Host device parameter error " ) , e )
2007-04-12 23:36:04 +04:00
2015-05-19 22:18:30 +03:00
def _validate_page_char ( self ) :
char_class = self . _get_char_class ( )
2011-08-30 23:03:27 +04:00
modebox = self . widget ( " char-mode " )
2011-07-14 21:13:13 +04:00
devbox = self . widget ( " char-device-type " )
2013-10-05 19:28:41 +04:00
typebox = self . widget ( " char-target-type " )
2015-05-20 00:17:53 +03:00
devtype = uiutil . get_list_selection ( devbox )
2013-07-05 16:59:58 +04:00
conn = self . conn . get_backend ( )
2007-04-12 23:36:04 +04:00
2015-05-19 22:18:30 +03:00
devclass = char_class ( conn )
2013-07-16 17:14:37 +04:00
devclass . type = devtype
2009-01-23 01:00:10 +03:00
2011-07-14 21:13:13 +04:00
source_path = self . widget ( " char-path " ) . get_text ( )
2014-03-25 18:42:34 +04:00
source_channel = self . widget ( " char-channel " ) . get_text ( )
2015-05-20 00:17:53 +03:00
source_mode = uiutil . get_list_selection ( modebox )
2011-07-14 21:13:13 +04:00
source_host = self . widget ( " char-host " ) . get_text ( )
bind_host = self . widget ( " char-bind-host " ) . get_text ( )
2013-04-17 02:37:00 +04:00
source_port = self . widget ( " char-port " ) . get_value ( )
bind_port = self . widget ( " char-bind-port " ) . get_value ( )
2013-10-05 21:27:11 +04:00
target_name = self . widget ( " char-target-name " ) . get_child ( ) . get_text ( )
2015-05-20 00:17:53 +03:00
target_type = uiutil . get_list_selection ( typebox )
2009-01-23 01:00:10 +03:00
2011-07-14 21:13:13 +04:00
if self . widget ( " char-use-telnet " ) . get_active ( ) :
2013-07-16 17:14:37 +04:00
protocol = VirtualSerialDevice . PROTOCOL_TELNET
2009-11-24 20:43:54 +03:00
else :
2013-07-16 17:14:37 +04:00
protocol = VirtualSerialDevice . PROTOCOL_RAW
2009-11-24 20:43:54 +03:00
2013-10-06 21:04:21 +04:00
if not self . widget ( " char-target-name " ) . get_visible ( ) :
target_name = None
if not typebox . get_visible ( ) :
target_type = None
2013-10-05 21:54:28 +04:00
if ( self . widget ( " char-auto-socket " ) . get_visible ( ) and
self . widget ( " char-auto-socket " ) . get_active ( ) ) :
source_path = None
source_mode = " bind "
2015-09-05 23:27:27 +03:00
if ( devclass . type == " tcp " and source_mode == " bind " ) :
devclass . bind_host = source_host
devclass . bind_port = source_port
source_host = source_port = source_mode = None
2009-11-24 20:43:54 +03:00
value_mappings = {
" source_path " : source_path ,
2014-03-25 18:42:34 +04:00
" source_channel " : source_channel ,
2011-08-30 23:03:27 +04:00
" source_mode " : source_mode ,
2009-11-24 20:43:54 +03:00
" source_host " : source_host ,
" source_port " : source_port ,
" bind_port " : bind_port ,
" bind_host " : bind_host ,
" protocol " : protocol ,
2011-04-05 03:35:31 +04:00
" target_name " : target_name ,
2013-10-05 19:28:41 +04:00
" target_type " : target_type ,
2009-11-24 20:43:54 +03:00
}
2009-01-23 01:00:10 +03:00
2009-11-24 20:43:54 +03:00
try :
self . _dev = devclass
2009-07-20 23:09:32 +04:00
2009-11-24 20:43:54 +03:00
for param_name , val in value_mappings . items ( ) :
2013-10-06 21:04:21 +04:00
if self . _dev . supports_property ( param_name ) and val is not None :
2009-11-24 20:43:54 +03:00
setattr ( self . _dev , param_name , val )
2007-07-14 21:48:24 +04:00
2009-11-24 20:43:54 +03:00
# Dump XML for sanity checking
self . _dev . get_xml_config ( )
2017-05-05 19:47:21 +03:00
except Exception as e :
2013-07-16 17:14:37 +04:00
return self . err . val_err (
_ ( " %s device parameter error " ) %
2015-05-19 22:18:30 +03:00
char_class . virtual_device_type . capitalize ( ) , e )
2007-09-26 04:05:45 +04:00
2015-05-19 22:18:30 +03:00
def _validate_page_video ( self ) :
2013-07-05 16:59:58 +04:00
conn = self . conn . get_backend ( )
2015-05-20 00:17:53 +03:00
model = uiutil . get_list_selection ( self . widget ( " video-model " ) )
2007-09-27 03:39:11 +04:00
2009-11-24 20:43:54 +03:00
try :
2013-07-06 04:14:57 +04:00
self . _dev = VirtualVideoDevice ( conn )
2013-07-15 19:07:40 +04:00
self . _dev . model = model
2017-05-05 19:47:21 +03:00
except Exception as e :
2011-08-30 22:50:50 +04:00
return self . err . val_err ( _ ( " Video device parameter error " ) , e )
2010-03-24 07:22:17 +03:00
2015-05-19 22:18:30 +03:00
def _validate_page_watchdog ( self ) :
2013-07-05 16:59:58 +04:00
conn = self . conn . get_backend ( )
2015-05-20 00:17:53 +03:00
model = uiutil . get_list_selection ( self . widget ( " watchdog-model " ) )
action = uiutil . get_list_selection ( self . widget ( " watchdog-action " ) )
2010-03-24 07:22:17 +03:00
try :
2013-07-06 04:14:57 +04:00
self . _dev = VirtualWatchdog ( conn )
2010-03-24 07:22:17 +03:00
self . _dev . model = model
self . _dev . action = action
2017-05-05 19:47:21 +03:00
except Exception as e :
2011-08-30 22:50:50 +04:00
return self . err . val_err ( _ ( " Watchdog parameter error " ) , e )
2009-01-23 01:00:26 +03:00
2015-05-19 22:18:30 +03:00
def _validate_page_filesystem ( self ) :
if self . _fsdetails . validate_page_filesystem ( ) is False :
2014-01-27 20:03:59 +04:00
return False
2015-05-19 22:18:30 +03:00
self . _dev = self . _fsdetails . get_dev ( )
2011-12-21 09:58:54 +04:00
2015-05-19 22:18:30 +03:00
def _validate_page_smartcard ( self ) :
2013-07-05 16:59:58 +04:00
conn = self . conn . get_backend ( )
2015-05-20 00:17:53 +03:00
mode = uiutil . get_list_selection ( self . widget ( " smartcard-mode " ) )
2011-06-23 19:42:03 +04:00
try :
2013-07-15 20:36:57 +04:00
self . _dev = VirtualSmartCardDevice ( conn )
self . _dev . mode = mode
2017-05-05 19:47:21 +03:00
except Exception as e :
2011-09-02 05:23:28 +04:00
return self . err . val_err ( _ ( " Smartcard device parameter error " ) , e )
2015-05-19 22:18:30 +03:00
def _validate_page_usbredir ( self ) :
2013-07-05 16:59:58 +04:00
conn = self . conn . get_backend ( )
2015-05-20 00:17:53 +03:00
stype = uiutil . get_list_selection ( self . widget ( " usbredir-list " ) )
2015-05-19 22:18:30 +03:00
host = None
service = None
if self . widget ( " usbredir-host " ) . is_visible ( ) :
host = self . widget ( " usbredir-host " ) . get_text ( )
service = uiutil . spin_get_helper ( self . widget ( " usbredir-service " ) )
2011-09-02 05:23:28 +04:00
try :
2013-07-15 20:57:37 +04:00
self . _dev = VirtualRedirDevice ( conn )
self . _dev . type = stype
2011-09-02 05:23:28 +04:00
if host :
self . _dev . host = host
if service :
self . _dev . service = service
2017-05-05 19:47:21 +03:00
except Exception as e :
2011-09-02 05:23:28 +04:00
return self . err . val_err ( _ ( " USB redirected device parameter error " ) ,
str ( e ) )
2011-06-23 19:42:03 +04:00
2015-05-19 22:18:30 +03:00
def _validate_page_tpm ( self ) :
2013-07-05 16:59:58 +04:00
conn = self . conn . get_backend ( )
2015-05-20 00:17:53 +03:00
typ = uiutil . get_list_selection ( self . widget ( " tpm-type " ) )
2013-06-26 05:45:09 +04:00
device_path = self . widget ( " tpm-device-path " ) . get_text ( )
value_mappings = {
" device_path " : device_path ,
}
try :
2013-07-15 20:18:23 +04:00
self . _dev = VirtualTPMDevice ( conn )
self . _dev . type = typ
2013-06-26 05:45:09 +04:00
for param_name , val in value_mappings . items ( ) :
if self . _dev . supports_property ( param_name ) :
setattr ( self . _dev , param_name , val )
2017-05-05 19:47:21 +03:00
except Exception as e :
2013-06-26 05:45:09 +04:00
return self . err . val_err ( _ ( " TPM device parameter error " ) , e )
2009-03-09 23:20:23 +03:00
2015-05-19 22:18:30 +03:00
def _validate_page_panic ( self ) :
2014-01-10 13:37:56 +04:00
conn = self . conn . get_backend ( )
iobase = self . widget ( " panic-iobase " ) . get_text ( )
value_mappings = {
" iobase " : iobase ,
}
try :
self . _dev = VirtualPanicDevice ( conn )
if not iobase :
iobase = self . _dev . IOBASE_DEFAULT
2014-01-12 01:08:42 +04:00
for param_name , val in value_mappings . items ( ) :
2014-01-10 13:37:56 +04:00
setattr ( self . _dev , param_name , val )
2017-05-05 19:47:21 +03:00
except Exception as e :
2014-01-10 13:37:56 +04:00
return self . err . val_err ( _ ( " Panic device parameter error " ) , e )
2015-05-19 22:18:30 +03:00
def _validate_page_controller ( self ) :
2014-04-26 18:40:17 +04:00
conn = self . conn . get_backend ( )
2015-05-19 22:18:30 +03:00
controller_type = uiutil . get_list_selection (
2015-05-20 00:17:53 +03:00
self . widget ( " controller-type " ) )
2015-05-20 00:54:53 +03:00
model = uiutil . get_list_selection ( self . widget ( " controller-model " ) )
2015-05-19 22:18:30 +03:00
2014-04-26 18:40:17 +04:00
self . _dev = VirtualController ( conn )
2014-06-16 07:48:22 +04:00
self . _selected_model = model
2014-04-26 18:40:17 +04:00
controllers = self . vm . get_controller_devices ( )
controller_num = [ x for x in controllers if
( x . type == controller_type ) ]
if len ( controller_num ) > 0 :
index_new = max ( [ x . index for x in controller_num ] ) + 1
self . _dev . index = index_new
self . _dev . type = controller_type
2014-06-16 07:48:22 +04:00
if model != " none " :
if model == " default " :
model = None
self . _dev . model = model
2015-05-19 22:18:30 +03:00
def _validate_page_rng ( self ) :
2015-05-20 00:17:53 +03:00
rtype = uiutil . get_list_selection ( self . widget ( " rng-type " ) )
2015-05-19 22:18:30 +03:00
backend_type = uiutil . get_list_selection (
2015-05-20 00:17:53 +03:00
self . widget ( " rng-backend-type " ) )
2015-05-19 22:18:30 +03:00
backend_mode = uiutil . get_list_selection (
2015-05-20 00:17:53 +03:00
self . widget ( " rng-backend-mode " ) )
2015-05-19 22:18:30 +03:00
connect_host = self . widget ( " rng-connect-host " ) . get_text ( )
connect_service = uiutil . spin_get_helper (
self . widget ( " rng-connect-service " ) )
bind_host = self . widget ( " rng-bind-host " ) . get_text ( )
bind_service = uiutil . spin_get_helper (
self . widget ( " rng-bind-service " ) )
2013-09-23 17:39:57 +04:00
2015-05-19 22:18:30 +03:00
device = self . widget ( " rng-device " ) . get_text ( )
if rtype == virtinst . VirtualRNGDevice . TYPE_RANDOM :
if not device :
2013-09-23 17:39:57 +04:00
return self . err . val_err ( _ ( " RNG selection error. " ) ,
_ ( " A device must be specified. " ) )
2015-05-19 22:18:30 +03:00
connect_host = None
connect_service = None
bind_host = None
bind_service = None
else :
device = None
2013-10-25 19:13:28 +04:00
2015-05-19 22:18:30 +03:00
if rtype == virtinst . VirtualRNGDevice . TYPE_EGD :
if ( backend_type == virtinst . VirtualRNGDevice . BACKEND_TYPE_UDP ) :
if not connect_host or not bind_host :
2013-10-25 19:13:28 +04:00
return self . err . val_err ( _ ( " RNG selection error. " ) ,
_ ( " Please specify both bind and connect host " ) )
2015-05-19 22:18:30 +03:00
if not connect_service or not bind_service :
2013-10-25 19:13:28 +04:00
return self . err . val_err ( _ ( " RNG selection error. " ) ,
_ ( " Please specify both bind and connect service " ) )
else :
2015-05-19 22:18:30 +03:00
if ( backend_mode ==
virtinst . VirtualRNGDevice . BACKEND_MODE_CONNECT ) :
bind_host = None
bind_service = None
else :
connect_host = None
connect_service = None
if not connect_host and not bind_host :
2013-10-25 19:13:28 +04:00
return self . err . val_err ( _ ( " RNG selection error. " ) ,
_ ( " The EGD host must be specified. " ) )
2015-05-19 22:18:30 +03:00
if not connect_service and not bind_service :
2013-10-25 19:13:28 +04:00
return self . err . val_err ( _ ( " RNG selection error. " ) ,
_ ( " The EGD service must be specified. " ) )
2013-09-23 17:39:57 +04:00
value_mappings = {
2015-05-19 22:18:30 +03:00
" backend_type " : backend_type ,
" backend_source_mode " : backend_mode ,
" connect_host " : connect_host ,
" connect_service " : connect_service ,
" bind_host " : bind_host ,
" bind_service " : bind_service ,
" device " : device ,
2013-09-23 17:39:57 +04:00
}
try :
2015-05-19 22:18:30 +03:00
self . _dev = virtinst . VirtualRNGDevice ( self . conn . get_backend ( ) )
self . _dev . type = rtype
2013-09-23 17:39:57 +04:00
for param_name , val in value_mappings . items ( ) :
if self . _dev . supports_property ( param_name ) :
setattr ( self . _dev , param_name , val )
2017-05-05 19:47:21 +03:00
except Exception as e :
2013-09-27 02:15:35 +04:00
return self . err . val_err ( _ ( " RNG device parameter error " ) , e )
2013-09-23 17:39:57 +04:00
2009-11-24 20:43:54 +03:00
####################
# Unsorted helpers #
####################
2009-03-09 23:20:23 +03:00
2014-01-29 01:53:11 +04:00
def _browse_storage_cb ( self , ignore , widget ) :
self . _browse_file ( widget )
2011-06-09 02:38:03 +04:00
def _browse_file ( self , textent , isdir = False ) :
2009-11-24 20:43:54 +03:00
def set_storage_cb ( src , path ) :
if path :
textent . set_text ( path )
2009-03-09 23:20:23 +03:00
2011-06-09 02:38:03 +04:00
reason = ( isdir and
self . config . CONFIG_DIR_FS or
self . config . CONFIG_DIR_IMAGE )
2015-05-19 22:18:30 +03:00
if self . _storagebrowser is None :
self . _storagebrowser = vmmStorageBrowser ( self . conn )
2009-03-09 23:20:23 +03:00
2015-05-19 22:18:30 +03:00
self . _storagebrowser . set_stable_defaults ( self . vm . stable_defaults ( ) )
self . _storagebrowser . set_finish_cb ( set_storage_cb )
self . _storagebrowser . set_browse_reason ( reason )
2009-11-24 20:43:54 +03:00
2015-05-19 22:18:30 +03:00
self . _storagebrowser . show ( self . topwin )