2007-04-12 23:36:04 +04:00
#
2014-01-20 20:09:13 +04:00
# Copyright (C) 2006-2007, 2013, 2014 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
2013-04-12 01:16:33 +04:00
# pylint: disable=E0611
2012-05-14 17:24:56 +04:00
from gi . repository import Gtk
from gi . repository import Gdk
2013-04-12 01:16:33 +04:00
# pylint: enable=E0611
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-01-27 03:15:50 +04:00
from virtManager import uiutil
2014-01-21 13:05:30 +04:00
from virtManager . fsdetails import vmmFSDetails
2014-01-29 03:44:40 +04:00
from virtManager . gfxdetails import vmmGraphicsDetails
2014-01-28 01:58:45 +04:00
from virtManager . netlist import vmmNetworkList
2007-04-12 23:36:04 +04:00
from virtManager . asyncjob import vmmAsyncJob
2009-03-09 23:19:39 +03:00
from virtManager . storagebrowse import vmmStorageBrowser
2010-12-09 01:26:19 +03:00
from virtManager . baseclass import vmmGObjectUI
2014-01-29 01:53:11 +04:00
from virtManager . addstorage import vmmAddStorage
2007-04-12 23:36:04 +04:00
2010-12-11 20:32:04 +03:00
PAGE_ERROR = 0
2007-04-12 23:36:04 +04:00
PAGE_DISK = 1
PAGE_NETWORK = 2
2007-09-26 04:05:45 +04:00
PAGE_INPUT = 3
2007-09-27 03:39:11 +04:00
PAGE_GRAPHICS = 4
2009-01-23 01:00:26 +03:00
PAGE_SOUND = 5
2009-03-09 23:20:23 +03:00
PAGE_HOSTDEV = 6
2009-07-14 17:25:39 +04:00
PAGE_CHAR = 7
2009-07-14 17:25:39 +04:00
PAGE_VIDEO = 8
2010-03-24 07:22:17 +03:00
PAGE_WATCHDOG = 9
2011-05-20 02:17:58 +04:00
PAGE_FILESYSTEM = 10
2011-06-23 19:42:03 +04:00
PAGE_SMARTCARD = 11
2011-09-02 05:23:28 +04:00
PAGE_USBREDIR = 12
2013-06-26 05:45:09 +04:00
PAGE_TPM = 13
2013-09-23 17:39:57 +04:00
PAGE_RNG = 14
2014-01-10 13:37:56 +04:00
PAGE_PANIC = 15
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
2009-03-09 23:19:39 +03:00
self . storage_browser = None
2009-07-14 17:25:39 +04:00
self . _dev = None
2014-01-29 03:44:40 +04:00
self . gfxdetails = vmmGraphicsDetails (
self . vm , self . builder , self . topwin )
self . widget ( " graphics-align " ) . add ( self . gfxdetails . top_box )
self . fsDetails = vmmFSDetails ( self . vm , self . builder , self . topwin )
2014-01-27 20:03:59 +04:00
self . widget ( " fs-box " ) . add ( self . fsDetails . top_box )
2014-01-29 01:53:11 +04:00
2014-01-28 01:58:45 +04: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 )
self . widget ( " config-storage-align " ) . add ( self . addstorage . top_box )
self . addstorage . connect ( " browse-clicked " , self . _browse_storage_cb )
self . addstorage . connect ( " storage-toggled " , self . toggle_storage_select )
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 ,
" on_create_finish_clicked " : self . finish ,
2013-09-23 00:29:58 +04:00
" on_hw_list_changed " : self . hw_selected ,
2009-11-24 21:14:55 +03:00
2014-01-13 01:52:26 +04:00
" on_config_storage_bustype_changed " : self . populate_disk_device ,
2009-11-24 21:14:55 +03:00
2007-05-24 23:51:32 +04:00
" on_mac_address_clicked " : self . change_macaddr_use ,
2009-11-24 21:14:55 +03:00
2009-07-14 17:25:39 +04:00
" on_char_device_type_changed " : self . change_char_device_type ,
2013-10-05 21:27:11 +04:00
" on_char_target_name_changed " : self . change_char_target_name ,
2013-10-05 21:54:28 +04:00
" on_char_auto_socket_toggled " : self . change_char_auto_socket ,
2009-07-14 17:25:39 +04:00
2013-06-26 05:45:09 +04:00
" on_tpm_device_type_changed " : self . change_tpm_device_type ,
2011-09-02 05:23:28 +04:00
" on_usbredir_type_changed " : self . change_usbredir_type ,
2013-09-23 17:39:57 +04:00
2013-10-25 19:13:28 +04:00
" on_rng_type_changed " : self . change_rng ,
" on_rng_backend_mode_changed " : self . change_rng ,
" on_rng_backend_type_changed " : self . change_rng ,
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
2013-09-22 20:18:49 +04:00
self . set_initial_state ( )
2011-04-14 16:47:42 +04:00
def show ( self , parent ) :
2012-02-01 03:16:54 +04:00
logging . debug ( " Showing addhw " )
2007-04-12 23:36:04 +04: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 ,
pollnodedev = True , pollmedia = True )
2007-04-12 23:36:04 +04:00
2010-11-29 22:06:43 +03:00
def close ( self , ignore1 = None , ignore2 = None ) :
2012-02-01 03:16:54 +04:00
logging . debug ( " Closing addhw " )
2009-11-24 20:43:54 +03:00
self . topwin . hide ( )
2011-04-12 02:35:21 +04:00
if self . storage_browser :
self . storage_browser . close ( )
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
2011-07-24 05:16:54 +04:00
if self . storage_browser :
self . storage_browser . cleanup ( )
self . storage_browser = None
2011-04-12 02:35:21 +04:00
2014-01-29 03:44:40 +04:00
self . gfxdetails . cleanup ( )
self . gfxdetails = None
2014-01-21 13:05:30 +04:00
self . fsDetails . cleanup ( )
2014-01-28 01:58:45 +04:00
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 #
##########################
2007-04-12 23:36:04 +04: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
2012-05-14 17:24:56 +04: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
widget = self . widget ( " config-storage-bustype " )
# [bus, label]
model = Gtk . ListStore ( str , str )
widget . set_model ( model )
2014-01-27 03:15:50 +04:00
uiutil . set_combo_text_column ( widget , 1 )
2014-01-13 01:52:26 +04:00
# Disk device type
2011-07-14 21:13:13 +04:00
target_list = self . widget ( " config-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 )
2007-07-14 21:48:24 +04:00
2010-05-20 16:34:32 +04:00
# Disk cache mode
2011-07-14 21:13:13 +04:00
cache_list = self . widget ( " config-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
2010-12-11 03:20:14 +03:00
# Disk format mode
2014-01-27 02:09:07 +04:00
self . populate_disk_format_combo_wrapper ( True )
2010-12-11 03:20:14 +03: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 )
2014-01-27 04:18:22 +04:00
uiutil . set_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
2010-12-11 23:12:22 +03:00
# model = [ Description, nodedev name ]
2011-07-14 21:13:13 +04:00
host_dev = self . widget ( " host-device " )
2013-04-30 18:53:10 +04:00
host_dev_model = Gtk . ListStore ( str , str , str , object )
2009-03-09 23:20:23 +03:00
host_dev . set_model ( host_dev_model )
2010-12-11 23:12:22 +03:00
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 )
2014-01-27 04:18:22 +04:00
uiutil . set_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 )
2014-01-27 03:15:50 +04:00
uiutil . set_combo_text_column ( lst , 1 )
2013-10-05 19:28:41 +04:00
if self . conn . is_qemu ( ) :
model . append ( [ " virtio " , " virtio " ] )
else :
model . append ( [ None , " default " ] )
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 )
2014-01-27 03:15:50 +04:00
uiutil . set_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 )
2014-01-27 03:15:50 +04:00
uiutil . set_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 " )
self . build_rng_type_combo ( combo )
combo = self . widget ( " rng-backend-type " )
self . build_rng_backend_type_combo ( combo )
combo = self . widget ( " rng-backend-mode " )
self . build_rng_backend_mode_combo ( combo )
2014-01-10 13:37:56 +04:00
# Panic widgets
combo = self . widget ( " panic-type " )
self . build_panic_address_type ( combo )
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 ] )
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 17:24:56 +04: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 " )
2012-05-14 17:24:56 +04: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 " )
2013-10-05 19:28:41 +04:00
add_hw_option ( " Console " , Gtk . STOCK_CONNECT , PAGE_CHAR ,
True , None , " console " )
2012-05-14 17:24:56 +04: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 " )
2010-12-11 23:55:31 +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 " )
add_hw_option ( " PCI 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 " ) ,
" pci " )
add_hw_option ( " Video " , " video-display " , PAGE_VIDEO ,
2013-10-06 18:08:04 +04:00
self . conn . check_support (
2013-07-06 19:20:28 +04:00
self . conn . SUPPORT_CONN_DOMAIN_VIDEO ) ,
2010-12-11 23:55:31 +03:00
_ ( " 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 17:24:56 +04:00
add_hw_option ( " Filesystem " , Gtk . STOCK_DIRECTORY , PAGE_FILESYSTEM ,
2013-10-06 18:08:04 +04:00
self . conn . check_support (
2013-10-03 00:41:23 +04:00
self . conn . SUPPORT_CONN_FILESYSTEM ) ,
2011-05-20 02:17:58 +04:00
_ ( " Not supported for this hypervisor/libvirt "
" combination. " ) )
2011-06-23 19:42:03 +04:00
add_hw_option ( " Smartcard " , " device_serial " , PAGE_SMARTCARD ,
True , None )
2011-09-02 05:23:28 +04:00
add_hw_option ( " USB Redirection " , " device_usb " , PAGE_USBREDIR ,
True , None )
2013-06-26 05:45:09 +04:00
add_hw_option ( " TPM " , " device_cpu " , PAGE_TPM ,
True , None )
2013-09-23 17:39:57 +04:00
add_hw_option ( " RNG " , " system-run " , PAGE_RNG , True , None )
2014-01-13 00:16:06 +04:00
add_hw_option ( " Panic Notifier " , " system-run " , PAGE_PANIC ,
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
def reset_state ( self ) :
2009-07-09 02:49:25 +04:00
# Storage init
2014-01-27 02:09:07 +04:00
self . populate_disk_format_combo_wrapper ( True )
2014-01-13 01:52:26 +04:00
self . populate_disk_bus ( )
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 )
2009-07-09 02:49:25 +04:00
self . change_macaddr_use ( )
2009-11-24 21:14:55 +03:00
2014-01-28 01:58:45 +04: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 " )
2007-09-26 04:05:45 +04:00
self . populate_input_model ( input_box . get_model ( ) )
input_box . set_active ( 0 )
2009-07-09 02:49:25 +04:00
# Graphics init
2014-01-29 03:44:40 +04: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 ( " " )
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
2014-01-21 13:05:30 +04:00
self . fsDetails . reset_state ( )
2011-05-20 02:17:58 +04:00
2012-02-09 03:20:59 +04:00
# Video params
2014-01-27 02:09:07 +04:00
self . populate_video_combo ( self . vm , self . widget ( " video-model " ) )
2012-02-09 03:20:59 +04:00
2013-07-15 20:18:23 +04:00
# TPM paams
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 " )
2010-12-11 20:32:04 +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
def populate_video_combo ( vm , combo , no_default = None ) :
model = combo . get_model ( )
has_spice = bool ( [ g for g in vm . get_graphics_devices ( )
if g . type == g . TYPE_SPICE ] )
has_qxl = bool ( [ v for v in vm . get_video_devices ( )
if v . model == " qxl " ] )
model . clear ( )
tmpdev = virtinst . VirtualVideoDevice ( vm . conn . get_backend ( ) )
for m in tmpdev . MODELS :
if vm . stable_defaults ( ) :
if m == " qxl " and not has_spice and not has_qxl :
# Only list QXL video option when VM has SPICE video
continue
if m == tmpdev . MODEL_DEFAULT and no_default :
continue
model . append ( [ m , tmpdev . pretty_model ( m ) ] )
if len ( model ) > 0 :
combo . set_active ( 0 )
@staticmethod
def build_video_combo ( vm , combo , no_default = None ) :
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2014-01-27 03:15:50 +04:00
uiutil . set_combo_text_column ( combo , 1 )
2014-01-27 02:09:07 +04:00
combo . get_model ( ) . set_sort_column_id ( 1 , Gtk . SortType . ASCENDING )
vmmAddHardware . populate_video_combo ( vm , combo , no_default )
@staticmethod
def build_sound_combo ( vm , combo , no_default = False ) :
model = Gtk . ListStore ( str )
combo . set_model ( model )
2014-01-27 03:15:50 +04:00
uiutil . set_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 ( )
stable_soundmodels = [ " ich6 " , " ac97 " ]
for m in virtinst . VirtualAudio . MODELS :
if m == virtinst . VirtualAudio . MODEL_DEFAULT and no_default :
continue
if ( stable_defaults and m not in stable_soundmodels ) :
continue
model . append ( [ m ] )
if len ( model ) > 0 :
combo . set_active ( 0 )
@staticmethod
def build_watchdogmodel_combo ( vm , combo , no_default = False ) :
ignore = vm
model = Gtk . ListStore ( str )
combo . set_model ( model )
2014-01-27 03:15:50 +04:00
uiutil . set_combo_text_column ( combo , 0 )
2014-01-27 02:09:07 +04:00
model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
for m in virtinst . VirtualWatchdog . MODELS :
if m == virtinst . VirtualAudio . MODEL_DEFAULT and no_default :
continue
model . append ( [ m ] )
if len ( model ) > 0 :
combo . set_active ( 0 )
@staticmethod
def build_watchdogaction_combo ( vm , combo , no_default = False ) :
ignore = vm
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2014-01-27 03:15:50 +04:00
uiutil . set_combo_text_column ( combo , 1 )
2014-01-27 02:09:07 +04:00
model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
for m in virtinst . VirtualWatchdog . ACTIONS :
if m == virtinst . VirtualWatchdog . ACTION_DEFAULT and no_default :
continue
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 ( ) :
mod_list = [ " rtl8139 " , " ne2k_pci " , " pcnet " , " e1000 " ]
if vm . get_hv_type ( ) in [ " kvm " , " qemu " , " test " ] :
mod_list . append ( " virtio " )
if ( vm . get_hv_type ( ) == " kvm " and
vm . get_machtype ( ) == " pseries " ) :
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 )
2014-01-27 03:15:50 +04:00
uiutil . set_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]
model . append ( [ " passthrough " , " Passthrough " ] )
model . append ( [ " host " , " Host " ] )
@staticmethod
def build_smartcard_mode_combo ( vm , combo ) :
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2014-01-27 03:15:50 +04:00
uiutil . set_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]
model . append ( [ " spicevmc " , " Spice channel " , False ] )
model . append ( [ " tcp " , " TCP " , True ] )
@staticmethod
def build_redir_type_combo ( vm , combo ) :
model = Gtk . ListStore ( str , str , bool )
combo . set_model ( model )
2014-01-27 03:15:50 +04:00
uiutil . set_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 )
2014-01-27 03:15:50 +04:00
uiutil . set_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_graphics_keymap_combo ( vm , combo , no_default = False ) :
ignore = vm
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2014-01-27 03:15:50 +04:00
uiutil . set_combo_text_column ( combo , 1 )
2014-01-27 02:09:07 +04:00
if not no_default :
model . append ( [ None , " default " ] )
else :
model . append ( [ None , " Auto " ] )
model . append ( [ virtinst . VirtualGraphics . KEYMAP_LOCAL ,
" Copy local keymap " ] )
for k in virtinst . VirtualGraphics . valid_keymaps ( ) :
model . append ( [ k , k ] )
combo . set_active ( - 1 )
@staticmethod
def build_disk_cache_combo ( vm , combo ) :
ignore = vm
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2014-01-27 03:15:50 +04:00
uiutil . set_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 ] )
_iter = model . insert ( 0 , [ None , " default " ] )
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 )
2014-01-27 03:15:50 +04:00
uiutil . set_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 :
model . append ( [ None , " default " ] )
combo . set_active ( 0 )
@staticmethod
def build_disk_bus_combo ( vm , combo , no_default = False ) :
ignore = vm
model = Gtk . ListStore ( str , str )
combo . set_model ( model )
2014-01-27 03:15:50 +04:00
uiutil . set_combo_text_column ( combo , 1 )
2014-01-27 02:09:07 +04:00
model . set_sort_column_id ( 1 , Gtk . SortType . ASCENDING )
if not no_default :
model . append ( [ None , " default " ] )
combo . set_active ( - 1 )
@staticmethod
def populate_disk_format_combo ( vm , combo , create ) :
model = Gtk . ListStore ( str )
combo . set_model ( model )
2014-01-27 03:15:50 +04:00
uiutil . set_combo_text_column ( combo , 0 )
2014-01-27 02:09:07 +04:00
formats = [ " raw " , " qcow2 " , " qed " ]
no_create_formats = [ ]
if not vm . stable_defaults ( ) :
formats . append ( " vmdk " )
no_create_formats . append ( " vdi " )
for m in formats :
model . append ( [ m ] )
if not create :
for m in no_create_formats :
model . append ( [ m ] )
if create :
2014-01-29 01:53:11 +04:00
fmt = vm . conn . get_default_storage_format ( )
2014-01-27 02:09:07 +04:00
combo . set_active ( 0 )
2014-01-29 01:53:11 +04:00
for row in model :
if row [ 0 ] == fmt :
combo . set_active_iter ( row . iter )
break
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
2014-01-13 01:52:26 +04:00
def populate_disk_bus ( self ) :
widget = self . widget ( " config-storage-bustype " )
model = widget . get_model ( )
2009-11-24 20:43:54 +03:00
model . clear ( )
if self . vm . is_hvm ( ) :
2014-01-13 01:52:26 +04:00
model . append ( [ " ide " , " IDE " ] )
model . append ( [ " fdc " , " Floppy " ] )
2010-12-13 22:31:27 +03:00
2014-01-28 14:26:35 +04:00
if not self . vm . stable_defaults ( ) :
2014-01-13 01:52:26 +04:00
model . append ( [ " scsi " , " SCSI " ] )
model . append ( [ " usb " , " USB " ] )
2013-08-18 01:59:17 +04:00
if self . vm . get_hv_type ( ) in [ " qemu " , " kvm " , " test " ] :
2014-01-13 01:52:26 +04:00
model . append ( [ " sata " , " SATA " ] )
model . append ( [ " sd " , " SD " ] )
model . append ( [ " virtio " , " Virtio " ] )
model . append ( [ " virtio-scsi " , " Virtio SCSI " ] )
2012-11-27 19:42:35 +04:00
if self . conn . is_xen ( ) or self . conn . is_test_conn ( ) :
2014-01-13 01:52:26 +04:00
model . append ( [ " xen " , " Xen " ] )
if len ( model ) > 0 :
widget . set_active ( 0 )
def populate_disk_device ( self , src ) :
ignore = src
bus = self . get_config_disk_bus ( )
devlist = self . widget ( " config-storage-devtype " )
model = devlist . get_model ( )
model . clear ( )
disk_buses = [ " ide " , " sata " , " scsi " , " sd " ,
" usb " , " virtio " , " virtio-scsi " , " xen " ]
floppy_buses = [ " fdc " ]
cdrom_buses = [ " ide " , " scsi " ]
2014-01-21 05:24:05 +04:00
lun_buses = [ " virtio-scsi " ]
2014-01-13 01:52:26 +04:00
if bus in disk_buses :
model . append ( [ virtinst . VirtualDisk . DEVICE_DISK ,
" drive-harddisk " , _ ( " Disk device " ) ] )
if bus in floppy_buses :
model . append ( [ virtinst . VirtualDisk . DEVICE_FLOPPY ,
" media-floppy " , _ ( " Floppy device " ) ] )
if bus in cdrom_buses :
model . append ( [ virtinst . VirtualDisk . DEVICE_CDROM ,
" media-cdrom " , _ ( " CDROM device " ) ] )
if bus in lun_buses :
model . append ( [ virtinst . VirtualDisk . DEVICE_LUN ,
" drive-harddisk " , _ ( " LUN device " ) ] )
if len ( model ) > 0 :
devlist . set_active ( 0 )
2009-11-24 20:43:54 +03:00
def populate_input_model ( self , model ) :
model . clear ( )
2012-11-27 19:44:13 +04:00
model . append ( [ _ ( " EvTouch USB Graphics Tablet " ) , " tablet " , " usb " ] )
model . append ( [ _ ( " Generic USB Mouse " ) , " mouse " , " usb " ] )
2009-11-24 20:43:54 +03:00
2010-12-11 23:55:31 +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 :
2011-04-12 02:35:21 +04:00
subdevs = self . conn . get_nodedevs ( subtype , subcap )
2009-11-24 20:43:54 +03:00
2011-04-12 02:35:21 +04:00
devs = self . conn . get_nodedevs ( devtype , devcap )
2009-11-24 20:43:54 +03:00
for dev in devs :
prettyname = dev . pretty_name ( )
for subdev in subdevs :
if dev . name == subdev . parent :
2014-01-12 23:52:15 +04:00
prettyname + = " ( %s ) " % subdev . pretty_name ( )
2009-11-24 20:43:54 +03:00
2013-04-30 18:53:10 +04:00
model . append ( [ prettyname , dev . name , devtype , dev ] )
2009-11-24 20:43:54 +03:00
if len ( model ) == 0 :
2013-09-09 19:04:08 +04:00
model . append ( [ _ ( " No Devices Available " ) , None , None , None ] )
2014-01-27 03:15:50 +04:00
uiutil . set_list_selection ( devlist , 0 )
2009-11-24 20:43:54 +03:00
2014-01-27 02:09:07 +04:00
def populate_disk_format_combo_wrapper ( self , create ) :
2013-08-20 11:15:47 +04:00
format_list = self . widget ( " config-storage-format " )
2014-01-27 02:09:07 +04:00
self . populate_disk_format_combo ( self . vm , format_list , create )
2013-08-20 11:15:47 +04:00
if not create :
format_list . get_child ( ) . set_text ( " " )
2014-01-29 01:53:11 +04:00
2009-11-24 20:43:54 +03:00
########################
2013-09-24 18:00:01 +04:00
# get_config_* methods #
########################
2013-09-23 17:39:57 +04:00
def build_combo_with_values ( self , combo , values , default = None ) :
dev_model = Gtk . ListStore ( str , str )
combo . set_model ( dev_model )
2014-01-27 04:18:22 +04:00
uiutil . set_combo_text_column ( combo , 1 )
2013-09-23 17:39:57 +04:00
dev_model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
types = combo . get_model ( )
types . clear ( )
# [xml value, label]
for t in values :
types . append ( t [ 0 : 2 ] )
if default :
idx = - 1
for rowid in range ( len ( combo . get_model ( ) ) ) :
idx = 0
row = combo . get_model ( ) [ rowid ]
if row [ 0 ] == default :
idx = rowid
break
combo . set_active ( idx )
def build_rng_type_combo ( self , combo ) :
types = [ ]
for t in virtinst . VirtualRNGDevice . TYPES :
types . append ( [ t , virtinst . VirtualRNGDevice . get_pretty_type ( t ) ] )
self . build_combo_with_values ( combo , types ,
virtinst . VirtualRNGDevice . TYPE_RANDOM )
def build_rng_backend_type_combo ( self , combo ) :
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 ] )
self . build_combo_with_values ( combo , types , default )
def build_rng_backend_mode_combo ( self , combo ) :
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 ] )
self . build_combo_with_values ( combo , types , default )
2014-01-10 13:37:56 +04:00
def build_panic_address_type ( self , combo ) :
types = [ ]
for t in virtinst . VirtualPanicDevice . TYPES :
types . append ( [ t , virtinst . VirtualPanicDevice . get_pretty_type ( t ) ] )
self . build_combo_with_values ( combo , types ,
virtinst . VirtualPanicDevice . ADDRESS_TYPE_ISA )
2007-04-12 23:36:04 +04:00
def get_config_hardware_type ( self ) :
2010-12-11 20:32:04 +03:00
row = self . get_hw_selection ( )
if not row :
2007-04-12 23:36:04 +04:00
return None
2010-12-11 20:32:04 +03:00
return row [ 2 ]
2007-04-12 23:36:04 +04:00
2009-11-24 20:43:54 +03:00
# Disk getters
2014-01-13 01:52:26 +04:00
def get_config_disk_bus ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection (
self . widget ( " config-storage-bustype " ) , 0 )
2010-03-04 23:35:34 +03:00
2014-01-13 01:52:26 +04:00
def get_config_disk_device ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection (
self . widget ( " config-storage-devtype " ) , 0 )
2007-07-14 21:48:24 +04:00
2014-01-13 01:52:26 +04:00
def get_config_disk_cache ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection (
self . widget ( " config-storage-cache " ) , 0 )
2010-05-20 16:34:32 +04:00
2010-12-11 03:20:14 +03:00
def get_config_disk_format ( self ) :
2011-07-14 21:13:13 +04:00
fmt = self . widget ( " config-storage-format " )
2012-05-14 17:24:56 +04:00
return fmt . get_child ( ) . get_text ( )
2010-12-11 03:20:14 +03:00
2009-11-24 20:43:54 +03:00
# Input getters
2007-09-26 04:05:45 +04:00
def get_config_input ( self ) :
2014-01-27 05:21:12 +04:00
row = uiutil . get_list_selection ( self . widget ( " input-type " ) )
return row [ 1 ] , row [ 2 ]
2007-09-26 04:05:45 +04:00
2009-11-24 20:43:54 +03:00
# Network getters
2009-01-23 01:00:10 +03:00
def get_config_net_model ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection ( self . widget ( " net-model " ) ) [ 0 ]
2009-01-23 01:00:10 +03:00
2007-05-24 23:51:32 +04:00
def get_config_macaddr ( self ) :
macaddr = None
2011-07-14 21:13:13 +04:00
if self . widget ( " mac-address " ) . get_active ( ) :
macaddr = self . widget ( " create-mac-address " ) . get_text ( )
2007-05-24 23:51:32 +04:00
return macaddr
2009-11-24 20:43:54 +03:00
# Sound getters
2009-01-23 01:00:26 +03:00
def get_config_sound_model ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection ( self . widget ( " sound-model " ) , 0 )
2009-01-23 01:00:26 +03:00
2009-11-24 20:43:54 +03:00
# Host device getters
2009-03-09 23:20:23 +03:00
def get_config_host_device_type_info ( self ) :
2010-12-11 23:55:31 +03: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 23:20:23 +03:00
def get_config_host_device_info ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection ( self . widget ( " host-device " ) )
2009-03-09 23:20:23 +03:00
2009-11-24 20:43:54 +03:00
# Video Getters
2009-07-14 17:25:39 +04:00
def get_config_video_model ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection ( self . widget ( " video-model " ) , 0 )
2009-07-14 17:25:39 +04:00
2010-03-24 07:22:17 +03:00
# Watchdog getters
def get_config_watchdog_model ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection ( self . widget ( " watchdog-model " ) , 0 )
2010-03-24 07:22:17 +03:00
def get_config_watchdog_action ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection ( self . widget ( " watchdog-action " ) , 0 )
2009-11-24 20:43:54 +03:00
2011-06-23 19:42:03 +04:00
# Smartcard getters
def get_config_smartcard_mode ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection ( self . widget ( " smartcard-mode " ) , 0 )
2011-06-23 19:42:03 +04:00
2011-09-02 05:23:28 +04:00
# USB redir getters
def get_config_usbredir_host ( self ) :
host = self . widget ( " usbredir-host " )
service = self . widget ( " usbredir-service " )
2013-09-09 19:17:01 +04:00
if not host . get_visible ( ) :
return None , None
2011-09-02 05:23:28 +04:00
2013-09-09 19:17:01 +04:00
return host . get_text ( ) , int ( service . get_value ( ) )
2011-09-02 05:23:28 +04:00
def get_config_usbredir_type ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection ( self . widget ( " usbredir-list " ) , 0 )
2011-09-02 05:23:28 +04:00
2013-06-26 05:45:09 +04:00
# TPM getters
def get_config_tpm_type ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection ( self . widget ( " tpm-type " ) , 0 )
2013-06-26 05:45:09 +04:00
2013-09-23 17:39:57 +04:00
# RNG getters
def get_config_rng_type ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection ( self . widget ( " rng-type " ) , 0 )
2013-09-23 17:39:57 +04:00
def get_config_rng_device ( self ) :
if self . get_config_rng_type ( ) == virtinst . VirtualRNGDevice . TYPE_RANDOM :
return self . widget ( " rng-device " ) . get_text ( )
return None
2013-10-25 19:13:28 +04:00
def get_config_rng_host ( self , is_connect = False ) :
connect_mode = virtinst . VirtualRNGDevice . BACKEND_MODE_CONNECT in \
self . get_config_rng_backend_mode ( )
is_udp = self . get_config_rng_backend_type ( ) == \
virtinst . VirtualRNGDevice . BACKEND_TYPE_UDP
if connect_mode == is_connect or is_udp :
widget_name = " rng-connect-host " if is_connect else " rng-bind-host "
return self . widget ( widget_name ) . get_text ( )
2013-09-23 17:39:57 +04:00
return None
2013-10-25 19:13:28 +04:00
def get_config_rng_service ( self , is_connect = False ) :
connect_mode = virtinst . VirtualRNGDevice . BACKEND_MODE_CONNECT in \
self . get_config_rng_backend_mode ( )
is_udp = self . get_config_rng_backend_type ( ) == \
virtinst . VirtualRNGDevice . BACKEND_TYPE_UDP
if connect_mode == is_connect or is_udp :
if is_connect :
widget_name = " rng-connect-service "
else :
widget_name = " rng-bind-service "
return self . widget ( widget_name ) . get_text ( )
2013-09-23 17:39:57 +04:00
return None
def get_config_rng_backend_type ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection ( self . widget ( " rng-backend-type " ) , 0 )
2013-09-23 17:39:57 +04:00
def get_config_rng_backend_mode ( self ) :
2014-01-27 05:21:12 +04:00
return uiutil . get_list_selection ( self . widget ( " rng-backend-mode " ) , 0 )
2013-09-23 17:39:57 +04:00
2009-11-24 20:43:54 +03:00
################
# UI listeners #
################
2010-12-11 20:32:04 +03:00
def set_hw_selection ( self , page ) :
2014-01-27 03:15:50 +04:00
uiutil . set_list_selection ( self . widget ( " hw-list " ) , page )
2009-11-24 20:43:54 +03:00
2010-12-11 20:32:04 +03:00
def get_hw_selection ( self ) :
2014-01-27 03:15:50 +04:00
return uiutil . get_list_selection ( self . widget ( " hw-list " ) )
2009-11-24 20:43:54 +03:00
2011-04-05 03:35:32 +04: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 ( )
2013-07-16 17:14:37 +04:00
char_class = self . get_char_type ( )
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 )
2010-12-11 20:32:04 +03:00
def hw_selected ( self , src = None ) :
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
2010-12-11 20:32:04 +03:00
row = self . get_hw_selection ( )
if not row :
self . set_hw_selection ( 0 )
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
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 :
2011-04-05 03:35:32 +04:00
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 :
( ignore , devtype , devcap ,
subtype , subcap ) = self . get_config_host_device_type_info ( )
self . populate_host_device_model ( devtype , devcap ,
subtype , subcap )
2010-12-11 21:05:07 +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
2011-12-22 22:10:17 +04:00
2009-11-24 20:43:54 +03:00
# Storage listeners
2014-01-29 01:53:11 +04:00
def toggle_storage_select ( self , ignore , src ) :
2010-03-04 23:35:34 +03:00
act = src . get_active ( )
2014-01-27 02:09:07 +04:00
self . populate_disk_format_combo_wrapper ( not act )
2010-03-04 23:35:34 +03:00
2009-11-24 20:43:54 +03:00
# Network listeners
2007-05-24 23:51:32 +04:00
def change_macaddr_use ( self , ignore = None ) :
2011-07-14 21:13:13 +04:00
if self . widget ( " mac-address " ) . get_active ( ) :
self . widget ( " create-mac-address " ) . set_sensitive ( True )
2007-05-24 23:51:32 +04:00
else :
2011-07-14 21:13:13 +04:00
self . widget ( " create-mac-address " ) . set_sensitive ( False )
2007-05-24 23:51:32 +04:00
2009-11-24 20:43:54 +03:00
# Char device listeners
2009-07-14 17:25:39 +04:00
def get_char_type ( self ) :
2010-12-11 20:32:04 +03:00
row = self . get_hw_selection ( )
label = " serial "
if row :
2010-12-11 23:55:31 +03:00
label = row [ 5 ]
2009-07-14 17:25:39 +04:00
2010-12-11 23:55:31 +03:00
if label == " parallel " :
2013-07-16 17:14:37 +04:00
return VirtualParallelDevice
2011-04-05 03:35:32 +04:00
elif label == " channel " :
2013-07-16 17:14:37 +04:00
return VirtualChannelDevice
2013-10-05 19:28:41 +04:00
elif label == " console " :
return VirtualConsoleDevice
2013-07-16 17:14:37 +04:00
return VirtualSerialDevice
2009-07-14 17:25:39 +04:00
2010-12-11 21:05:07 +03: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-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 :
2013-07-16 17:14:37 +04:00
char_class = self . get_char_type ( )
return char_class . virtual_device_type . capitalize ( ) + " Device "
2010-12-11 23:55:31 +03:00
if page == PAGE_HOSTDEV :
return self . get_config_host_device_type_info ( ) [ 0 ]
raise RuntimeError ( " Unknown page %s " % page )
2010-12-11 21:05:07 +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
2013-06-26 05:45:09 +04:00
def change_tpm_device_type ( self , src ) :
2014-01-27 05:21:12 +04:00
devtype = uiutil . get_list_selection ( src , 0 )
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
2013-10-05 21:54:28 +04:00
def change_char_auto_socket ( self , src ) :
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
2013-10-05 21:27:11 +04:00
def change_char_target_name ( self , src ) :
if not src . get_visible ( ) :
return
text = src . get_child ( ) . get_text ( )
settype = None
if text == VirtualChannelDevice . CHANNEL_NAME_SPICE :
settype = " spicevmc "
elif ( text == VirtualChannelDevice . CHANNEL_NAME_QEMUGA or
text == VirtualChannelDevice . CHANNEL_NAME_LIBGUESTFS ) :
settype = " unix "
2014-01-27 03:15:50 +04:00
uiutil . set_row_selection ( self . widget ( " char-device-type " ) , settype )
2013-10-05 21:27:11 +04:00
2009-07-14 17:25:39 +04:00
def change_char_device_type ( self , src ) :
2014-01-27 05:21:12 +04:00
devtype = uiutil . get_list_selection ( src , 0 )
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 " ,
" source_mode " : " char-mode " ,
" source_host " : " char-host " ,
" bind_host " : " char-bind-host " ,
" protocol " : " char-use-telnet " ,
}
2013-07-16 17:14:37 +04:00
char_class = self . get_char_type ( )
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
2011-09-02 05:23:28 +04:00
def change_usbredir_type ( self , src ) :
2014-01-27 05:21:12 +04:00
showhost = uiutil . get_list_selection ( src , 2 )
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
2013-10-25 19:13:28 +04:00
def change_rng ( self , ignore1 ) :
2013-09-23 17:39:57 +04:00
model = self . get_config_rng_type ( )
if model is None :
return
is_egd = model == 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
2013-10-25 19:13:28 +04:00
backend_type = self . get_config_rng_backend_type ( )
backend_mode = self . get_config_rng_backend_mode ( )
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
2013-09-07 04:59:01 +04:00
def setup_device ( self , asyncjob ) :
logging . debug ( " Running setup for device= %s " , self . _dev )
self . _dev . setup ( meter = asyncjob . get_meter ( ) )
logging . debug ( " Setup complete " )
2008-03-14 20:18:44 +03:00
2010-02-06 23:59:52 +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
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 )
2009-11-24 20:43:54 +03:00
except Exception , 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 )
2009-11-24 20:43:54 +03:00
except Exception , e :
2011-04-06 19:22:03 +04: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 :
failure = self . add_device ( )
except Exception , e :
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 )
self . topwin . set_sensitive ( True )
self . topwin . get_window ( ) . set_cursor (
Gdk . Cursor . new ( Gdk . CursorType . TOP_LEFT_ARROW ) )
self . _dev = None
if not failure :
self . close ( )
2010-02-06 23:59:52 +03:00
2013-09-07 04:59:01 +04:00
def finish ( self , ignore = None ) :
notebook = self . widget ( " create-pages " )
try :
if self . validate ( notebook . get_current_page ( ) ) is False :
return
except Exception , e :
self . err . show_err ( _ ( " Uncaught error validating hardware "
" input: %s " ) % str ( e ) )
return
self . topwin . set_sensitive ( False )
self . topwin . get_window ( ) . set_cursor (
Gdk . Cursor . new ( Gdk . CursorType . WATCH ) )
progWin = vmmAsyncJob ( self . setup_device , [ ] ,
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 #
###########################
2013-10-06 20:55:21 +04:00
def _validate ( self , page_num ) :
2010-12-11 20:32:04 +03:00
if page_num == PAGE_ERROR :
self . _dev = None
return True
2009-11-24 20:43:54 +03: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 23:33:32 +03:00
return self . validate_page_input ( )
2009-11-24 20:43:54 +03:00
elif page_num == PAGE_GRAPHICS :
return self . validate_page_graphics ( )
elif page_num == PAGE_SOUND :
return self . validate_page_sound ( )
2009-03-09 23:20:23 +03:00
elif page_num == PAGE_HOSTDEV :
2009-11-24 20:43:54 +03: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 07:22:17 +03:00
elif page_num == PAGE_WATCHDOG :
return self . validate_page_watchdog ( )
2011-05-20 02:17:58 +04:00
elif page_num == PAGE_FILESYSTEM :
return self . validate_page_filesystem ( )
2011-06-23 19:42:03 +04:00
elif page_num == PAGE_SMARTCARD :
return self . validate_page_smartcard ( )
2011-09-02 05:23:28 +04:00
elif page_num == PAGE_USBREDIR :
return self . validate_page_usbredir ( )
2013-06-26 05:45:09 +04:00
elif page_num == PAGE_TPM :
return self . validate_page_tpm ( )
2013-09-23 17:39:57 +04:00
elif page_num == PAGE_RNG :
return self . validate_page_rng ( )
2014-01-10 13:37:56 +04:00
elif page_num == PAGE_PANIC :
return self . validate_page_panic ( )
2009-03-09 23:20:23 +03:00
2013-10-06 20:55:21 +04:00
def validate ( self , page_num ) :
ret = self . _validate ( page_num )
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-01-29 01:53:11 +04:00
def _set_disk_controller ( self , disk , controller_model ) :
# Add a SCSI controller with model virtio-scsi if needed
disk . vmm_controller = None
if controller_model != " virtio-scsi " :
return
controllers = self . vm . get_controller_devices ( )
ctrls_scsi = [ x for x in controllers if
( x . type == VirtualController . TYPE_SCSI ) ]
if len ( ctrls_scsi ) > 0 :
index_new = max ( [ x . index for x in ctrls_scsi ] ) + 1
else :
index_new = 0
controller = VirtualController ( self . conn . get_backend ( ) )
controller . type = " scsi "
controller . model = controller_model
disk . vmm_controller = controller
for d in controllers :
if controller . type == d . type :
controller . index = index_new
if controller_model == d . model :
disk . vmm_controller = None
controller = d
break
disk . address . type = disk . address . ADDRESS_TYPE_DRIVE
disk . address . controller = controller . index
2009-11-24 20:43:54 +03:00
def validate_page_storage ( self ) :
2014-01-13 01:52:26 +04:00
bus = self . get_config_disk_bus ( )
device = self . get_config_disk_device ( )
2010-05-20 16:34:32 +04:00
cache = self . get_config_disk_cache ( )
2010-12-11 03:20:14 +03:00
fmt = self . get_config_disk_format ( )
2013-07-05 16:59:58 +04:00
2014-01-29 01:53:11 +04:00
controller_model = None
2012-12-07 14:21:38 +04:00
if bus == " virtio-scsi " :
2013-02-07 00:41:43 +04:00
bus = " scsi "
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 ( ) ]
disk = self . addstorage . validate_storage ( self . vm . get_name ( ) ,
collidelist = collidelist , device = device , fmt = fmt )
if disk in [ True , False ] :
return disk
2009-11-24 20:43:54 +03:00
try :
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
if not self . is_customize_dialog :
used = [ ]
disks = ( self . vm . get_disk_devices ( ) +
self . vm . get_disk_devices ( inactive = True ) )
for d in disks :
used . append ( d . target )
2010-02-06 23:59:52 +03:00
2014-01-29 01:53:11 +04:00
disk . generate_target ( used )
2010-03-04 23:35:34 +03:00
2014-01-29 01:53:11 +04:00
self . _set_disk_controller ( disk , controller_model )
except Exception , e :
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
2009-11-24 20:43:54 +03:00
def validate_page_network ( self ) :
2014-01-28 01:58:45 +04:00
nettype = self . netlist . get_network_selection ( ) [ 0 ]
2009-11-24 20:43:54 +03:00
mac = self . get_config_macaddr ( )
2014-01-27 05:21:12 +04:00
model = self . get_config_net_model ( )
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
2014-01-28 01:58:45 +04: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
2010-02-06 23:33:32 +03:00
def validate_page_input ( self ) :
2014-01-27 05:21:12 +04:00
inp_type , inp_bus = self . get_config_input ( )
2013-07-05 16:59:58 +04:00
dev = virtinst . VirtualInputDevice ( self . conn . get_backend ( ) )
2010-02-06 23:33:32 +03:00
dev . type = inp_type
dev . bus = inp_bus
self . _dev = dev
2009-11-24 20:43:54 +03:00
def validate_page_graphics ( self ) :
try :
2014-01-29 03:44:40 +04:00
( gtype , port ,
tlsport , addr , passwd , keymap ) = self . gfxdetails . get_values ( )
2013-07-16 04:43:41 +04:00
self . _dev = virtinst . VirtualGraphics ( self . conn . get_backend ( ) )
self . _dev . type = gtype
2013-09-02 19:54:36 +04:00
self . _dev . port = port
2014-01-29 03:44:40 +04:00
self . _dev . passwd = passwd
self . _dev . listen = addr
self . _dev . tlsPort = tlsport
if keymap :
self . _dev . keymap = keymap
2009-11-24 20:43:54 +03:00
except ValueError , 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
def validate_page_sound ( self ) :
smodel = self . get_config_sound_model ( )
try :
2013-07-16 06:00:08 +04:00
self . _dev = virtinst . VirtualAudio ( self . conn . get_backend ( ) )
self . _dev . model = smodel
2009-11-24 20:43:54 +03:00
except Exception , 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
2009-11-24 20:43:54 +03:00
def validate_page_hostdev ( self ) :
2014-01-27 05:21:12 +04:00
row = self . get_config_host_device_info ( )
2013-04-30 18:53:10 +04:00
is_dup = False
2009-07-14 17:25:39 +04:00
2014-01-27 05:21:12 +04:00
if row 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
2014-01-27 05:21:12 +04:00
devtype = row [ 2 ]
nodedev = row [ 3 ]
2013-04-30 18:53:10 +04:00
if devtype == " usb_device " :
vendor = nodedev . vendor_id
product = nodedev . product_id
count = self . conn . get_nodedevs_number ( devtype , vendor , product )
if not count :
raise RuntimeError ( _ ( " Could not find USB device "
" (vendorId: %s , productId: %s ) "
% ( vendor , product ) ) )
if count > 1 :
is_dup = True
2009-11-24 20:43:54 +03:00
try :
2013-09-28 02:06:39 +04:00
dev = virtinst . VirtualHostDevice ( self . conn . get_backend ( ) )
dev . set_from_nodedev ( nodedev , use_full_usb = is_dup )
self . _dev = dev
2009-11-24 20:43:54 +03:00
except Exception , 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
2009-11-24 20:43:54 +03:00
def validate_page_char ( self ) :
2013-07-16 17:14:37 +04:00
charclass = self . get_char_type ( )
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 " )
2014-01-27 05:21:12 +04:00
devtype = uiutil . get_list_selection ( devbox , 0 )
2013-07-05 16:59:58 +04:00
conn = self . conn . get_backend ( )
2007-04-12 23:36:04 +04:00
2013-07-16 17:14:37 +04:00
devclass = charclass ( conn )
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-01-27 05:21:12 +04:00
source_mode = uiutil . get_list_selection ( modebox , 0 )
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 ( )
2014-01-27 05:21:12 +04:00
target_type = uiutil . get_list_selection ( typebox , 0 )
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 "
2009-11-24 20:43:54 +03:00
value_mappings = {
" source_path " : source_path ,
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 ( )
except Exception , e :
2013-07-16 17:14:37 +04:00
return self . err . val_err (
_ ( " %s device parameter error " ) %
charclass . virtual_device_type . capitalize ( ) , e )
2007-09-26 04:05:45 +04:00
2009-11-24 20:43:54 +03:00
def validate_page_video ( self ) :
2013-07-05 16:59:58 +04:00
conn = self . conn . get_backend ( )
2009-11-24 20:43:54 +03:00
model = self . get_config_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
2009-11-24 20:43:54 +03:00
except Exception , 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
def validate_page_watchdog ( self ) :
2013-07-05 16:59:58 +04:00
conn = self . conn . get_backend ( )
2010-03-24 07:22:17 +03:00
model = self . get_config_watchdog_model ( )
action = self . get_config_watchdog_action ( )
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
except Exception , 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
2011-05-20 02:17:58 +04:00
def validate_page_filesystem ( self ) :
2014-01-27 20:03:59 +04:00
if self . fsDetails . validate_page_filesystem ( ) is False :
return False
2014-01-21 13:05:30 +04:00
self . _dev = self . fsDetails . get_dev ( )
2011-12-21 09:58:54 +04:00
2011-06-23 19:42:03 +04:00
def validate_page_smartcard ( self ) :
2013-07-05 16:59:58 +04:00
conn = self . conn . get_backend ( )
2011-06-23 19:42:03 +04:00
mode = self . get_config_smartcard_mode ( )
try :
2013-07-15 20:36:57 +04:00
self . _dev = VirtualSmartCardDevice ( conn )
self . _dev . mode = mode
2011-06-23 19:42:03 +04:00
except Exception , e :
2011-09-02 05:23:28 +04:00
return self . err . val_err ( _ ( " Smartcard device parameter error " ) , e )
def validate_page_usbredir ( self ) :
2013-07-05 16:59:58 +04:00
conn = self . conn . get_backend ( )
2011-09-02 05:23:28 +04:00
stype = self . get_config_usbredir_type ( )
2013-09-09 19:17:01 +04:00
host , service = self . get_config_usbredir_host ( )
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
except Exception , e :
return self . err . val_err ( _ ( " USB redirected device parameter error " ) ,
str ( e ) )
2011-06-23 19:42:03 +04:00
2013-06-26 05:45:09 +04:00
def validate_page_tpm ( self ) :
2013-07-05 16:59:58 +04:00
conn = self . conn . get_backend ( )
2013-06-26 05:45:09 +04:00
typ = self . get_config_tpm_type ( )
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 )
except Exception , e :
return self . err . val_err ( _ ( " TPM device parameter error " ) , e )
2009-03-09 23:20:23 +03:00
2014-01-10 13:37:56 +04:00
def validate_page_panic ( self ) :
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 )
except Exception , e :
return self . err . val_err ( _ ( " Panic device parameter error " ) , e )
2013-09-23 17:39:57 +04:00
def validate_page_rng ( self ) :
2013-10-25 19:13:28 +04:00
conn = virtinst . VirtualRNGDevice . BACKEND_MODE_CONNECT in \
self . get_config_rng_backend_mode ( )
2013-09-23 17:39:57 +04:00
model = self . get_config_rng_type ( )
2013-10-25 19:13:28 +04:00
is_udp = self . get_config_rng_backend_type ( ) == \
virtinst . VirtualRNGDevice . BACKEND_TYPE_UDP
2013-09-23 17:39:57 +04:00
if model == virtinst . VirtualRNGDevice . TYPE_RANDOM :
if not self . get_config_rng_device ( ) :
return self . err . val_err ( _ ( " RNG selection error. " ) ,
_ ( " A device must be specified. " ) )
elif model == virtinst . VirtualRNGDevice . TYPE_EGD :
2013-10-25 19:13:28 +04:00
conn = self . get_config_rng_backend_mode ( ) == \
virtinst . VirtualRNGDevice . BACKEND_MODE_CONNECT
if is_udp :
if not self . get_config_rng_host ( is_connect = conn ) or \
not self . get_config_rng_host ( is_connect = not conn ) :
return self . err . val_err ( _ ( " RNG selection error. " ) ,
_ ( " Please specify both bind and connect host " ) )
if not int ( self . get_config_rng_service ( is_connect = conn ) ) or \
not int ( self . get_config_rng_service ( is_connect = not conn ) ) :
return self . err . val_err ( _ ( " RNG selection error. " ) ,
_ ( " Please specify both bind and connect service " ) )
else :
if not self . get_config_rng_host ( is_connect = conn ) :
return self . err . val_err ( _ ( " RNG selection error. " ) ,
_ ( " The EGD host must be specified. " ) )
if not int ( self . get_config_rng_service ( is_connect = conn ) ) :
return self . err . val_err ( _ ( " RNG selection error. " ) ,
_ ( " The EGD service must be specified. " ) )
2013-09-23 17:39:57 +04:00
else :
return self . err . val_err ( _ ( " RNG selection error. " ) ,
_ ( " Invalid RNG type. " ) )
value_mappings = {
" backend_type " : self . get_config_rng_backend_type ( ) ,
" backend_source_mode " : self . get_config_rng_backend_mode ( ) ,
2013-10-25 19:13:28 +04:00
" connect_host " : self . get_config_rng_host ( is_connect = True ) ,
" connect_service " : self . get_config_rng_service ( is_connect = True ) ,
" bind_host " : self . get_config_rng_host ( ) ,
" bind_service " : self . get_config_rng_service ( ) ,
2013-09-23 17:39:57 +04:00
" device " : self . get_config_rng_device ( ) ,
}
try :
self . _dev = virtinst . VirtualRNGDevice ( conn )
self . _dev . type = self . get_config_rng_type ( )
for param_name , val in value_mappings . items ( ) :
if self . _dev . supports_property ( param_name ) :
setattr ( self . _dev , param_name , val )
except Exception , 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-04-12 02:35:21 +04:00
conn = self . conn
2011-06-09 02:38:03 +04:00
reason = ( isdir and
self . config . CONFIG_DIR_FS or
self . config . CONFIG_DIR_IMAGE )
2012-11-08 17:15:02 +04:00
if self . storage_browser is None :
2010-12-09 01:26:19 +03:00
self . storage_browser = vmmStorageBrowser ( conn )
2009-03-09 23:20:23 +03:00
2014-01-20 20:09:13 +04:00
self . storage_browser . stable_defaults = self . vm . stable_defaults ( )
2011-07-22 20:22:09 +04:00
2009-11-24 20:43:54 +03:00
self . storage_browser . set_finish_cb ( set_storage_cb )
2011-06-09 02:38:03 +04:00
self . storage_browser . set_browse_reason ( reason )
2009-11-24 20:43:54 +03:00
2011-04-14 16:47:42 +04:00
self . storage_browser . show ( self . topwin , conn )