2007-03-28 03:52:00 +04:00
#
2014-07-23 17:48:17 +04:00
# Copyright (C) 2007, 2013-2014 Red Hat, Inc.
2007-03-28 03:52:00 +04:00
# Copyright (C) 2007 Daniel P. Berrange <berrange@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-03-28 03:52:00 +04:00
#
2010-02-26 01:42:00 +03:00
import logging
2008-08-15 19:07:45 +04:00
2012-05-14 17:24:56 +04:00
from gi . repository import GObject
from gi . repository import Gtk
2013-08-13 16:26:28 +04:00
from gi . repository import Gdk
2011-04-18 20:39:53 +04:00
2010-12-17 18:32:54 +03:00
from virtinst import VirtualDisk
2013-09-20 04:18:12 +04:00
from virtinst import StoragePool
2010-02-09 01:13:36 +03:00
from virtinst import Interface
2007-03-28 03:52:00 +04:00
2014-09-13 00:10:45 +04:00
from . import uiutil
from . asyncjob import vmmAsyncJob
from . createnet import vmmCreateNetwork
from . createpool import vmmCreatePool
from . createvol import vmmCreateVolume
from . createinterface import vmmCreateInterface
from . baseclass import vmmGObjectUI
from . graphwidgets import Sparkline
2007-03-30 05:23:17 +04:00
2010-02-09 01:13:36 +03:00
INTERFACE_PAGE_INFO = 0
INTERFACE_PAGE_ERROR = 1
2014-07-23 17:48:17 +04:00
EDIT_NET_IDS = (
EDIT_NET_NAME ,
2013-09-29 20:28:01 +04:00
EDIT_NET_AUTOSTART ,
2014-06-25 14:36:46 +04:00
EDIT_NET_QOS ,
2014-07-23 17:48:17 +04:00
) = range ( 3 )
2013-09-29 20:28:01 +04:00
2014-07-23 17:48:17 +04:00
EDIT_POOL_IDS = (
2013-09-29 20:28:01 +04:00
EDIT_POOL_NAME ,
EDIT_POOL_AUTOSTART ,
2014-07-23 17:48:17 +04:00
) = range ( 100 , 102 )
EDIT_INTERFACE_IDS = (
EDIT_INTERFACE_STARTMODE ,
) = range ( 200 , 201 )
2013-09-29 20:14:00 +04:00
2013-04-13 22:34:52 +04:00
2010-12-09 01:26:19 +03:00
class vmmHost ( vmmGObjectUI ) :
2012-05-14 17:24:56 +04:00
__gsignals__ = {
" action-exit-app " : ( GObject . SignalFlags . RUN_FIRST , None , [ ] ) ,
" action-view-manager " : ( GObject . SignalFlags . RUN_FIRST , None , [ ] ) ,
" action-restore-domain " : ( GObject . SignalFlags . RUN_FIRST , None , [ str ] ) ,
" host-closed " : ( GObject . SignalFlags . RUN_FIRST , None , [ ] ) ,
" host-opened " : ( GObject . SignalFlags . RUN_FIRST , None , [ ] ) ,
}
2011-04-13 18:47:31 +04:00
def __init__ ( self , conn ) :
2013-09-23 00:10:16 +04:00
vmmGObjectUI . __init__ ( self , " host.ui " , " vmm-host " )
2007-03-28 03:52:00 +04:00
self . conn = conn
2009-11-17 23:44:27 +03:00
self . title = conn . get_short_hostname ( ) + " " + self . topwin . get_title ( )
self . topwin . set_title ( self . title )
2008-09-10 18:34:27 +04:00
2011-07-12 19:50:11 +04:00
self . ICON_RUNNING = " state_running "
self . ICON_SHUTOFF = " state_shutoff "
2008-08-15 19:07:45 +04:00
2009-11-17 23:44:27 +03:00
self . addnet = None
self . addpool = None
self . addvol = None
2010-02-09 01:13:36 +03:00
self . addinterface = None
2009-11-17 23:44:27 +03:00
self . volmenu = None
2012-02-08 04:05:45 +04:00
self . _in_refresh = False
2007-03-28 03:52:00 +04:00
2013-09-29 20:28:01 +04:00
self . active_edits = [ ]
2013-09-29 20:14:00 +04:00
2009-11-17 23:44:27 +03:00
self . cpu_usage_graph = None
self . memory_usage_graph = None
self . init_conn_state ( )
2007-03-28 03:52:00 +04:00
2009-11-20 01:29:20 +03:00
self . init_net_state ( )
self . init_storage_state ( )
2010-02-09 01:13:36 +03:00
self . init_interface_state ( )
2009-11-20 01:29:20 +03:00
2013-02-16 22:31:46 +04:00
self . builder . connect_signals ( {
2009-11-17 23:18:38 +03:00
" on_menu_file_view_manager_activate " : self . view_manager ,
" on_menu_file_quit_activate " : self . exit_app ,
2007-03-28 03:52:00 +04:00
" on_menu_file_close_activate " : self . close ,
" on_vmm_host_delete_event " : self . close ,
2013-07-07 19:06:15 +04:00
" on_host_page_switch " : self . page_changed ,
2009-11-17 23:18:38 +03:00
2010-05-12 19:42:59 +04:00
" on_menu_restore_saved_activate " : self . restore_domain ,
2010-02-09 01:13:36 +03:00
2007-03-30 05:23:17 +04:00
" on_net_add_clicked " : self . add_network ,
2007-04-03 22:01:45 +04:00
" on_net_delete_clicked " : self . delete_network ,
" on_net_stop_clicked " : self . stop_network ,
" on_net_start_clicked " : self . start_network ,
2014-07-23 17:48:17 +04:00
" on_net_apply_clicked " : ( lambda * x : self . net_apply ( ) ) ,
2013-09-23 00:29:58 +04:00
" on_net_list_changed " : self . net_selected ,
2013-09-29 20:14:00 +04:00
" on_net_autostart_toggled " : self . net_autostart_changed ,
" on_net_name_changed " : ( lambda * x :
self . enable_net_apply ( x , EDIT_NET_NAME ) ) ,
2010-02-09 01:13:36 +03:00
2008-08-15 19:07:45 +04:00
" on_pool_add_clicked " : self . add_pool ,
" on_vol_add_clicked " : self . add_vol ,
" on_pool_stop_clicked " : self . stop_pool ,
" on_pool_start_clicked " : self . start_pool ,
" on_pool_delete_clicked " : self . delete_pool ,
2010-04-21 18:56:06 +04:00
" on_pool_refresh_clicked " : self . pool_refresh ,
2008-08-15 19:07:45 +04:00
" on_pool_autostart_toggled " : self . pool_autostart_changed ,
" on_vol_delete_clicked " : self . delete_vol ,
2008-09-10 19:08:19 +04:00
" on_vol_list_button_press_event " : self . popup_vol_menu ,
2014-07-23 17:48:17 +04:00
" on_pool_apply_clicked " : ( lambda * x : self . pool_apply ( ) ) ,
2013-09-23 00:29:58 +04:00
" on_vol_list_changed " : self . vol_selected ,
2013-09-29 20:28:01 +04:00
" on_pool_name_changed " : ( lambda * x :
self . enable_pool_apply ( x , EDIT_POOL_NAME ) ) ,
2010-02-09 01:13:36 +03:00
" on_interface_add_clicked " : self . add_interface ,
" on_interface_start_clicked " : self . start_interface ,
" on_interface_stop_clicked " : self . stop_interface ,
" on_interface_delete_clicked " : self . delete_interface ,
" on_interface_startmode_changed " : self . interface_startmode_changed ,
2014-07-23 17:48:17 +04:00
" on_interface_apply_clicked " : ( lambda * x : self . interface_apply ( ) ) ,
2013-09-23 00:29:58 +04:00
" on_interface_list_changed " : self . interface_selected ,
2010-02-09 01:13:36 +03:00
2008-03-24 18:39:19 +03:00
" on_config_autoconnect_toggled " : self . toggle_autoconnect ,
2014-06-25 14:36:46 +04:00
" on_qos_inbound_average_changed " : ( lambda * x :
self . enable_net_apply ( x , EDIT_NET_QOS ) ) ,
" on_qos_inbound_peak_changed " : ( lambda * x :
self . enable_net_apply ( x , EDIT_NET_QOS ) ) ,
" on_qos_inbound_burst_changed " : ( lambda * x :
self . enable_net_apply ( x , EDIT_NET_QOS ) ) ,
" on_qos_outbound_average_changed " : ( lambda * x :
self . enable_net_apply ( x , EDIT_NET_QOS ) ) ,
" on_qos_outbound_peak_changed " : ( lambda * x :
self . enable_net_apply ( x , EDIT_NET_QOS ) ) ,
" on_qos_outbound_burst_changed " : ( lambda * x :
self . enable_net_apply ( x , EDIT_NET_QOS ) ) ,
" on_net_qos_inbound_enable_toggled " : self . change_qos_in_enable ,
" on_net_qos_outbound_enable_toggled " : self . change_qos_out_enable ,
2012-11-08 17:15:02 +04:00
} )
2007-03-28 03:52:00 +04:00
2013-10-01 02:46:54 +04:00
self . repopulate_networks ( )
self . repopulate_storage_pools ( )
self . repopulate_interfaces ( )
2013-09-23 20:37:03 +04:00
self . conn . connect ( " net-added " , self . repopulate_networks )
self . conn . connect ( " net-removed " , self . repopulate_networks )
self . conn . connect ( " net-started " , self . refresh_network )
self . conn . connect ( " net-stopped " , self . refresh_network )
self . conn . connect ( " pool-added " , self . repopulate_storage_pools )
self . conn . connect ( " pool-removed " , self . repopulate_storage_pools )
self . conn . connect ( " pool-started " , self . refresh_storage_pool )
self . conn . connect ( " pool-stopped " , self . refresh_storage_pool )
self . conn . connect ( " interface-added " , self . repopulate_interfaces )
self . conn . connect ( " interface-removed " , self . repopulate_interfaces )
self . conn . connect ( " interface-started " , self . refresh_interface )
self . conn . connect ( " interface-stopped " , self . refresh_interface )
self . conn . connect ( " state-changed " , self . conn_state_changed )
2007-03-28 03:52:00 +04:00
self . conn . connect ( " resources-sampled " , self . refresh_resources )
2008-09-18 18:33:53 +04:00
self . reset_state ( )
2007-03-28 03:52:00 +04:00
2009-03-08 22:34:15 +03:00
2009-11-17 23:44:27 +03:00
def init_net_state ( self ) :
2011-07-14 21:13:13 +04:00
self . widget ( " network-pages " ) . set_show_tabs ( False )
2010-02-26 01:31:27 +03:00
2009-11-20 01:29:20 +03:00
# [ unique, label, icon name, icon size, is_active ]
2012-05-14 17:24:56 +04:00
netListModel = Gtk . ListStore ( str , str , str , int , bool )
2011-07-14 21:13:13 +04:00
self . widget ( " net-list " ) . set_model ( netListModel )
2009-11-17 23:44:27 +03:00
2014-07-23 17:48:17 +04:00
sel = self . widget ( " net-list " ) . get_selection ( )
sel . set_select_function ( ( lambda * x : self . confirm_changes ( ) ) , None )
2012-05-14 17:24:56 +04:00
netCol = Gtk . TreeViewColumn ( " Networks " )
2009-11-17 23:44:27 +03:00
netCol . set_spacing ( 6 )
2012-05-14 17:24:56 +04:00
net_txt = Gtk . CellRendererText ( )
net_img = Gtk . CellRendererPixbuf ( )
2009-11-17 23:44:27 +03:00
netCol . pack_start ( net_img , False )
netCol . pack_start ( net_txt , True )
netCol . add_attribute ( net_txt , ' text ' , 1 )
2009-11-20 01:29:20 +03:00
netCol . add_attribute ( net_txt , ' sensitive ' , 4 )
2009-11-17 23:44:27 +03:00
netCol . add_attribute ( net_img , ' icon-name ' , 2 )
netCol . add_attribute ( net_img , ' stock-size ' , 3 )
2011-07-14 21:13:13 +04:00
self . widget ( " net-list " ) . append_column ( netCol )
2012-05-14 17:24:56 +04:00
netListModel . set_sort_column_id ( 1 , Gtk . SortType . ASCENDING )
2009-11-17 23:44:27 +03:00
def init_storage_state ( self ) :
2011-07-14 21:13:13 +04:00
self . widget ( " storage-pages " ) . set_show_tabs ( False )
2010-02-26 01:31:27 +03:00
2012-05-14 17:24:56 +04:00
self . volmenu = Gtk . Menu ( )
2014-02-26 00:57:38 +04:00
volCopyPath = Gtk . ImageMenuItem . new_with_label ( _ ( " Copy Volume Path " ) )
2012-05-14 17:24:56 +04:00
volCopyImage = Gtk . Image ( )
volCopyImage . set_from_stock ( Gtk . STOCK_COPY , Gtk . IconSize . MENU )
2009-11-17 23:44:27 +03:00
volCopyPath . set_image ( volCopyImage )
volCopyPath . show ( )
volCopyPath . connect ( " activate " , self . copy_vol_path )
self . volmenu . add ( volCopyPath )
2012-05-14 17:24:56 +04:00
volListModel = Gtk . ListStore ( str , str , str , str , str )
2011-07-14 21:13:13 +04:00
self . widget ( " vol-list " ) . set_model ( volListModel )
2009-11-17 23:44:27 +03:00
2012-05-14 17:24:56 +04:00
volCol = Gtk . TreeViewColumn ( " Volumes " )
vol_txt1 = Gtk . CellRendererText ( )
2009-11-17 23:44:27 +03:00
volCol . pack_start ( vol_txt1 , True )
volCol . add_attribute ( vol_txt1 , ' text ' , 1 )
volCol . set_sort_column_id ( 1 )
2011-07-14 21:13:13 +04:00
self . widget ( " vol-list " ) . append_column ( volCol )
2009-11-17 23:44:27 +03:00
2012-05-14 17:24:56 +04:00
volSizeCol = Gtk . TreeViewColumn ( " Size " )
vol_txt2 = Gtk . CellRendererText ( )
2009-11-17 23:44:27 +03:00
volSizeCol . pack_start ( vol_txt2 , False )
volSizeCol . add_attribute ( vol_txt2 , ' text ' , 2 )
volSizeCol . set_sort_column_id ( 2 )
2011-07-14 21:13:13 +04:00
self . widget ( " vol-list " ) . append_column ( volSizeCol )
2009-11-17 23:44:27 +03:00
2012-05-14 17:24:56 +04:00
volFormatCol = Gtk . TreeViewColumn ( " Format " )
vol_txt3 = Gtk . CellRendererText ( )
2009-11-17 23:44:27 +03:00
volFormatCol . pack_start ( vol_txt3 , False )
volFormatCol . add_attribute ( vol_txt3 , ' text ' , 3 )
volFormatCol . set_sort_column_id ( 3 )
2011-07-14 21:13:13 +04:00
self . widget ( " vol-list " ) . append_column ( volFormatCol )
2009-11-17 23:44:27 +03:00
2012-05-14 17:24:56 +04:00
volUseCol = Gtk . TreeViewColumn ( " Used By " )
vol_txt4 = Gtk . CellRendererText ( )
2010-12-17 18:32:54 +03:00
volUseCol . pack_start ( vol_txt4 , False )
volUseCol . add_attribute ( vol_txt4 , ' text ' , 4 )
volUseCol . set_sort_column_id ( 4 )
2011-07-14 21:13:13 +04:00
self . widget ( " vol-list " ) . append_column ( volUseCol )
2010-12-17 18:32:54 +03:00
2012-05-14 17:24:56 +04:00
volListModel . set_sort_column_id ( 1 , Gtk . SortType . ASCENDING )
2009-11-17 23:44:27 +03:00
2014-07-23 17:48:17 +04:00
self . init_pool_list ( )
2009-11-17 23:44:27 +03:00
2010-02-09 01:13:36 +03:00
def init_interface_state ( self ) :
2011-07-14 21:13:13 +04:00
self . widget ( " interface-pages " ) . set_show_tabs ( False )
2010-02-09 01:13:36 +03:00
# [ unique, label, icon name, icon size, is_active ]
2012-05-14 17:24:56 +04:00
interfaceListModel = Gtk . ListStore ( str , str , str , int , bool )
2011-07-14 21:13:13 +04:00
self . widget ( " interface-list " ) . set_model ( interfaceListModel )
2010-02-09 01:13:36 +03:00
2014-07-23 17:48:17 +04:00
sel = self . widget ( " interface-list " ) . get_selection ( )
sel . set_select_function ( ( lambda * x : self . confirm_changes ( ) ) , None )
2012-05-14 17:24:56 +04:00
interfaceCol = Gtk . TreeViewColumn ( " Interfaces " )
2010-02-09 01:13:36 +03:00
interfaceCol . set_spacing ( 6 )
2012-05-14 17:24:56 +04:00
interface_txt = Gtk . CellRendererText ( )
interface_img = Gtk . CellRendererPixbuf ( )
2010-02-09 01:13:36 +03:00
interfaceCol . pack_start ( interface_img , False )
interfaceCol . pack_start ( interface_txt , True )
interfaceCol . add_attribute ( interface_txt , ' text ' , 1 )
interfaceCol . add_attribute ( interface_txt , ' sensitive ' , 4 )
interfaceCol . add_attribute ( interface_img , ' icon-name ' , 2 )
interfaceCol . add_attribute ( interface_img , ' stock-size ' , 3 )
2011-07-14 21:13:13 +04:00
self . widget ( " interface-list " ) . append_column ( interfaceCol )
2012-05-14 17:24:56 +04:00
interfaceListModel . set_sort_column_id ( 1 , Gtk . SortType . ASCENDING )
2010-02-09 01:13:36 +03:00
2014-05-21 12:41:30 +04:00
# Startmode combo
2014-01-27 02:09:07 +04:00
vmmCreateInterface . build_interface_startmode_combo (
self . widget ( " interface-startmode " ) )
2010-02-09 01:13:36 +03:00
# [ name, type ]
2012-05-14 17:24:56 +04:00
childListModel = Gtk . ListStore ( str , str )
2011-07-14 21:13:13 +04:00
childList = self . widget ( " interface-child-list " )
2010-02-09 01:13:36 +03:00
childList . set_model ( childListModel )
2012-05-14 17:24:56 +04:00
childNameCol = Gtk . TreeViewColumn ( " Name " )
child_txt1 = Gtk . CellRendererText ( )
2010-02-09 01:13:36 +03:00
childNameCol . pack_start ( child_txt1 , True )
childNameCol . add_attribute ( child_txt1 , ' text ' , 0 )
childNameCol . set_sort_column_id ( 0 )
childList . append_column ( childNameCol )
2012-05-14 17:24:56 +04:00
childTypeCol = Gtk . TreeViewColumn ( " Interface Type " )
child_txt2 = Gtk . CellRendererText ( )
2010-02-09 01:13:36 +03:00
childTypeCol . pack_start ( child_txt2 , True )
childTypeCol . add_attribute ( child_txt2 , ' text ' , 1 )
childTypeCol . set_sort_column_id ( 1 )
childList . append_column ( childTypeCol )
2012-05-14 17:24:56 +04:00
childListModel . set_sort_column_id ( 0 , Gtk . SortType . ASCENDING )
2010-02-09 01:13:36 +03:00
2009-11-17 23:44:27 +03:00
def init_conn_state ( self ) :
uri = self . conn . get_uri ( )
host = self . conn . get_hostname ( )
drv = self . conn . get_driver ( )
memory = self . conn . pretty_host_memory_size ( )
proc = self . conn . host_active_processor_count ( )
arch = self . conn . host_architecture ( )
auto = self . conn . get_autoconnect ( )
2011-07-14 21:13:13 +04:00
self . widget ( " overview-uri " ) . set_text ( uri )
self . widget ( " overview-hostname " ) . set_text ( host )
self . widget ( " overview-hypervisor " ) . set_text ( drv )
self . widget ( " overview-memory " ) . set_text ( memory )
self . widget ( " overview-cpus " ) . set_text ( str ( proc ) )
self . widget ( " overview-arch " ) . set_text ( arch )
self . widget ( " config-autoconnect " ) . set_active ( auto )
2009-11-17 23:44:27 +03:00
self . cpu_usage_graph = Sparkline ( )
self . cpu_usage_graph . show ( )
2013-09-27 22:17:57 +04:00
self . widget ( " performance-cpu-align " ) . add ( self . cpu_usage_graph )
2009-11-17 23:44:27 +03:00
self . memory_usage_graph = Sparkline ( )
self . memory_usage_graph . show ( )
2013-09-27 22:17:57 +04:00
self . widget ( " performance-memory-align " ) . add ( self . memory_usage_graph )
2009-11-17 23:44:27 +03:00
2007-03-28 03:52:00 +04:00
def show ( self ) :
2012-02-01 03:16:54 +04:00
logging . debug ( " Showing host details: %s " , self . conn )
2010-12-09 01:26:19 +03:00
vis = self . is_visible ( )
2010-02-23 22:18:12 +03:00
self . topwin . present ( )
2010-12-09 01:26:19 +03:00
if vis :
return
2007-03-28 03:52:00 +04:00
2011-04-13 18:47:31 +04:00
self . emit ( " host-opened " )
2009-11-17 23:18:38 +03:00
2007-03-28 03:52:00 +04:00
def is_visible ( self ) :
2012-05-14 17:24:56 +04:00
return self . topwin . get_visible ( )
2007-03-28 03:52:00 +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 host details: %s " , self . conn )
2010-12-09 01:26:19 +03:00
if not self . is_visible ( ) :
return
2014-07-23 17:48:17 +04:00
self . confirm_changes ( )
2010-12-09 01:26:19 +03:00
self . topwin . hide ( )
2011-04-13 18:47:31 +04:00
self . emit ( " host-closed " )
2008-08-15 19:07:45 +04:00
return 1
2007-08-29 05:43:27 +04:00
2011-07-24 05:16:54 +04:00
def _cleanup ( self ) :
self . conn = None
2011-04-13 17:27:02 +04:00
2011-07-24 05:16:54 +04:00
if self . addnet :
self . addnet . cleanup ( )
self . addnet = None
2011-04-13 17:27:02 +04:00
2011-07-24 05:16:54 +04:00
if self . addpool :
self . addpool . cleanup ( )
self . addpool = None
2011-04-13 17:27:02 +04:00
2011-07-24 05:16:54 +04:00
if self . addvol :
self . addvol . cleanup ( )
self . addvol = None
2011-04-13 17:27:02 +04:00
2011-07-24 05:16:54 +04:00
if self . addinterface :
self . addinterface . cleanup ( )
self . addinterface = None
2011-04-13 17:27:02 +04:00
2011-07-24 05:16:54 +04:00
self . volmenu . destroy ( )
self . volmenu = None
2011-04-13 17:27:02 +04:00
2011-07-24 05:16:54 +04:00
self . cpu_usage_graph . destroy ( )
self . cpu_usage_graph = None
2011-04-13 17:27:02 +04:00
2011-07-24 05:16:54 +04:00
self . memory_usage_graph . destroy ( )
self . memory_usage_graph = None
2011-04-13 17:27:02 +04:00
2010-12-09 19:22:35 +03:00
def view_manager ( self , src_ignore ) :
2009-11-17 23:18:38 +03:00
self . emit ( " action-view-manager " )
2010-12-09 19:22:35 +03:00
def restore_domain ( self , src_ignore ) :
2010-05-12 19:42:59 +04:00
self . emit ( " action-restore-domain " , self . conn . get_uri ( ) )
2010-12-09 19:22:35 +03:00
def exit_app ( self , src_ignore ) :
2009-11-17 23:18:38 +03:00
self . emit ( " action-exit-app " )
2008-09-18 18:33:53 +04:00
def reset_state ( self ) :
self . refresh_resources ( )
self . conn_state_changed ( )
2009-11-25 22:16:31 +03:00
2009-11-17 23:44:27 +03:00
# Update autostart value
auto = self . conn . get_autoconnect ( )
2011-07-14 21:13:13 +04:00
self . widget ( " config-autoconnect " ) . set_active ( auto )
2008-09-18 18:33:53 +04:00
2013-07-07 19:06:15 +04:00
def page_changed ( self , src , child , pagenum ) :
ignore = src
ignore = child
2014-07-23 17:48:17 +04:00
self . confirm_changes ( )
2013-07-07 19:06:15 +04:00
if pagenum == 1 :
2014-07-23 17:48:17 +04:00
self . repopulate_networks ( )
2013-07-07 19:06:15 +04:00
self . conn . schedule_priority_tick ( pollnet = True )
elif pagenum == 2 :
2014-07-23 17:48:17 +04:00
self . repopulate_storage_volumes ( )
2013-07-07 19:06:15 +04:00
self . conn . schedule_priority_tick ( pollpool = True )
elif pagenum == 3 :
2014-07-23 17:48:17 +04:00
self . repopulate_interfaces ( )
2013-07-07 19:06:15 +04:00
self . conn . schedule_priority_tick ( polliface = True )
2007-03-28 03:52:00 +04:00
def refresh_resources ( self , ignore = None ) :
2011-04-10 07:03:01 +04:00
vm_memory = self . conn . pretty_stats_memory ( )
2007-03-28 03:52:00 +04:00
host_memory = self . conn . pretty_host_memory_size ( )
2011-07-12 05:22:50 +04:00
cpu_vector = self . conn . host_cpu_time_vector ( )
memory_vector = self . conn . stats_memory_vector ( )
2007-03-28 03:52:00 +04:00
cpu_vector . reverse ( )
memory_vector . reverse ( )
2011-07-12 05:22:50 +04:00
2011-07-14 21:13:13 +04:00
self . widget ( " performance-cpu " ) . set_text ( " %d %% " %
2011-07-12 05:22:50 +04:00
self . conn . host_cpu_time_percentage ( ) )
2011-07-14 21:13:13 +04:00
self . widget ( " performance-memory " ) . set_text (
2011-07-12 05:22:50 +04:00
_ ( " %(currentmem)s of %(maxmem)s " ) %
{ ' currentmem ' : vm_memory , ' maxmem ' : host_memory } )
self . cpu_usage_graph . set_property ( " data_array " , cpu_vector )
2007-03-28 03:52:00 +04:00
self . memory_usage_graph . set_property ( " data_array " , memory_vector )
2008-09-18 18:33:53 +04:00
def conn_state_changed ( self , ignore1 = None ) :
2014-09-12 02:16:21 +04:00
conn_active = self . conn . is_active ( )
2013-06-30 20:42:49 +04:00
self . widget ( " menu_file_restore_saved " ) . set_sensitive ( conn_active )
self . widget ( " net-add " ) . set_sensitive ( conn_active and
self . conn . is_network_capable ( ) )
self . widget ( " pool-add " ) . set_sensitive ( conn_active and
self . conn . is_storage_capable ( ) )
self . widget ( " interface-add " ) . set_sensitive ( conn_active and
self . conn . is_interface_capable ( ) )
if not conn_active :
2010-03-21 01:42:32 +03:00
self . set_net_error_page ( _ ( " Connection not active. " ) )
self . set_storage_error_page ( _ ( " Connection not active. " ) )
self . set_interface_error_page ( _ ( " Connection not active. " ) )
2013-06-30 20:42:49 +04:00
self . repopulate_networks ( )
self . repopulate_storage_pools ( )
self . repopulate_interfaces ( )
2010-03-21 01:42:32 +03:00
return
2013-07-07 01:24:51 +04:00
if not self . conn . is_network_capable ( ) :
2010-03-21 01:42:32 +03:00
self . set_net_error_page (
_ ( " Libvirt connection does not support virtual network "
" management. " ) )
2011-04-10 05:27:41 +04:00
if not self . conn . is_storage_capable ( ) :
2010-03-21 01:42:32 +03:00
self . set_storage_error_page (
_ ( " Libvirt connection does not support storage management. " ) )
2013-07-07 01:24:51 +04:00
if not self . conn . is_interface_capable ( ) :
2010-03-21 01:42:32 +03:00
self . set_interface_error_page (
_ ( " Libvirt connection does not support interface management. " ) )
2009-11-25 22:16:31 +03:00
def toggle_autoconnect ( self , src ) :
self . conn . set_autoconnect ( src . get_active ( ) )
2009-11-17 23:44:27 +03:00
2013-10-01 02:46:54 +04:00
2008-08-15 19:07:45 +04:00
# -------------------------
# Virtual Network functions
# -------------------------
2010-12-09 19:22:35 +03:00
def delete_network ( self , src_ignore ) :
2008-08-15 19:07:45 +04:00
net = self . current_network ( )
2008-08-26 20:10:25 +04:00
if net is None :
return
2009-01-24 00:34:33 +03:00
result = self . err . yes_no ( _ ( " Are you sure you want to permanently "
" delete the network %s ? " ) % net . get_name ( ) )
2008-08-26 20:10:25 +04:00
if not result :
return
2010-12-10 22:02:11 +03:00
2012-01-17 07:04:40 +04:00
logging . debug ( " Deleting network ' %s ' " , net . get_name ( ) )
2011-04-15 23:23:13 +04:00
vmmAsyncJob . simple_async_noshow ( net . delete , [ ] , self ,
_ ( " Error deleting network ' %s ' " ) % net . get_name ( ) )
2008-08-15 19:07:45 +04:00
2010-12-09 19:22:35 +03:00
def start_network ( self , src_ignore ) :
2008-08-15 19:07:45 +04:00
net = self . current_network ( )
2008-08-26 20:10:25 +04:00
if net is None :
return
2012-01-17 07:04:40 +04:00
logging . debug ( " Starting network ' %s ' " , net . get_name ( ) )
2011-04-15 23:23:13 +04:00
vmmAsyncJob . simple_async_noshow ( net . start , [ ] , self ,
_ ( " Error starting network ' %s ' " ) % net . get_name ( ) )
2008-08-15 19:07:45 +04:00
2010-12-09 19:22:35 +03:00
def stop_network ( self , src_ignore ) :
2008-08-15 19:07:45 +04:00
net = self . current_network ( )
2008-08-26 20:10:25 +04:00
if net is None :
return
2012-01-17 07:04:40 +04:00
logging . debug ( " Stopping network ' %s ' " , net . get_name ( ) )
2011-04-15 23:23:13 +04:00
vmmAsyncJob . simple_async_noshow ( net . stop , [ ] , self ,
_ ( " Error stopping network ' %s ' " ) % net . get_name ( ) )
2008-08-15 19:07:45 +04:00
2010-12-09 19:22:35 +03:00
def add_network ( self , src_ignore ) :
2010-12-10 22:02:11 +03:00
logging . debug ( " Launching ' Add Network ' " )
2008-08-26 20:10:25 +04:00
try :
if self . addnet is None :
2010-12-09 01:26:19 +03:00
self . addnet = vmmCreateNetwork ( self . conn )
2011-04-14 16:47:42 +04:00
self . addnet . show ( self . topwin )
2008-08-26 20:10:25 +04:00
except Exception , e :
2011-04-06 19:22:03 +04:00
self . err . show_err ( _ ( " Error launching network wizard: %s " ) % str ( e ) )
2008-08-15 19:07:45 +04:00
2014-07-23 17:48:17 +04:00
def net_apply ( self ) :
2008-08-26 19:17:31 +04:00
net = self . current_network ( )
if net is None :
return
2012-01-17 07:04:40 +04:00
logging . debug ( " Applying changes for network ' %s ' " , net . get_name ( ) )
2008-08-26 19:17:31 +04:00
try :
2013-09-29 20:28:01 +04:00
if EDIT_NET_AUTOSTART in self . active_edits :
2013-09-29 20:14:00 +04:00
auto = self . widget ( " net-autostart " ) . get_active ( )
net . set_autostart ( auto )
2013-09-29 20:28:01 +04:00
if EDIT_NET_NAME in self . active_edits :
2013-09-29 20:14:00 +04:00
net . define_name ( self . widget ( " net-name " ) . get_text ( ) )
2014-09-21 01:21:16 +04:00
self . idle_add ( self . repopulate_networks )
2014-06-25 14:36:46 +04:00
if EDIT_NET_QOS in self . active_edits :
in_qos = self . widget ( " net-qos-inbound-enable " ) . get_active ( )
out_qos = self . widget ( " net-qos-outbound-enable " ) . get_active ( )
def get_value ( name , enabled ) :
if not enabled :
return None
return self . widget ( name ) . get_text ( ) or None
args = { }
args [ ' inbound_average ' ] = get_value ( " qos-inbound-average " , in_qos )
args [ ' inbound_peak ' ] = get_value ( " qos-inbound-peak " , in_qos )
args [ ' inbound_burst ' ] = get_value ( " qos-inbound-burst " , in_qos )
args [ ' outbound_average ' ] = get_value ( " qos-outbound-average " , out_qos )
args [ ' outbound_peak ' ] = get_value ( " qos-outbound-peak " , out_qos )
args [ ' outbound_burst ' ] = get_value ( " qos-outbound-burst " , out_qos )
if net . set_qos ( * * args ) :
self . err . show_err (
_ ( " Network could not be updated " ) ,
text2 = _ ( " This change will take effect when the "
" network is restarted " ) ,
buttons = Gtk . ButtonsType . OK ,
dialog_type = Gtk . MessageType . INFO )
2008-08-26 19:17:31 +04:00
except Exception , e :
2013-10-01 02:46:54 +04:00
self . err . show_err ( _ ( " Error changing network settings: %s " ) % str ( e ) )
2008-08-26 19:17:31 +04:00
return
2013-09-29 20:14:00 +04:00
finally :
self . disable_net_apply ( )
def disable_net_apply ( self ) :
2014-07-23 17:48:17 +04:00
for i in EDIT_NET_IDS :
if i in self . active_edits :
self . active_edits . remove ( i )
2011-07-14 21:13:13 +04:00
self . widget ( " net-apply " ) . set_sensitive ( False )
2008-08-26 19:17:31 +04:00
2014-07-23 17:48:17 +04:00
def disable_interface_apply ( self ) :
for i in EDIT_INTERFACE_IDS :
if i in self . active_edits :
self . active_edits . remove ( i )
self . widget ( " interface-apply " ) . set_sensitive ( False )
2013-09-29 20:14:00 +04:00
def enable_net_apply ( self , * arglist ) :
edittype = arglist [ - 1 ]
self . widget ( " net-apply " ) . set_sensitive ( True )
2013-09-29 20:28:01 +04:00
if edittype not in self . active_edits :
self . active_edits . append ( edittype )
2013-09-29 20:14:00 +04:00
2014-07-23 17:48:17 +04:00
def enable_interface_apply ( self , * arglist ) :
edittype = arglist [ - 1 ]
self . widget ( " interface-apply " ) . set_sensitive ( True )
if edittype not in self . active_edits :
self . active_edits . append ( edittype )
2010-12-09 19:22:35 +03:00
def net_autostart_changed ( self , src_ignore ) :
2011-07-14 21:13:13 +04:00
auto = self . widget ( " net-autostart " ) . get_active ( )
self . widget ( " net-autostart " ) . set_label ( auto and
_ ( " On Boot " ) or
_ ( " Never " ) )
2013-09-29 20:14:00 +04:00
self . enable_net_apply ( EDIT_NET_AUTOSTART )
2008-08-26 19:17:31 +04:00
2007-04-03 22:01:45 +04:00
def current_network ( self ) :
2014-06-03 01:17:47 +04:00
connkey = uiutil . get_list_selection ( self . widget ( " net-list " ) , 0 )
2013-10-01 02:46:54 +04:00
try :
2014-06-03 01:17:47 +04:00
return connkey and self . conn . get_net ( connkey )
2013-10-01 02:46:54 +04:00
except KeyError :
2014-01-27 05:21:12 +04:00
return None
2007-04-03 22:01:45 +04:00
2014-06-03 01:17:47 +04:00
def refresh_network ( self , src_ignore , connkey ) :
2011-07-14 21:13:13 +04:00
uilist = self . widget ( " net-list " )
2010-12-10 22:02:11 +03:00
sel = uilist . get_selection ( )
2014-01-27 05:21:12 +04:00
model , treeiter = sel . get_selected ( )
2014-06-03 01:17:47 +04:00
net = self . conn . get_net ( connkey )
2013-07-07 19:06:15 +04:00
net . tick ( )
2010-12-10 22:02:11 +03:00
for row in uilist . get_model ( ) :
2014-06-03 01:17:47 +04:00
if row [ 0 ] == connkey :
2013-07-07 19:06:15 +04:00
row [ 4 ] = net . is_active ( )
2010-12-10 22:02:11 +03:00
2014-01-27 05:21:12 +04:00
if treeiter is not None :
2014-06-03 01:17:47 +04:00
if model [ treeiter ] [ 0 ] == connkey :
2007-04-03 22:01:45 +04:00
self . net_selected ( sel )
2007-03-28 03:52:00 +04:00
2010-02-26 01:31:27 +03:00
def set_net_error_page ( self , msg ) :
self . reset_net_state ( )
2011-07-14 21:13:13 +04:00
self . widget ( " network-pages " ) . set_current_page ( 1 )
self . widget ( " network-error-label " ) . set_text ( msg )
2010-02-26 01:31:27 +03:00
2007-03-28 03:52:00 +04:00
def net_selected ( self , src ) :
2014-01-27 05:21:12 +04:00
model , treeiter = src . get_selected ( )
if treeiter is None :
2010-02-26 01:31:27 +03:00
self . set_net_error_page ( _ ( " No virtual network selected. " ) )
2008-08-26 18:55:03 +04:00
return
2009-03-08 22:34:15 +03:00
2011-07-14 21:13:13 +04:00
self . widget ( " network-pages " ) . set_current_page ( 0 )
2014-06-03 01:17:47 +04:00
connkey = model [ treeiter ] [ 0 ]
2013-03-29 22:38:28 +04:00
try :
2014-06-03 01:17:47 +04:00
net = self . conn . get_net ( connkey )
2013-03-29 22:38:28 +04:00
except KeyError :
2013-09-29 20:14:00 +04:00
self . disable_net_apply ( )
2013-03-29 22:38:28 +04:00
return
except Exception , e :
logging . exception ( e )
self . set_net_error_page ( _ ( " Error selecting network: %s " ) % e )
2010-02-26 01:42:00 +03:00
try :
self . populate_net_state ( net )
except Exception , e :
logging . exception ( e )
self . set_net_error_page ( _ ( " Error selecting network: %s " ) % e )
2013-09-29 20:14:00 +04:00
finally :
self . disable_net_apply ( )
2010-02-26 03:42:08 +03:00
2013-09-21 04:40:07 +04:00
def _populate_net_ipv4_state ( self , net ) :
( netstr ,
( dhcpstart , dhcpend ) ,
( routeaddr , routevia ) ) = net . get_ipv4_network ( )
self . widget ( " net-ipv4-expander " ) . set_visible ( bool ( netstr ) )
if not netstr :
return
forward = net . get_ipv4_forward_mode ( )
self . widget ( " net-ipv4-forwarding-icon " ) . set_from_stock (
forward and Gtk . STOCK_CONNECT or Gtk . STOCK_DISCONNECT ,
Gtk . IconSize . MENU )
self . widget ( " net-ipv4-forwarding " ) . set_text ( net . pretty_forward_mode ( ) )
dhcpstr = _ ( " Disabled " )
if dhcpstart :
dhcpstr = dhcpstart + " - " + dhcpend
self . widget ( " net-ipv4-dhcp-range " ) . set_text ( dhcpstr )
self . widget ( " net-ipv4-network " ) . set_text ( netstr )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible (
2013-09-21 04:40:07 +04:00
self . widget ( " net-ipv4-route " ) , bool ( routevia ) )
if routevia :
routevia = routeaddr + " , gateway= " + routevia
self . widget ( " net-ipv4-route " ) . set_text ( routevia or " " )
def _populate_net_ipv6_state ( self , net ) :
( netstr ,
( dhcpstart , dhcpend ) ,
( routeaddr , routevia ) ) = net . get_ipv6_network ( )
self . widget ( " net-ipv6-expander " ) . set_visible ( bool ( netstr ) )
self . widget ( " net-ipv6-forwarding-icon " ) . set_from_stock (
netstr and Gtk . STOCK_CONNECT or Gtk . STOCK_DISCONNECT ,
Gtk . IconSize . MENU )
if netstr :
prettymode = _ ( " Routed network " )
elif net . get_ipv6_enabled ( ) :
prettymode = _ ( " Isolated network, internal routing only " )
else :
prettymode = _ ( " Isolated network, routing disabled " )
self . widget ( " net-ipv6-forwarding " ) . set_text ( prettymode )
dhcpstr = _ ( " Disabled " )
if dhcpstart :
dhcpstr = dhcpstart + " - " + dhcpend
self . widget ( " net-ipv6-dhcp-range " ) . set_text ( dhcpstr )
self . widget ( " net-ipv6-network " ) . set_text ( netstr or " " )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible (
2013-09-21 04:40:07 +04:00
self . widget ( " net-ipv6-route " ) , bool ( routevia ) )
if routevia :
routevia = routeaddr + " , gateway= " + routevia
self . widget ( " net-ipv6-route " ) . set_text ( routevia or " " )
2014-06-25 14:36:46 +04:00
def update_qos_widgets ( self ) :
enabled = self . widget ( " net-qos-inbound-enable " ) . get_active ( )
self . widget ( " net-qos-inbound-grid " ) . set_visible ( enabled )
enabled = self . widget ( " net-qos-outbound-enable " ) . get_active ( )
self . widget ( " net-qos-outbound-grid " ) . set_visible ( enabled )
def change_qos_in_enable ( self , ignore ) :
self . enable_net_apply ( EDIT_NET_QOS )
self . update_qos_widgets ( )
def change_qos_out_enable ( self , ignore ) :
self . enable_net_apply ( EDIT_NET_QOS )
self . update_qos_widgets ( )
def _populate_qos_state ( self , net ) :
qos = net . get_qos ( )
self . widget ( " net-qos-inbound-enable " ) . set_active ( qos . is_inbound ( ) )
self . widget ( " net-qos-outbound-enable " ) . set_active ( qos . is_outbound ( ) )
self . update_qos_widgets ( )
self . widget ( " qos-inbound-average " ) . set_text ( qos . inbound_average or " " )
self . widget ( " qos-inbound-peak " ) . set_text ( qos . inbound_peak or " " )
self . widget ( " qos-inbound-burst " ) . set_text ( qos . inbound_burst or " " )
self . widget ( " qos-outbound-average " ) . set_text ( qos . outbound_average or " " )
self . widget ( " qos-outbound-peak " ) . set_text ( qos . outbound_peak or " " )
self . widget ( " qos-outbound-burst " ) . set_text ( qos . outbound_burst or " " )
2010-02-26 01:42:00 +03:00
def populate_net_state ( self , net ) :
2008-08-26 18:55:03 +04:00
active = net . is_active ( )
2011-07-14 21:13:13 +04:00
self . widget ( " net-details " ) . set_sensitive ( True )
2013-09-29 20:14:00 +04:00
self . widget ( " net-name " ) . set_text ( net . get_name ( ) )
self . widget ( " net-name " ) . set_editable ( not active )
2013-09-21 04:40:07 +04:00
self . widget ( " net-device " ) . set_text ( net . get_bridge_device ( ) or " " )
self . widget ( " net-name-domain " ) . set_text ( net . get_name_domain ( ) or " " )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( " net-name-domain " ) ,
2013-09-21 04:40:07 +04:00
bool ( net . get_name_domain ( ) ) )
2008-08-26 18:55:03 +04:00
2009-11-16 15:14:49 +03:00
state = active and _ ( " Active " ) or _ ( " Inactive " )
2011-07-12 19:50:11 +04:00
icon = ( active and self . ICON_RUNNING or
self . ICON_SHUTOFF )
2011-07-14 21:13:13 +04:00
self . widget ( " net-state " ) . set_text ( state )
self . widget ( " net-state-icon " ) . set_from_icon_name ( icon ,
2014-01-12 23:36:03 +04:00
Gtk . IconSize . BUTTON )
2008-08-26 18:55:03 +04:00
2011-07-14 21:13:13 +04:00
self . widget ( " net-start " ) . set_sensitive ( not active )
self . widget ( " net-stop " ) . set_sensitive ( active )
self . widget ( " net-delete " ) . set_sensitive ( not active )
2008-08-26 18:55:03 +04:00
autostart = net . get_autostart ( )
2009-11-16 15:14:49 +03:00
autolabel = autostart and _ ( " On Boot " ) or _ ( " Never " )
2011-07-14 21:13:13 +04:00
self . widget ( " net-autostart " ) . set_active ( autostart )
self . widget ( " net-autostart " ) . set_label ( autolabel )
2008-08-26 18:55:03 +04:00
2013-09-21 04:40:07 +04:00
self . _populate_net_ipv4_state ( net )
self . _populate_net_ipv6_state ( net )
2014-06-25 14:36:46 +04:00
self . _populate_qos_state ( net )
2013-03-29 22:38:28 +04:00
2008-08-26 19:17:31 +04:00
2008-08-26 18:55:03 +04:00
def reset_net_state ( self ) :
2011-07-14 21:13:13 +04:00
self . widget ( " net-details " ) . set_sensitive ( False )
self . widget ( " net-name " ) . set_text ( " " )
self . widget ( " net-device " ) . set_text ( " " )
self . widget ( " net-state " ) . set_text ( _ ( " Inactive " ) )
self . widget ( " net-state-icon " ) . set_from_icon_name ( self . ICON_SHUTOFF ,
2014-01-12 23:36:03 +04:00
Gtk . IconSize . BUTTON )
2011-07-14 21:13:13 +04:00
self . widget ( " net-start " ) . set_sensitive ( False )
self . widget ( " net-stop " ) . set_sensitive ( False )
self . widget ( " net-delete " ) . set_sensitive ( False )
self . widget ( " net-autostart " ) . set_label ( _ ( " Never " ) )
self . widget ( " net-autostart " ) . set_active ( False )
2013-09-21 04:40:07 +04:00
self . widget ( " net-ipv4-network " ) . set_text ( " " )
self . widget ( " net-ipv4-dhcp-range " ) . set_text ( " " )
self . widget ( " net-ipv4-route " ) . set_text ( " " )
self . widget ( " net-ipv4-forwarding-icon " ) . set_from_stock (
2012-05-14 17:24:56 +04:00
Gtk . STOCK_DISCONNECT , Gtk . IconSize . MENU )
2013-09-21 04:40:07 +04:00
self . widget ( " net-ipv4-forwarding " ) . set_text (
2013-03-29 22:38:28 +04:00
_ ( " Isolated network " ) )
2013-09-21 04:40:07 +04:00
self . widget ( " net-ipv6-network " ) . set_text ( " " )
self . widget ( " net-ipv6-dhcp-range " ) . set_text ( " " )
self . widget ( " net-ipv6-route " ) . set_text ( " " )
self . widget ( " net-ipv6-forwarding " ) . set_text (
2013-03-29 22:38:28 +04:00
_ ( " Isolated network " ) )
2013-09-29 20:14:00 +04:00
self . disable_net_apply ( )
2007-03-28 03:52:00 +04:00
2014-06-03 01:17:47 +04:00
def repopulate_networks ( self , src = None , connkey = None ) :
ignore = src
ignore = connkey
2011-07-14 21:13:13 +04:00
self . populate_networks ( self . widget ( " net-list " ) . get_model ( ) )
2007-03-30 05:23:17 +04:00
2007-03-28 03:52:00 +04:00
def populate_networks ( self , model ) :
2013-10-01 02:46:54 +04:00
curnet = self . current_network ( )
2011-07-14 21:13:13 +04:00
net_list = self . widget ( " net-list " )
2014-03-14 05:04:34 +04:00
net_list . get_selection ( ) . unselect_all ( )
2007-03-28 03:52:00 +04:00
model . clear ( )
2014-06-03 01:17:47 +04:00
for net in self . conn . list_nets ( ) :
model . append ( [ net . get_connkey ( ) , net . get_name ( ) , " network-idle " ,
2012-05-14 17:24:56 +04:00
Gtk . IconSize . LARGE_TOOLBAR ,
2009-11-20 01:29:20 +03:00
bool ( net . is_active ( ) ) ] )
2007-03-28 03:52:00 +04:00
2014-01-27 03:15:50 +04:00
uiutil . set_row_selection ( net_list ,
2014-06-03 01:17:47 +04:00
curnet and curnet . get_connkey ( ) or None )
2009-03-08 22:34:15 +03:00
2007-03-28 03:52:00 +04:00
2008-08-15 19:07:45 +04:00
# ------------------------------
# Storage Manager methods
# ------------------------------
2010-12-09 19:22:35 +03:00
def stop_pool ( self , src_ignore ) :
2008-08-15 19:07:45 +04:00
pool = self . current_pool ( )
2010-12-10 22:02:11 +03:00
if pool is None :
return
2012-01-17 07:04:40 +04:00
logging . debug ( " Stopping pool ' %s ' " , pool . get_name ( ) )
2011-04-15 23:23:13 +04:00
vmmAsyncJob . simple_async_noshow ( pool . stop , [ ] , self ,
_ ( " Error stopping pool ' %s ' " ) % pool . get_name ( ) )
2008-08-15 19:07:45 +04:00
2010-12-09 19:22:35 +03:00
def start_pool ( self , src_ignore ) :
2008-08-15 19:07:45 +04:00
pool = self . current_pool ( )
2010-12-10 22:02:11 +03:00
if pool is None :
return
2012-01-17 07:04:40 +04:00
logging . debug ( " Starting pool ' %s ' " , pool . get_name ( ) )
2011-04-15 23:23:13 +04:00
vmmAsyncJob . simple_async_noshow ( pool . start , [ ] , self ,
_ ( " Error starting pool ' %s ' " ) % pool . get_name ( ) )
2008-08-15 19:07:45 +04:00
2010-12-09 19:22:35 +03:00
def delete_pool ( self , src_ignore ) :
2008-08-15 19:07:45 +04:00
pool = self . current_pool ( )
if pool is None :
return
2009-01-24 00:34:33 +03:00
result = self . err . yes_no ( _ ( " Are you sure you want to permanently "
" delete the pool %s ? " ) % pool . get_name ( ) )
2008-08-15 19:07:45 +04:00
if not result :
return
2010-12-10 22:02:11 +03:00
2012-01-17 07:04:40 +04:00
logging . debug ( " Deleting pool ' %s ' " , pool . get_name ( ) )
2011-04-15 23:23:13 +04:00
vmmAsyncJob . simple_async_noshow ( pool . delete , [ ] , self ,
_ ( " Error deleting pool ' %s ' " ) % pool . get_name ( ) )
2008-08-15 19:07:45 +04:00
2010-12-09 19:22:35 +03:00
def pool_refresh ( self , src_ignore ) :
2012-02-08 04:05:45 +04:00
if self . _in_refresh :
logging . debug ( " Already refreshing the pool, skipping " )
return
2014-07-23 17:48:17 +04:00
if not self . confirm_changes ( ) :
return
2010-04-21 18:56:06 +04:00
pool = self . current_pool ( )
if pool is None :
return
2012-02-08 04:05:45 +04:00
self . _in_refresh = True
2011-04-15 23:23:13 +04:00
def cb ( ) :
2012-02-08 04:05:45 +04:00
try :
pool . refresh ( )
2012-02-10 23:07:51 +04:00
self . idle_add ( self . refresh_current_pool )
2012-02-08 04:05:45 +04:00
finally :
self . _in_refresh = False
2011-04-15 23:23:13 +04:00
2012-01-17 07:04:40 +04:00
logging . debug ( " Refresh pool ' %s ' " , pool . get_name ( ) )
2011-04-15 23:23:13 +04:00
vmmAsyncJob . simple_async_noshow ( cb , [ ] , self ,
_ ( " Error refreshing pool ' %s ' " ) % pool . get_name ( ) )
2010-04-21 18:56:06 +04:00
2010-12-09 19:22:35 +03:00
def delete_vol ( self , src_ignore ) :
2008-08-15 19:07:45 +04:00
vol = self . current_vol ( )
if vol is None :
return
2009-01-24 00:34:33 +03:00
result = self . err . yes_no ( _ ( " Are you sure you want to permanently "
" delete the volume %s ? " ) % vol . get_name ( ) )
2008-08-15 19:07:45 +04:00
if not result :
return
2011-04-15 23:23:13 +04:00
def cb ( ) :
2008-08-15 19:07:45 +04:00
vol . delete ( )
2012-02-10 23:07:51 +04:00
def idlecb ( ) :
self . refresh_current_pool ( )
2013-12-05 03:57:43 +04:00
self . repopulate_storage_volumes ( )
2012-02-10 23:07:51 +04:00
self . idle_add ( idlecb )
2011-04-15 23:23:13 +04:00
2012-01-17 07:04:40 +04:00
logging . debug ( " Deleting volume ' %s ' " , vol . get_name ( ) )
2011-04-15 23:23:13 +04:00
vmmAsyncJob . simple_async_noshow ( cb , [ ] , self ,
_ ( " Error refreshing volume ' %s ' " ) % vol . get_name ( ) )
2008-08-15 19:07:45 +04:00
2010-12-09 19:22:35 +03:00
def add_pool ( self , src_ignore ) :
2010-12-10 22:02:11 +03:00
logging . debug ( " Launching ' Add Pool ' wizard " )
2008-08-26 20:10:25 +04:00
try :
if self . addpool is None :
2010-12-09 01:26:19 +03:00
self . addpool = vmmCreatePool ( self . conn )
2011-04-14 16:47:42 +04:00
self . addpool . show ( self . topwin )
2008-08-26 20:10:25 +04:00
except Exception , e :
2011-04-06 19:22:03 +04:00
self . err . show_err ( _ ( " Error launching pool wizard: %s " ) % str ( e ) )
2008-08-15 19:07:45 +04:00
2010-12-09 19:22:35 +03:00
def add_vol ( self , src_ignore ) :
2008-08-15 19:07:45 +04:00
pool = self . current_pool ( )
if pool is None :
return
2010-12-10 22:02:11 +03:00
2012-01-17 07:04:40 +04:00
logging . debug ( " Launching ' Add Volume ' wizard for pool ' %s ' " ,
2010-12-10 22:02:11 +03:00
pool . get_name ( ) )
2008-08-15 20:44:45 +04:00
try :
if self . addvol is None :
2010-12-09 01:26:19 +03:00
self . addvol = vmmCreateVolume ( self . conn , pool )
2008-08-15 20:44:45 +04:00
self . addvol . connect ( " vol-created " , self . refresh_current_pool )
else :
2013-08-13 16:26:26 +04:00
self . addvol . set_parent_pool ( self . conn , pool )
2011-04-14 16:47:42 +04:00
self . addvol . show ( self . topwin )
2008-08-15 20:44:45 +04:00
except Exception , e :
2011-04-06 19:22:03 +04:00
self . err . show_err ( _ ( " Error launching volume wizard: %s " ) % str ( e ) )
2008-08-15 19:07:45 +04:00
def refresh_current_pool ( self , ignore1 = None ) :
cp = self . current_pool ( )
if cp is None :
return
2008-09-07 23:35:13 +04:00
cp . refresh ( )
2014-06-03 01:17:47 +04:00
self . refresh_storage_pool ( None , cp . get_connkey ( ) )
2008-08-15 19:07:45 +04:00
def current_pool ( self ) :
2014-06-03 01:17:47 +04:00
connkey = uiutil . get_list_selection ( self . widget ( " pool-list " ) , 0 )
2013-10-01 02:46:54 +04:00
try :
2014-06-03 01:17:47 +04:00
return connkey and self . conn . get_pool ( connkey )
2013-10-01 02:46:54 +04:00
except KeyError :
2014-01-27 05:21:12 +04:00
return None
2008-08-15 19:07:45 +04:00
def current_vol ( self ) :
pool = self . current_pool ( )
if not pool :
return None
2014-01-27 05:21:12 +04:00
2014-06-03 01:17:47 +04:00
connkey = uiutil . get_list_selection ( self . widget ( " vol-list " ) , 0 )
2014-01-27 05:21:12 +04:00
try :
2014-06-03 01:17:47 +04:00
return connkey and pool . get_volume ( connkey )
2014-01-27 05:21:12 +04:00
except KeyError :
return None
2008-08-15 19:07:45 +04:00
2014-07-23 17:48:17 +04:00
def pool_apply ( self ) :
2008-08-15 19:07:45 +04:00
pool = self . current_pool ( )
if pool is None :
return
2012-01-17 07:04:40 +04:00
logging . debug ( " Applying changes for pool ' %s ' " , pool . get_name ( ) )
2008-08-15 19:07:45 +04:00
try :
2013-09-29 20:28:01 +04:00
if EDIT_POOL_AUTOSTART in self . active_edits :
auto = self . widget ( " pool-autostart " ) . get_active ( )
pool . set_autostart ( auto )
if EDIT_POOL_NAME in self . active_edits :
pool . define_name ( self . widget ( " pool-name-entry " ) . get_text ( ) )
2014-09-21 01:21:16 +04:00
self . idle_add ( self . repopulate_storage_pools )
2008-08-15 19:07:45 +04:00
except Exception , e :
2013-10-01 02:46:54 +04:00
self . err . show_err ( _ ( " Error changing pool settings: %s " ) % str ( e ) )
2008-08-15 19:07:45 +04:00
return
2014-07-23 17:48:17 +04:00
2013-09-29 20:28:01 +04:00
self . disable_pool_apply ( )
def disable_pool_apply ( self ) :
2014-07-23 17:48:17 +04:00
for i in EDIT_POOL_IDS :
if i in self . active_edits :
self . active_edits . remove ( i )
2011-07-14 21:13:13 +04:00
self . widget ( " pool-apply " ) . set_sensitive ( False )
2008-08-15 19:07:45 +04:00
2013-09-29 20:28:01 +04:00
def enable_pool_apply ( self , * arglist ) :
edittype = arglist [ - 1 ]
self . widget ( " pool-apply " ) . set_sensitive ( True )
if edittype not in self . active_edits :
self . active_edits . append ( edittype )
2010-12-09 19:22:35 +03:00
def pool_autostart_changed ( self , src_ignore ) :
2011-07-14 21:13:13 +04:00
auto = self . widget ( " pool-autostart " ) . get_active ( )
self . widget ( " pool-autostart " ) . set_label ( auto and
_ ( " On Boot " ) or
_ ( " Never " ) )
2013-09-29 20:28:01 +04:00
self . enable_pool_apply ( EDIT_POOL_AUTOSTART )
2008-08-15 19:07:45 +04:00
2010-02-26 01:31:27 +03:00
def set_storage_error_page ( self , msg ) :
self . reset_pool_state ( )
2011-07-14 21:13:13 +04:00
self . widget ( " storage-pages " ) . set_current_page ( 1 )
self . widget ( " storage-error-label " ) . set_text ( msg )
2010-02-26 01:31:27 +03:00
2008-08-15 19:07:45 +04:00
def pool_selected ( self , src ) :
2014-01-27 05:21:12 +04:00
model , treeiter = src . get_selected ( )
if treeiter is None :
2010-02-26 01:31:27 +03:00
self . set_storage_error_page ( _ ( " No storage pool selected. " ) )
2008-08-15 19:07:45 +04:00
return
2011-07-14 21:13:13 +04:00
self . widget ( " storage-pages " ) . set_current_page ( 0 )
2014-06-03 01:17:47 +04:00
connkey = model [ treeiter ] [ 0 ]
2010-02-26 01:42:00 +03:00
try :
2014-06-03 01:17:47 +04:00
self . populate_pool_state ( connkey )
2010-02-26 01:42:00 +03:00
except Exception , e :
logging . exception ( e )
self . set_storage_error_page ( _ ( " Error selecting pool: %s " ) % e )
2013-09-29 20:28:01 +04:00
self . disable_pool_apply ( )
2010-02-26 03:42:08 +03:00
2014-06-03 01:17:47 +04:00
def populate_pool_state ( self , connkey ) :
pool = self . conn . get_pool ( connkey )
2013-07-07 19:06:15 +04:00
pool . tick ( )
2008-08-15 19:07:45 +04:00
auto = pool . get_autostart ( )
active = pool . is_active ( )
# Set pool details state
2011-07-14 21:13:13 +04:00
self . widget ( " pool-details " ) . set_sensitive ( True )
self . widget ( " pool-name " ) . set_markup ( " <b> %s :</b> " %
pool . get_name ( ) )
2013-09-29 20:28:01 +04:00
self . widget ( " pool-name-entry " ) . set_text ( pool . get_name ( ) )
self . widget ( " pool-name-entry " ) . set_editable ( not active )
2011-07-14 21:13:13 +04:00
self . widget ( " pool-sizes " ) . set_markup (
2011-07-12 19:50:11 +04:00
""" <span size= " large " > %s Free</span> / <i> %s In Use</i> """ %
( pool . get_pretty_available ( ) , pool . get_pretty_allocation ( ) ) )
2011-07-14 21:13:13 +04:00
self . widget ( " pool-type " ) . set_text (
2013-09-20 04:18:12 +04:00
StoragePool . get_pool_type_desc ( pool . get_type ( ) ) )
2011-07-14 21:13:13 +04:00
self . widget ( " pool-location " ) . set_text (
2011-07-12 19:50:11 +04:00
pool . get_target_path ( ) )
2011-07-14 21:13:13 +04:00
self . widget ( " pool-state-icon " ) . set_from_icon_name (
2011-07-12 19:50:11 +04:00
( ( active and self . ICON_RUNNING ) or self . ICON_SHUTOFF ) ,
2014-01-12 23:36:03 +04:00
Gtk . IconSize . BUTTON )
2011-07-14 21:13:13 +04:00
self . widget ( " pool-state " ) . set_text (
2011-07-12 19:50:11 +04:00
( active and _ ( " Active " ) ) or _ ( " Inactive " ) )
2011-07-14 21:13:13 +04:00
self . widget ( " pool-autostart " ) . set_label (
2011-07-12 19:50:11 +04:00
( auto and _ ( " On Boot " ) ) or _ ( " Never " ) )
2011-07-14 21:13:13 +04:00
self . widget ( " pool-autostart " ) . set_active ( auto )
2008-08-15 19:07:45 +04:00
2011-07-14 21:13:13 +04:00
self . widget ( " vol-list " ) . set_sensitive ( active )
2013-12-05 03:57:43 +04:00
self . repopulate_storage_volumes ( )
2008-08-15 19:07:45 +04:00
2011-07-14 21:13:13 +04:00
self . widget ( " pool-delete " ) . set_sensitive ( not active )
self . widget ( " pool-stop " ) . set_sensitive ( active )
self . widget ( " pool-start " ) . set_sensitive ( not active )
self . widget ( " vol-add " ) . set_sensitive ( active )
2013-09-20 04:18:12 +04:00
self . widget ( " vol-add " ) . set_tooltip_text ( _ ( " Create new volume " ) )
2011-07-14 21:13:13 +04:00
self . widget ( " vol-delete " ) . set_sensitive ( False )
2008-08-15 19:07:45 +04:00
2013-09-20 04:18:12 +04:00
if active and not pool . supports_volume_creation ( ) :
self . widget ( " vol-add " ) . set_sensitive ( False )
self . widget ( " vol-add " ) . set_tooltip_text (
_ ( " Pool does not support volume creation " ) )
2011-07-15 01:07:21 +04:00
2014-06-03 01:17:47 +04:00
def refresh_storage_pool ( self , src , connkey ) :
ignore = src
refresh_pool_in_list ( self . widget ( " pool-list " ) , self . conn , connkey )
2009-03-08 22:34:15 +03:00
curpool = self . current_pool ( )
2014-06-03 01:17:47 +04:00
if curpool . get_connkey ( ) != connkey :
2008-09-06 05:28:26 +04:00
return
2009-03-08 22:34:15 +03:00
# Currently selected pool changed state: force a 'pool_selected' to
# update vol list
2011-07-14 21:13:13 +04:00
self . pool_selected ( self . widget ( " pool-list " ) . get_selection ( ) )
2008-08-15 19:07:45 +04:00
def reset_pool_state ( self ) :
2011-07-14 21:13:13 +04:00
self . widget ( " pool-details " ) . set_sensitive ( False )
self . widget ( " pool-name " ) . set_text ( " " )
2013-09-29 20:28:01 +04:00
self . widget ( " pool-name-entry " ) . set_text ( " " )
2011-07-14 21:13:13 +04:00
self . widget ( " pool-sizes " ) . set_markup ( """ <span size= " large " > </span> """ )
self . widget ( " pool-type " ) . set_text ( " " )
self . widget ( " pool-location " ) . set_text ( " " )
self . widget ( " pool-state-icon " ) . set_from_icon_name ( self . ICON_SHUTOFF ,
2014-01-12 23:36:03 +04:00
Gtk . IconSize . BUTTON )
2011-07-14 21:13:13 +04:00
self . widget ( " pool-state " ) . set_text ( _ ( " Inactive " ) )
self . widget ( " vol-list " ) . get_model ( ) . clear ( )
self . widget ( " pool-autostart " ) . set_label ( _ ( " Never " ) )
self . widget ( " pool-autostart " ) . set_active ( False )
self . widget ( " pool-delete " ) . set_sensitive ( False )
self . widget ( " pool-stop " ) . set_sensitive ( False )
self . widget ( " pool-start " ) . set_sensitive ( False )
self . widget ( " vol-add " ) . set_sensitive ( False )
self . widget ( " vol-delete " ) . set_sensitive ( False )
self . widget ( " vol-list " ) . set_sensitive ( False )
2013-09-29 20:28:01 +04:00
self . disable_pool_apply ( )
2008-08-15 19:07:45 +04:00
def vol_selected ( self , src ) :
2014-01-27 05:21:12 +04:00
model , treeiter = src . get_selected ( )
ignore = model
if treeiter is None :
2011-07-14 21:13:13 +04:00
self . widget ( " vol-delete " ) . set_sensitive ( False )
2008-08-15 19:07:45 +04:00
return
2011-07-14 21:13:13 +04:00
self . widget ( " vol-delete " ) . set_sensitive ( True )
2008-08-15 19:07:45 +04:00
2010-12-09 19:22:35 +03:00
def popup_vol_menu ( self , widget_ignore , event ) :
2008-10-23 00:53:28 +04:00
if event . button != 3 :
return
2013-04-14 21:16:02 +04:00
self . volmenu . popup ( None , None , None , None , 0 , event . time )
2008-09-10 19:08:19 +04:00
def copy_vol_path ( self , ignore = None ) :
vol = self . current_vol ( )
if not vol :
return
2013-08-13 16:26:28 +04:00
clipboard = Gtk . Clipboard . get ( Gdk . SELECTION_CLIPBOARD )
2008-09-10 19:08:19 +04:00
target_path = vol . get_target_path ( )
if target_path :
2013-08-13 16:26:28 +04:00
clipboard . set_text ( target_path , - 1 )
2008-09-10 19:08:19 +04:00
2014-06-03 01:17:47 +04:00
def repopulate_storage_pools ( self , src = None , connkey = None ) :
ignore = src
ignore = connkey
2011-07-14 21:13:13 +04:00
pool_list = self . widget ( " pool-list " )
2013-10-01 02:46:54 +04:00
populate_storage_pools ( pool_list , self . conn , self . current_pool ( ) )
2008-08-15 19:07:45 +04:00
2013-12-05 03:57:43 +04:00
def repopulate_storage_volumes ( self ) :
list_widget = self . widget ( " vol-list " )
2008-08-15 19:07:45 +04:00
pool = self . current_pool ( )
2013-12-05 03:57:43 +04:00
populate_storage_volumes ( list_widget , pool , None )
2008-08-15 19:07:45 +04:00
2009-03-08 22:34:15 +03:00
2010-02-09 01:13:36 +03:00
#############################
# Interface manager methods #
#############################
2010-12-09 19:22:35 +03:00
def stop_interface ( self , src_ignore ) :
2010-02-09 01:13:36 +03:00
interface = self . current_interface ( )
if interface is None :
return
2014-01-27 02:42:24 +04:00
if not self . err . chkbox_helper ( self . config . get_confirm_interface ,
2011-04-15 00:43:17 +04:00
self . config . set_confirm_interface ,
text1 = _ ( " Are you sure you want to stop the interface "
" ' %s ' ? " % interface . get_name ( ) ) ) :
return
2010-02-09 06:34:23 +03:00
2012-01-17 07:04:40 +04:00
logging . debug ( " Stopping interface ' %s ' " , interface . get_name ( ) )
2011-04-15 23:23:13 +04:00
vmmAsyncJob . simple_async_noshow ( interface . stop , [ ] , self ,
_ ( " Error stopping interface ' %s ' " ) % interface . get_name ( ) )
2010-02-09 01:13:36 +03:00
2010-12-09 19:22:35 +03:00
def start_interface ( self , src_ignore ) :
2010-02-09 01:13:36 +03:00
interface = self . current_interface ( )
if interface is None :
return
2014-01-27 02:42:24 +04:00
if not self . err . chkbox_helper ( self . config . get_confirm_interface ,
2011-04-15 00:43:17 +04:00
self . config . set_confirm_interface ,
text1 = _ ( " Are you sure you want to start the interface "
" ' %s ' ? " % interface . get_name ( ) ) ) :
return
2010-02-09 06:34:23 +03:00
2012-01-17 07:04:40 +04:00
logging . debug ( " Starting interface ' %s ' " , interface . get_name ( ) )
2011-04-15 23:23:13 +04:00
vmmAsyncJob . simple_async_noshow ( interface . start , [ ] , self ,
_ ( " Error starting interface ' %s ' " ) % interface . get_name ( ) )
2010-02-09 01:13:36 +03:00
2010-12-09 19:22:35 +03:00
def delete_interface ( self , src_ignore ) :
2010-02-09 01:13:36 +03:00
interface = self . current_interface ( )
if interface is None :
return
result = self . err . yes_no ( _ ( " Are you sure you want to permanently "
" delete the interface %s ? " )
% interface . get_name ( ) )
if not result :
return
2012-01-17 07:04:40 +04:00
logging . debug ( " Deleting interface ' %s ' " , interface . get_name ( ) )
2011-04-15 23:23:13 +04:00
vmmAsyncJob . simple_async_noshow ( interface . delete , [ ] , self ,
_ ( " Error deleting interface ' %s ' " ) % interface . get_name ( ) )
2010-02-09 01:13:36 +03:00
2010-12-09 19:22:35 +03:00
def add_interface ( self , src_ignore ) :
2010-12-10 22:02:11 +03:00
logging . debug ( " Launching ' Add Interface ' wizard " )
2010-02-09 01:13:36 +03:00
try :
if self . addinterface is None :
2010-12-09 01:26:19 +03:00
self . addinterface = vmmCreateInterface ( self . conn )
2011-04-14 16:47:42 +04:00
self . addinterface . show ( self . topwin )
2010-02-09 01:13:36 +03:00
except Exception , e :
self . err . show_err ( _ ( " Error launching interface wizard: %s " ) %
2011-04-06 19:22:03 +04:00
str ( e ) )
2010-02-09 01:13:36 +03:00
def refresh_current_interface ( self , ignore1 = None ) :
cp = self . current_interface ( )
if cp is None :
return
2011-07-22 21:54:40 +04:00
self . refresh_interface ( None , cp . get_name ( ) )
2010-02-09 01:13:36 +03:00
def current_interface ( self ) :
2014-06-03 01:17:47 +04:00
connkey = uiutil . get_list_selection ( self . widget ( " interface-list " ) , 0 )
2013-10-01 02:46:54 +04:00
try :
2014-06-03 01:17:47 +04:00
return connkey and self . conn . get_interface ( connkey )
2013-10-01 02:46:54 +04:00
except KeyError :
2014-01-27 05:21:12 +04:00
return None
2010-02-09 01:13:36 +03:00
2014-07-23 17:48:17 +04:00
def interface_apply ( self ) :
2010-02-09 01:13:36 +03:00
interface = self . current_interface ( )
if interface is None :
return
2014-07-23 17:48:17 +04:00
if EDIT_INTERFACE_STARTMODE not in self . active_edits :
return
2014-01-27 05:21:12 +04:00
newmode = uiutil . get_list_selection (
self . widget ( " interface-startmode " ) , 0 )
2010-02-09 01:13:36 +03:00
2012-01-17 07:04:40 +04:00
logging . debug ( " Applying changes for interface ' %s ' " ,
2010-12-10 22:02:11 +03:00
interface . get_name ( ) )
2010-02-09 01:13:36 +03:00
try :
interface . set_startmode ( newmode )
except Exception , e :
self . err . show_err ( _ ( " Error setting interface startmode: %s " ) %
2011-04-06 19:22:03 +04:00
str ( e ) )
2010-02-09 01:13:36 +03:00
return
2013-05-14 20:15:02 +04:00
# XXX: This will require an interface restart
2014-07-23 17:48:17 +04:00
self . disable_interface_apply ( )
2010-02-09 01:13:36 +03:00
2010-12-09 19:22:35 +03:00
def interface_startmode_changed ( self , src_ignore ) :
2014-07-23 17:48:17 +04:00
self . enable_interface_apply ( EDIT_INTERFACE_STARTMODE )
2010-02-09 01:13:36 +03:00
def set_interface_error_page ( self , msg ) :
self . reset_interface_state ( )
2011-07-14 21:13:13 +04:00
self . widget ( " interface-pages " ) . set_current_page ( INTERFACE_PAGE_ERROR )
self . widget ( " interface-error-label " ) . set_text ( msg )
2010-02-09 01:13:36 +03:00
def interface_selected ( self , src ) :
2014-01-27 05:21:12 +04:00
model , treeiter = src . get_selected ( )
if treeiter is None :
2010-02-09 01:13:36 +03:00
self . set_interface_error_page ( _ ( " No interface selected. " ) )
return
2011-07-14 21:13:13 +04:00
self . widget ( " interface-pages " ) . set_current_page ( INTERFACE_PAGE_INFO )
2014-06-03 01:17:47 +04:00
connkey = model [ treeiter ] [ 0 ]
2010-02-26 01:42:00 +03:00
try :
2014-06-03 01:17:47 +04:00
self . populate_interface_state ( connkey )
2010-02-26 01:42:00 +03:00
except Exception , e :
logging . exception ( e )
self . set_interface_error_page ( _ ( " Error selecting interface: %s " ) %
e )
2014-07-23 17:48:17 +04:00
self . disable_interface_apply ( )
2010-02-26 03:42:08 +03:00
2014-06-03 01:17:47 +04:00
def populate_interface_state ( self , connkey ) :
interface = self . conn . get_interface ( connkey )
name = interface . get_name ( )
2010-02-09 01:13:36 +03:00
children = interface . get_slaves ( )
itype = interface . get_type ( )
mac = interface . get_mac ( )
active = interface . is_active ( )
startmode = interface . get_startmode ( )
2010-02-26 05:13:33 +03:00
ipv4 = interface . get_ipv4 ( )
ipv6 = interface . get_ipv6 ( )
2010-02-09 01:13:36 +03:00
2011-07-14 21:13:13 +04:00
self . widget ( " interface-details " ) . set_sensitive ( True )
self . widget ( " interface-name " ) . set_markup (
2010-02-09 01:13:36 +03:00
" <b> %s %s :</b> " % ( interface . get_pretty_type ( ) ,
interface . get_name ( ) ) )
2011-07-14 21:13:13 +04:00
self . widget ( " interface-mac " ) . set_text ( mac or _ ( " Unknown " ) )
2010-02-09 01:13:36 +03:00
2011-07-14 21:13:13 +04:00
self . widget ( " interface-state-icon " ) . set_from_icon_name (
2011-07-12 19:50:11 +04:00
( ( active and self . ICON_RUNNING ) or self . ICON_SHUTOFF ) ,
2014-01-12 23:36:03 +04:00
Gtk . IconSize . BUTTON )
2011-07-14 21:13:13 +04:00
self . widget ( " interface-state " ) . set_text (
2010-02-09 01:13:36 +03:00
( active and _ ( " Active " ) ) or _ ( " Inactive " ) )
2010-02-26 03:42:08 +03:00
# Set start mode
2011-07-14 21:13:13 +04:00
start_list = self . widget ( " interface-startmode " )
2010-02-26 03:42:08 +03:00
start_model = start_list . get_model ( )
2011-07-14 21:13:13 +04:00
start_label = self . widget ( " interface-startmode-label " )
2010-02-26 03:42:08 +03:00
start_list . hide ( )
start_label . show ( )
start_label . set_text ( startmode )
idx = 0
for row in start_model :
if row [ 0 ] == startmode :
start_list . set_active ( idx )
start_list . show ( )
start_label . hide ( )
break
idx + = 1
2012-02-08 16:24:58 +04:00
# This can fail if other interfaces are busted, so ignore errors
used_by = None
try :
2014-01-27 02:42:24 +04:00
used_by = vmmCreateInterface . iface_in_use_by ( self . conn , name )
2012-02-08 16:24:58 +04:00
except Exception , e :
logging . debug ( " Error looking up iface usage: %s " , e )
2011-07-14 21:13:13 +04:00
self . widget ( " interface-inuseby " ) . set_text ( used_by or " - " )
2010-02-09 01:13:36 +03:00
2010-02-26 05:13:33 +03:00
# IP info
2013-09-02 04:18:14 +04:00
self . widget ( " interface-ipv4-expander " ) . set_visible ( bool ( ipv4 ) )
self . widget ( " interface-ipv6-expander " ) . set_visible ( bool ( ipv6 ) )
2010-02-26 05:13:33 +03:00
if ipv4 :
mode = ipv4 [ 0 ] and " DHCP " or " Static "
addr = ipv4 [ 1 ] or " - "
2011-07-14 21:13:13 +04:00
self . widget ( " interface-ipv4-mode " ) . set_text ( mode )
self . widget ( " interface-ipv4-address " ) . set_text ( addr )
2010-02-26 05:13:33 +03:00
if ipv6 :
mode = " "
if ipv6 [ 1 ] :
mode = " Autoconf "
if ipv6 [ 0 ] :
mode + = " DHCP "
else :
mode = " Static "
addrstr = " - "
if ipv6 [ 2 ] :
2010-11-29 22:06:43 +03:00
addrstr = reduce ( lambda x , y : x + " \n " + y , ipv6 [ 2 ] )
2010-02-26 05:13:33 +03:00
2011-07-14 21:13:13 +04:00
self . widget ( " interface-ipv6-mode " ) . set_text ( mode )
self . widget ( " interface-ipv6-address " ) . set_text ( addrstr )
2010-02-26 05:13:33 +03:00
2011-07-14 21:13:13 +04:00
self . widget ( " interface-delete " ) . set_sensitive ( not active )
self . widget ( " interface-stop " ) . set_sensitive ( active )
self . widget ( " interface-start " ) . set_sensitive ( not active )
2010-02-09 01:13:36 +03:00
show_child = ( children or
2013-09-10 01:14:16 +04:00
itype in [ Interface . INTERFACE_TYPE_BRIDGE ,
Interface . INTERFACE_TYPE_BOND ] )
2013-09-02 04:18:14 +04:00
self . widget ( " interface-child-box " ) . set_visible ( show_child )
2010-02-09 01:13:36 +03:00
self . populate_interface_children ( )
2014-06-03 01:17:47 +04:00
def refresh_interface ( self , src , connkey ) :
ignore = src
2011-07-14 21:13:13 +04:00
iface_list = self . widget ( " interface-list " )
2010-02-09 01:13:36 +03:00
sel = iface_list . get_selection ( )
2014-01-27 05:21:12 +04:00
model , treeiter = sel . get_selected ( )
2014-06-03 01:17:47 +04:00
iface = self . conn . get_interface ( connkey )
name = iface . get_name ( )
2013-07-07 19:06:15 +04:00
iface . tick ( )
2010-02-09 01:13:36 +03:00
for row in iface_list . get_model ( ) :
if row [ 0 ] == name :
2013-07-07 19:06:15 +04:00
row [ 4 ] = iface . is_active ( )
2010-02-09 01:13:36 +03:00
2014-01-27 05:21:12 +04:00
if treeiter is not None :
if model [ treeiter ] [ 0 ] == name :
2010-02-09 01:13:36 +03:00
self . interface_selected ( sel )
def reset_interface_state ( self ) :
2011-07-14 21:13:13 +04:00
self . widget ( " interface-delete " ) . set_sensitive ( False )
self . widget ( " interface-stop " ) . set_sensitive ( False )
self . widget ( " interface-start " ) . set_sensitive ( False )
self . widget ( " interface-apply " ) . set_sensitive ( False )
2010-02-09 01:13:36 +03:00
2014-06-03 01:17:47 +04:00
def repopulate_interfaces ( self , src = None , connkey = None ) :
ignore = src
ignore = connkey
2011-07-14 21:13:13 +04:00
interface_list = self . widget ( " interface-list " )
2010-02-09 01:13:36 +03:00
self . populate_interfaces ( interface_list . get_model ( ) )
def populate_interfaces ( self , model ) :
2013-10-01 02:46:54 +04:00
curiface = self . current_interface ( )
2011-07-14 21:13:13 +04:00
iface_list = self . widget ( " interface-list " )
2014-03-14 05:04:34 +04:00
iface_list . get_selection ( ) . unselect_all ( )
2010-02-09 01:13:36 +03:00
model . clear ( )
2014-06-03 01:17:47 +04:00
for iface in self . conn . list_interfaces ( ) :
model . append ( [ iface . get_connkey ( ) , iface . get_name ( ) ,
" network-idle " , Gtk . IconSize . LARGE_TOOLBAR ,
2010-02-09 01:13:36 +03:00
bool ( iface . is_active ( ) ) ] )
2014-01-27 03:15:50 +04:00
uiutil . set_row_selection ( iface_list ,
2014-06-03 01:17:47 +04:00
curiface and curiface . get_connkey ( ) or None )
2010-02-09 01:13:36 +03:00
def populate_interface_children ( self ) :
interface = self . current_interface ( )
2011-07-14 21:13:13 +04:00
child_list = self . widget ( " interface-child-list " )
2010-02-09 01:13:36 +03:00
model = child_list . get_model ( )
2014-03-14 05:04:34 +04:00
child_list . get_selection ( ) . unselect_all ( )
2010-02-09 01:13:36 +03:00
model . clear ( )
if not interface :
return
for name , itype in interface . get_slaves ( ) :
row = [ name , itype ]
model . append ( row )
2014-07-23 17:48:17 +04:00
def confirm_changes ( self ) :
if not self . active_edits :
return True
if self . err . chkbox_helper (
self . config . get_confirm_unapplied ,
self . config . set_confirm_unapplied ,
text1 = ( _ ( " There are unapplied changes. "
" Would you like to apply them now? " ) ) ,
chktext = _ ( " Don ' t warn me again. " ) ,
default = False ) :
self . pool_apply ( )
self . net_apply ( )
self . interface_apply ( )
self . active_edits = [ ]
return True
def init_pool_list ( self ) :
pool_list = self . widget ( " pool-list " )
init_pool_list ( pool_list , self . pool_selected )
sel = pool_list . get_selection ( )
sel . set_select_function ( ( lambda * x : self . confirm_changes ( ) ) ,
None )
2010-02-09 01:13:36 +03:00
2009-03-08 22:34:15 +03:00
# These functions are broken out, since they are used by storage browser
# dialog.
def init_pool_list ( pool_list , changed_func ) :
2012-05-14 17:24:56 +04:00
poolListModel = Gtk . ListStore ( str , str , bool , str )
2009-03-08 22:34:15 +03:00
pool_list . set_model ( poolListModel )
pool_list . get_selection ( ) . connect ( " changed " , changed_func )
2012-05-14 17:24:56 +04:00
poolCol = Gtk . TreeViewColumn ( " Storage Pools " )
pool_txt = Gtk . CellRendererText ( )
pool_per = Gtk . CellRendererText ( )
2009-03-08 22:34:15 +03:00
poolCol . pack_start ( pool_per , False )
poolCol . pack_start ( pool_txt , True )
poolCol . add_attribute ( pool_txt , ' markup ' , 1 )
poolCol . add_attribute ( pool_txt , ' sensitive ' , 2 )
poolCol . add_attribute ( pool_per , ' markup ' , 3 )
pool_list . append_column ( poolCol )
2012-05-14 17:24:56 +04:00
poolListModel . set_sort_column_id ( 1 , Gtk . SortType . ASCENDING )
2009-03-08 22:34:15 +03:00
2013-04-13 22:34:52 +04:00
2014-06-03 01:17:47 +04:00
def refresh_pool_in_list ( pool_list , conn , connkey ) :
2009-03-08 22:34:15 +03:00
for row in pool_list . get_model ( ) :
2014-06-03 01:17:47 +04:00
if row [ 0 ] != connkey :
continue
# Update active sensitivity and percent available for passed key
row [ 3 ] = get_pool_size_percent ( conn , connkey )
row [ 2 ] = conn . get_pool ( connkey ) . is_active ( )
return
2009-03-08 22:34:15 +03:00
2013-04-13 22:34:52 +04:00
2013-10-01 02:46:54 +04:00
def populate_storage_pools ( pool_list , conn , curpool ) :
2009-03-08 22:34:15 +03:00
model = pool_list . get_model ( )
2013-08-13 16:26:27 +04:00
# Prevent events while the model is modified
pool_list . set_model ( None )
2014-03-14 05:04:34 +04:00
pool_list . get_selection ( ) . unselect_all ( )
2009-03-08 22:34:15 +03:00
model . clear ( )
2014-06-03 01:17:47 +04:00
for pool in conn . list_pools ( ) :
connkey = pool . get_connkey ( )
per = get_pool_size_percent ( conn , connkey )
pool = conn . get_pool ( connkey )
2009-03-08 22:34:15 +03:00
name = pool . get_name ( )
2013-09-20 04:18:12 +04:00
typ = StoragePool . get_pool_type_desc ( pool . get_type ( ) )
2009-03-08 22:34:15 +03:00
label = " %s \n <span size= ' small ' > %s </span> " % ( name , typ )
2014-06-03 01:17:47 +04:00
model . append ( [ connkey , label , pool . is_active ( ) , per ] )
2009-03-08 22:34:15 +03:00
2013-08-13 16:26:27 +04:00
pool_list . set_model ( model )
2014-01-27 03:15:50 +04:00
uiutil . set_row_selection ( pool_list ,
2014-06-03 01:17:47 +04:00
curpool and curpool . get_connkey ( ) or None )
2009-03-08 22:34:15 +03:00
2013-04-13 22:34:52 +04:00
2013-12-05 03:57:43 +04:00
def populate_storage_volumes ( list_widget , pool , sensitive_cb ) :
vols = pool and pool . get_volumes ( ) or { }
model = list_widget . get_model ( )
2014-03-14 05:04:34 +04:00
list_widget . get_selection ( ) . unselect_all ( )
2013-12-05 03:57:43 +04:00
model . clear ( )
for key in vols . keys ( ) :
vol = vols [ key ]
try :
path = vol . get_target_path ( )
2013-12-05 18:17:29 +04:00
name = vol . get_pretty_name ( pool . get_type ( ) )
2013-12-05 03:57:43 +04:00
cap = vol . get_pretty_capacity ( )
fmt = vol . get_format ( ) or " "
except :
logging . debug ( " Error getting volume info for ' %s ' , "
" hiding it " , key , exc_info = True )
continue
namestr = None
try :
if path :
names = VirtualDisk . path_in_use_by ( vol . conn . get_backend ( ) ,
path )
namestr = " , " . join ( names )
if not namestr :
namestr = None
except :
logging . exception ( " Failed to determine if storage volume in "
" use. " )
row = [ key , name , cap , fmt , namestr ]
if sensitive_cb :
row . append ( sensitive_cb ( fmt ) )
model . append ( row )
2014-06-03 01:17:47 +04:00
def get_pool_size_percent ( conn , connkey ) :
pool = conn . get_pool ( connkey )
2009-03-08 22:34:15 +03:00
cap = pool . get_capacity ( )
alloc = pool . get_allocation ( )
if not cap or alloc is None :
per = 0
else :
per = int ( ( ( float ( alloc ) / float ( cap ) ) * 100 ) )
return " <span size= ' small ' color= ' #484848 ' > %s %% </span> " % int ( per )