2014-01-20 20:09:13 +04:00
# Copyright (C) 2006-2007, 2013, 2014 Red Hat, Inc.
2014-01-21 13:05:30 +04:00
# Copyright (C) 2006 Hugh O. Brock <hbrock@redhat.com>
# Copyright (C) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2014-01-21 13:05:30 +04:00
from gi . repository import Gtk
2018-09-06 03:13:56 +03:00
from virtinst import DeviceFilesystem
2014-09-13 00:10:45 +04:00
from . import uiutil
from . baseclass import vmmGObjectUI
from . storagebrowse import vmmStorageBrowser
2014-01-21 13:05:30 +04:00
class vmmFSDetails ( vmmGObjectUI ) :
2014-01-21 13:05:31 +04:00
__gsignals__ = {
2018-03-15 15:10:09 +03:00
" changed " : ( vmmGObjectUI . RUN_FIRST , None , [ ] )
2014-01-21 13:05:31 +04:00
}
2014-01-27 20:03:59 +04:00
def __init__ ( self , vm , builder , topwin ) :
vmmGObjectUI . __init__ ( self , " fsdetails.ui " ,
None , builder = builder , topwin = topwin )
2014-01-21 13:05:30 +04:00
self . vm = vm
self . conn = vm . conn
self . _dev = None
self . storage_browser = None
self . builder . connect_signals ( {
" on_fs_type_combo_changed " : self . change_field ,
" on_fs_driver_combo_changed " : self . change_field ,
" on_fs_source_browse_clicked " : self . browse_fs_source ,
2014-01-21 13:05:31 +04:00
" on_fs_mode_combo_changed " : self . notify_change ,
" on_fs_wrpolicy_combo_changed " : self . notify_change ,
" on_fs_readonly_toggled " : self . notify_change ,
" on_fs_format_combo_changed " : self . notify_change ,
" on_fs_source_changed " : self . notify_change ,
" on_fs_ram_source_changed " : self . notify_change ,
" on_fs_target_changed " : self . notify_change ,
2014-01-21 13:05:30 +04:00
} )
2014-01-27 20:03:59 +04:00
self . set_initial_state ( )
self . top_box = self . widget ( " vmm-fs-details " )
2014-01-21 13:05:30 +04:00
def _cleanup ( self ) :
self . vm = None
self . conn = None
self . _dev = None
if self . storage_browser :
self . storage_browser . cleanup ( )
self . storage_browser = None
def show_pair_combo ( self , basename , show_combo ) :
combo = self . widget ( basename + " -combo " )
label = self . widget ( basename + " -label " )
combo . set_visible ( show_combo )
label . set_visible ( not show_combo )
def show_check_button ( self , basename , show ) :
check = self . widget ( basename )
check . set_visible ( show )
##########################
# Initialization methods #
##########################
def set_initial_state ( self ) :
2014-01-24 14:40:10 +04:00
def simple_store_set ( comboname , values , sort = True , capitalize = True ) :
2014-01-21 13:05:30 +04:00
combo = self . widget ( comboname )
2018-09-02 04:58:46 +03:00
# [XML value, label]
2014-01-21 13:05:30 +04:00
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-24 14:40:10 +04:00
if sort :
2014-01-21 13:05:30 +04:00
model . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
2018-09-02 04:58:46 +03:00
for xmlval in values :
label = xmlval
if xmlval is None :
label = " Default "
if capitalize :
label = label . capitalize ( )
model . append ( [ xmlval , label ] )
2014-01-21 13:05:30 +04:00
# Filesystem widgets
if self . conn . is_openvz ( ) :
2014-03-06 20:41:34 +04:00
simple_store_set ( " fs-type-combo " ,
2018-03-20 19:18:35 +03:00
[ DeviceFilesystem . TYPE_MOUNT ,
DeviceFilesystem . TYPE_TEMPLATE ] , sort = False )
2014-01-21 13:05:30 +04:00
elif self . conn . is_lxc ( ) :
2014-03-06 20:41:34 +04:00
simple_store_set ( " fs-type-combo " ,
2018-03-20 19:18:35 +03:00
[ DeviceFilesystem . TYPE_MOUNT ,
DeviceFilesystem . TYPE_FILE ,
DeviceFilesystem . TYPE_BLOCK ,
DeviceFilesystem . TYPE_RAM ] , sort = False )
2014-01-21 13:05:30 +04:00
else :
2018-03-20 19:18:35 +03:00
simple_store_set ( " fs-type-combo " , [ DeviceFilesystem . TYPE_MOUNT ] )
self . widget ( " fs-type-label " ) . set_text ( DeviceFilesystem . TYPE_MOUNT )
2014-01-21 13:05:30 +04:00
2018-09-02 04:58:46 +03:00
simple_store_set ( " fs-mode-combo " , DeviceFilesystem . MODES + [ None ] )
2018-09-06 03:13:56 +03:00
drivers = [ ]
2017-06-27 21:13:36 +03:00
if self . conn . is_qemu ( ) or self . conn . is_test ( ) :
2018-09-06 03:13:56 +03:00
drivers + = [ DeviceFilesystem . DRIVER_PATH ,
DeviceFilesystem . DRIVER_HANDLE ]
if self . conn . is_lxc ( ) or self . conn . is_test ( ) :
drivers + = [ DeviceFilesystem . DRIVER_LOOP ,
DeviceFilesystem . DRIVER_NBD ]
simple_store_set ( " fs-driver-combo " , drivers + [ None ] )
simple_store_set ( " fs-format-combo " , [ " raw " , " qcow2 " ] , capitalize = False )
2018-09-02 04:58:46 +03:00
simple_store_set ( " fs-wrpolicy-combo " ,
DeviceFilesystem . WRPOLICIES + [ None ] )
2014-03-06 20:41:34 +04:00
self . show_pair_combo ( " fs-type " ,
self . conn . is_openvz ( ) or self . conn . is_lxc ( ) )
2014-01-21 13:05:30 +04:00
self . show_check_button ( " fs-readonly " ,
2014-03-06 20:41:34 +04:00
self . conn . is_qemu ( ) or
2017-06-27 21:13:36 +03:00
self . conn . is_test ( ) or
2014-03-06 20:41:34 +04:00
self . conn . is_lxc ( ) )
2014-01-21 13:05:30 +04:00
def reset_state ( self ) :
self . widget ( " fs-type-combo " ) . set_active ( 0 )
self . widget ( " fs-mode-combo " ) . set_active ( 0 )
self . widget ( " fs-driver-combo " ) . set_active ( 0 )
self . widget ( " fs-format-combo " ) . set_active ( 0 )
self . widget ( " fs-wrpolicy-combo " ) . set_active ( 0 )
self . widget ( " fs-source " ) . set_text ( " " )
self . widget ( " fs-target " ) . set_text ( " " )
self . widget ( " fs-readonly " ) . set_active ( False )
# Getters
def get_dev ( self ) :
return self . _dev
def get_config_fs_mode ( self ) :
2015-05-20 00:17:53 +03:00
return uiutil . get_list_selection ( self . widget ( " fs-mode-combo " ) ,
2014-04-03 18:53:54 +04:00
check_visible = True )
2014-01-21 13:05:30 +04:00
def get_config_fs_wrpolicy ( self ) :
2015-05-20 00:17:53 +03:00
return uiutil . get_list_selection ( self . widget ( " fs-wrpolicy-combo " ) ,
2014-04-03 18:53:54 +04:00
check_visible = True )
2014-01-21 13:05:30 +04:00
def get_config_fs_type ( self ) :
2017-06-27 21:08:44 +03:00
if self . widget ( " fs-type-label " ) . is_visible ( ) :
return self . widget ( " fs-type-label " ) . get_text ( )
2015-05-20 00:17:53 +03:00
return uiutil . get_list_selection ( self . widget ( " fs-type-combo " ) ,
2014-04-03 18:53:54 +04:00
check_visible = True )
2014-01-21 13:05:30 +04:00
def get_config_fs_readonly ( self ) :
2014-03-06 20:45:26 +04:00
if not self . widget ( " fs-readonly " ) . is_visible ( ) :
return None
return self . widget ( " fs-readonly " ) . get_active ( )
2014-01-21 13:05:30 +04:00
def get_config_fs_driver ( self ) :
2015-05-20 00:17:53 +03:00
return uiutil . get_list_selection ( self . widget ( " fs-driver-combo " ) ,
2014-04-03 18:53:54 +04:00
check_visible = True )
2014-01-21 13:05:30 +04:00
def get_config_fs_format ( self ) :
2015-05-20 00:17:53 +03:00
return uiutil . get_list_selection ( self . widget ( " fs-format-combo " ) ,
2014-04-03 18:53:54 +04:00
check_visible = True )
2014-01-21 13:05:30 +04:00
# Setters
2014-01-21 13:05:31 +04:00
def set_dev ( self , dev ) :
self . _dev = dev
2018-09-02 04:58:46 +03:00
self . set_config_value ( " fs-type " , dev . type )
self . set_config_value ( " fs-mode " , dev . accessmode )
self . set_config_value ( " fs-driver " , dev . driver )
self . set_config_value ( " fs-wrpolicy " , dev . wrpolicy )
self . set_config_value ( " fs-format " , dev . format )
2018-03-20 19:18:35 +03:00
if dev . type != DeviceFilesystem . TYPE_RAM :
2014-01-21 13:05:31 +04:00
self . widget ( " fs-source " ) . set_text ( dev . source )
else :
2017-10-11 14:35:55 +03:00
self . widget ( " fs-ram-source-spin " ) . set_value ( int ( dev . source ) / / 1024 )
2014-01-21 13:05:31 +04:00
self . widget ( " fs-target " ) . set_text ( dev . target or " " )
self . widget ( " fs-readonly " ) . set_active ( dev . readonly )
2014-03-06 20:41:34 +04:00
self . show_pair_combo ( " fs-type " ,
self . conn . is_openvz ( ) or self . conn . is_lxc ( ) )
2014-01-21 13:05:31 +04:00
2014-01-21 13:05:30 +04:00
def set_config_value ( self , name , value ) :
combo = self . widget ( " %s -combo " % name )
label = self . widget ( " %s -label " % name )
2018-09-06 03:13:56 +03:00
uiutil . set_list_selection ( combo , value )
2014-01-21 13:05:30 +04:00
if label :
2018-09-02 04:58:46 +03:00
label . set_text ( value or " default " )
2014-01-21 13:05:30 +04:00
# listeners
2014-01-21 13:05:31 +04:00
def notify_change ( self , ignore ) :
self . emit ( " changed " )
2014-01-21 13:05:30 +04:00
def browse_fs_source ( self , ignore1 ) :
self . _browse_file ( self . widget ( " fs-source " ) , isdir = True )
def update_fs_rows ( self ) :
fstype = self . get_config_fs_type ( )
fsdriver = self . get_config_fs_driver ( )
ismount = bool (
2018-03-20 19:18:35 +03:00
fstype == DeviceFilesystem . TYPE_MOUNT or
2017-06-27 21:13:36 +03:00
self . conn . is_qemu ( ) or self . conn . is_test ( ) )
2014-01-21 13:05:30 +04:00
show_mode = bool ( ismount and
2018-03-20 19:18:35 +03:00
( fsdriver == DeviceFilesystem . DRIVER_PATH or
2018-09-02 04:58:46 +03:00
fsdriver is None ) )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( " fs-mode-box " ) , show_mode )
2014-01-21 13:05:30 +04:00
show_wrpol = bool ( ismount and
2018-03-20 19:18:35 +03:00
fsdriver and ( fsdriver == DeviceFilesystem . DRIVER_PATH or
fsdriver == DeviceFilesystem . DRIVER_HANDLE ) )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( " fs-wrpolicy-box " ) ,
2014-01-21 13:05:30 +04:00
show_wrpol )
2018-03-20 19:18:35 +03:00
show_ram_source = fstype == DeviceFilesystem . TYPE_RAM
2014-03-06 20:41:34 +04:00
uiutil . set_grid_row_visible (
self . widget ( " fs-ram-source-box " ) , show_ram_source )
uiutil . set_grid_row_visible (
self . widget ( " fs-source-box " ) , not show_ram_source )
2014-01-21 13:05:30 +04:00
show_format = bool (
2018-03-20 19:18:35 +03:00
fsdriver == DeviceFilesystem . DRIVER_NBD )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( " fs-format-box " ) , show_format )
2014-01-21 13:05:30 +04:00
self . show_pair_combo ( " fs-format " , True )
show_mode_combo = False
show_driver_combo = False
2017-06-27 21:13:36 +03:00
show_wrpolicy_combo = self . conn . is_qemu ( ) or self . conn . is_test ( )
2018-03-20 19:18:35 +03:00
if fstype == DeviceFilesystem . TYPE_TEMPLATE :
2014-01-21 13:05:30 +04:00
source_text = _ ( " Te_mplate: " )
else :
source_text = _ ( " _Source path: " )
2017-06-27 21:13:36 +03:00
show_mode_combo = self . conn . is_qemu ( ) or self . conn . is_test ( )
2014-03-06 20:41:34 +04:00
show_driver_combo = ( self . conn . is_qemu ( ) or
self . conn . is_lxc ( ) or
2017-06-27 21:13:36 +03:00
self . conn . is_test ( ) )
2014-01-21 13:05:30 +04:00
self . widget ( " fs-source-title " ) . set_text ( source_text )
self . widget ( " fs-source-title " ) . set_use_underline ( True )
self . show_pair_combo ( " fs-mode " , show_mode_combo )
self . show_pair_combo ( " fs-driver " , show_driver_combo )
self . show_pair_combo ( " fs-wrpolicy " , show_wrpolicy_combo )
def change_field ( self , src ) :
self . update_fs_rows ( )
2014-01-21 13:05:31 +04:00
self . notify_change ( src )
2014-01-21 13:05:30 +04:00
# Page validation method
def validate_page_filesystem ( self ) :
conn = self . conn . get_backend ( )
source = self . widget ( " fs-source " ) . get_text ( )
target = self . widget ( " fs-target " ) . get_text ( )
2014-01-27 03:15:50 +04:00
usage = uiutil . spin_get_helper ( self . widget ( " fs-ram-source-spin " ) )
2014-01-21 13:05:30 +04:00
mode = self . get_config_fs_mode ( )
fstype = self . get_config_fs_type ( )
readonly = self . get_config_fs_readonly ( )
driver = self . get_config_fs_driver ( )
fsformat = self . get_config_fs_format ( )
wrpolicy = self . get_config_fs_wrpolicy ( )
2018-03-20 19:18:35 +03:00
if not source and fstype != DeviceFilesystem . TYPE_RAM :
2014-01-21 13:05:30 +04:00
return self . err . val_err ( _ ( " A filesystem source must be specified " ) )
2018-03-20 19:18:35 +03:00
elif usage == 0 and fstype == DeviceFilesystem . TYPE_RAM :
2014-03-06 20:41:34 +04:00
return self . err . val_err (
_ ( " A RAM filesystem usage must be specified " ) )
2014-01-21 13:05:30 +04:00
if not target :
return self . err . val_err ( _ ( " A filesystem target must be specified " ) )
try :
2018-03-20 19:18:35 +03:00
self . _dev = DeviceFilesystem ( conn )
if fstype == DeviceFilesystem . TYPE_RAM :
2014-01-21 13:05:30 +04:00
self . _dev . source = usage
2014-06-16 07:56:02 +04:00
self . _dev . units = ' MiB '
2014-01-21 13:05:30 +04:00
else :
self . _dev . source = source
self . _dev . target = target
2018-09-04 00:03:02 +03:00
self . _dev . validate_target ( target )
2014-01-21 13:05:30 +04:00
if mode :
2015-09-21 03:15:34 +03:00
self . _dev . accessmode = mode
2014-01-21 13:05:30 +04:00
if fstype :
self . _dev . type = fstype
if readonly :
self . _dev . readonly = readonly
if driver :
self . _dev . driver = driver
2018-03-20 19:18:35 +03:00
if driver == DeviceFilesystem . DRIVER_LOOP :
2014-01-21 13:05:30 +04:00
self . _dev . format = " raw "
2018-03-20 19:18:35 +03:00
elif driver == DeviceFilesystem . DRIVER_NBD :
2014-01-21 13:05:30 +04:00
self . _dev . format = fsformat
if wrpolicy :
self . _dev . wrpolicy = wrpolicy
2017-05-05 19:47:21 +03:00
except Exception as e :
2014-01-21 13:05:30 +04:00
return self . err . val_err ( _ ( " Filesystem parameter error " ) , e )
def _browse_file ( self , textent , isdir = False ) :
def set_storage_cb ( src , path ) :
if path :
textent . set_text ( path )
reason = ( isdir and
self . config . CONFIG_DIR_FS or
self . config . CONFIG_DIR_IMAGE )
2015-04-09 01:29:48 +03:00
if self . storage_browser and self . storage_browser . conn != self . conn :
self . storage_browser . cleanup ( )
self . storage_browser = None
if self . storage_browser is None :
self . storage_browser = vmmStorageBrowser ( self . conn )
2014-01-21 13:05:30 +04:00
self . storage_browser . set_finish_cb ( set_storage_cb )
self . storage_browser . set_browse_reason ( reason )
2015-04-09 01:29:48 +03:00
self . storage_browser . show ( self . topwin . get_ancestor ( Gtk . Window ) )