2007-03-28 03:52:00 +04:00
#
# Copyright (C) 2007 Red Hat, Inc.
# 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
2013-04-12 01:16:33 +04:00
# pylint: disable=E0611
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
2013-04-12 01:16:33 +04:00
# pylint: enable=E0611
2011-04-18 20:39:53 +04:00
2010-12-17 18:32:54 +03:00
from virtinst import VirtualDisk
2008-08-15 19:07:45 +04:00
from virtinst import Storage
2010-02-09 01:13:36 +03:00
from virtinst import Interface
2007-03-28 03:52:00 +04:00
2010-02-09 01:13:36 +03:00
from virtManager import uihelpers
2011-04-15 23:23:13 +04:00
from virtManager . asyncjob import vmmAsyncJob
2008-09-18 18:33:53 +04:00
from virtManager . connection import vmmConnection
2007-03-30 05:23:17 +04:00
from virtManager . createnet import vmmCreateNetwork
2008-08-15 19:07:45 +04:00
from virtManager . createpool import vmmCreatePool
from virtManager . createvol import vmmCreateVolume
2010-02-09 01:18:06 +03:00
from virtManager . createinterface import vmmCreateInterface
2010-12-09 01:26:19 +03:00
from virtManager . baseclass import vmmGObjectUI
2009-07-22 18:21:33 +04:00
from virtManager . 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
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 ) :
2012-02-02 02:26:46 +04:00
vmmGObjectUI . __init__ ( self , " vmm-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
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-17 23:44:27 +03:00
# Set up signals
2011-07-14 21:13:13 +04:00
self . widget ( " net-list " ) . get_selection ( ) . connect ( " changed " ,
self . net_selected )
self . widget ( " vol-list " ) . get_selection ( ) . connect ( " changed " ,
self . vol_selected )
self . widget ( " interface-list " ) . get_selection ( ) . connect ( " changed " ,
self . interface_selected )
2010-02-09 01:13:36 +03:00
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
2007-03-30 05:23:17 +04:00
self . conn . connect ( " net-added " , self . repopulate_networks )
self . conn . connect ( " net-removed " , self . repopulate_networks )
2008-08-15 19:07:45 +04:00
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 )
2007-03-30 05:23:17 +04:00
2010-02-09 01:13:36 +03:00
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 )
2008-09-18 18:33:53 +04:00
self . conn . connect ( " state-changed " , self . conn_state_changed )
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 ,
2008-08-26 19:17:31 +04:00
" on_net_autostart_toggled " : self . net_autostart_changed ,
" on_net_apply_clicked " : self . net_apply ,
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 ,
2008-08-15 19:07:45 +04:00
" on_pool_apply_clicked " : self . pool_apply ,
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 ,
" on_interface_apply_clicked " : self . interface_apply ,
2008-03-24 18:39:19 +03:00
" on_config_autoconnect_toggled " : self . toggle_autoconnect ,
2012-11-08 17:15:02 +04:00
} )
2007-03-28 03:52:00 +04:00
2012-05-14 17:24:56 +04:00
finish_img = Gtk . Image . new_from_stock ( Gtk . STOCK_DELETE ,
Gtk . IconSize . BUTTON )
2011-07-14 21:13:13 +04:00
self . widget ( " vol-delete " ) . set_image ( finish_img )
2012-05-14 17:24:56 +04:00
finish_img = Gtk . Image . new_from_stock ( Gtk . STOCK_NEW ,
Gtk . IconSize . BUTTON )
2011-07-14 21:13:13 +04:00
self . widget ( " vol-add " ) . set_image ( finish_img )
2009-09-29 22:25:37 +04:00
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
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
self . populate_networks ( netListModel )
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 ( )
volCopyPath = Gtk . ImageMenuItem ( _ ( " Copy Volume Path " ) )
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
2011-07-14 21:13:13 +04:00
init_pool_list ( self . widget ( " pool-list " ) ,
2009-11-17 23:44:27 +03:00
self . pool_selected )
2011-07-14 21:13:13 +04:00
populate_storage_pools ( self . widget ( " pool-list " ) ,
2009-11-17 23:44:27 +03:00
self . conn )
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
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
# Starmode combo
2011-07-14 21:13:13 +04:00
uihelpers . build_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
self . populate_interfaces ( interfaceListModel )
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 ( )
2011-07-14 21:13:13 +04:00
self . widget ( " performance-table " ) . attach ( self . cpu_usage_graph , 1 , 2 , 0 , 1 )
2009-11-17 23:44:27 +03:00
self . memory_usage_graph = Sparkline ( )
self . memory_usage_graph . show ( )
2011-07-14 21:13:13 +04:00
self . widget ( " performance-table " ) . attach ( self . memory_usage_graph ,
1 , 2 , 1 , 2 )
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
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
if pagenum == 1 :
self . conn . schedule_priority_tick ( pollnet = True )
elif pagenum == 2 :
self . conn . schedule_priority_tick ( pollpool = True )
elif pagenum == 3 :
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 ) :
2013-06-30 20:42:49 +04:00
conn_active = ( self . conn . get_state ( ) == vmmConnection . STATE_ACTIVE )
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
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
2010-12-09 19:22:35 +03:00
def net_apply ( self , src_ignore ) :
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 :
2011-07-14 21:13:13 +04:00
auto = self . widget ( " net-autostart " ) . get_active ( )
2011-04-15 23:23:13 +04:00
net . set_autostart ( auto )
2008-08-26 19:17:31 +04:00
except Exception , e :
2011-04-06 19:22:03 +04:00
self . err . show_err ( _ ( " Error setting net autostart: %s " ) % str ( e ) )
2008-08-26 19:17:31 +04:00
return
2011-07-14 21:13:13 +04:00
self . widget ( " net-apply " ) . set_sensitive ( False )
2008-08-26 19:17:31 +04:00
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 " ) )
self . widget ( " net-apply " ) . set_sensitive ( True )
2008-08-26 19:17:31 +04:00
2007-04-03 22:01:45 +04:00
def current_network ( self ) :
2011-07-14 21:13:13 +04:00
sel = self . widget ( " net-list " ) . get_selection ( )
2007-04-03 22:01:45 +04:00
active = sel . get_selected ( )
2012-11-08 17:15:02 +04:00
if active [ 1 ] is not None :
2007-04-03 22:01:45 +04:00
curruuid = active [ 0 ] . get_value ( active [ 1 ] , 0 )
return self . conn . get_net ( curruuid )
return None
2011-07-22 21:54:40 +04:00
def refresh_network ( self , src_ignore , uuid ) :
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 ( )
2007-04-03 22:01:45 +04:00
active = sel . get_selected ( )
2013-07-07 19:06:15 +04:00
net = self . conn . get_net ( uuid )
net . tick ( )
2010-12-10 22:02:11 +03:00
for row in uilist . get_model ( ) :
if row [ 0 ] == uuid :
2013-07-07 19:06:15 +04:00
row [ 4 ] = net . is_active ( )
2010-12-10 22:02:11 +03:00
2012-11-08 17:15:02 +04:00
if active [ 1 ] is not None :
2010-12-10 22:02:11 +03:00
currname = active [ 0 ] . get_value ( active [ 1 ] , 0 )
if currname == uuid :
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 ) :
2008-08-26 18:55:03 +04:00
selected = src . get_selected ( )
2012-11-08 17:15:02 +04:00
if selected [ 1 ] is None or \
selected [ 0 ] . get_value ( selected [ 1 ] , 0 ) 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 )
2013-03-29 22:38:28 +04:00
try :
net = self . conn . get_net ( selected [ 0 ] . get_value ( selected [ 1 ] , 0 ) )
except KeyError :
self . widget ( " net-apply " ) . set_sensitive ( False )
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 )
2011-07-14 21:13:13 +04:00
self . widget ( " net-apply " ) . set_sensitive ( False )
2010-02-26 03:42:08 +03:00
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 )
self . widget ( " net-name " ) . set_text ( net . get_name ( ) )
2013-03-29 22:38:28 +04:00
dns_name = net . get_name_domain ( )
if dns_name :
self . widget ( " net-name-domain " ) . set_text ( dns_name )
else :
self . widget ( " net-name-domain " ) . set_text ( " " )
2008-08-26 18:55:03 +04:00
2009-11-16 15:14:49 +03:00
dev = active and net . get_bridge_device ( ) or " "
state = active and _ ( " Active " ) or _ ( " Inactive " )
2011-07-12 19:50:11 +04:00
icon = ( active and self . ICON_RUNNING or
self . ICON_SHUTOFF )
2009-11-16 15:14:49 +03:00
2011-07-14 21:13:13 +04:00
self . widget ( " net-device " ) . set_text ( dev )
self . widget ( " net-device " ) . set_sensitive ( active )
self . widget ( " net-state " ) . set_text ( state )
self . widget ( " net-state-icon " ) . set_from_icon_name ( icon ,
2012-05-14 17:24:56 +04:00
Gtk . IconSize . MENU )
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-03-29 22:38:28 +04:00
######### IPv4 #########
result = net . get_ipv4_network ( )
network = result [ 0 ]
dhcp = result [ 1 ]
route = result [ 2 ]
if network :
self . widget ( " net-frame-ip4 " ) . show ( )
else :
self . widget ( " net-frame-ip4 " ) . hide ( )
2011-07-14 21:13:13 +04:00
self . widget ( " net-ip4-network " ) . set_text ( str ( network ) )
2008-08-26 18:55:03 +04:00
2009-11-16 15:14:49 +03:00
start = dhcp and str ( dhcp [ 0 ] ) or _ ( " Disabled " )
end = dhcp and str ( dhcp [ 1 ] ) or _ ( " Disabled " )
2011-07-14 21:13:13 +04:00
self . widget ( " net-ip4-dhcp-start " ) . set_text ( start )
self . widget ( " net-ip4-dhcp-end " ) . set_text ( end )
2013-03-29 22:38:28 +04:00
if route and route [ 0 ] and route [ 1 ] :
2013-05-14 20:15:02 +04:00
routeVia = str ( route [ 0 ] ) + " , gateway= " + str ( route [ 1 ] )
2013-03-29 22:38:28 +04:00
self . widget ( " net-ip4-route-label " ) . show ( )
else :
routeVia = _ ( " " )
self . widget ( " net-ip4-route-label " ) . hide ( )
self . widget ( " net-ip4-route-via " ) . set_text ( routeVia )
2009-11-16 15:14:49 +03:00
forward , ignore = net . get_ipv4_forward ( )
2012-05-14 17:24:56 +04:00
iconsize = Gtk . IconSize . MENU
icon = forward and Gtk . STOCK_CONNECT or Gtk . STOCK_DISCONNECT
2011-07-14 21:13:13 +04:00
self . widget ( " net-ip4-forwarding-icon " ) . set_from_stock ( icon , iconsize )
2009-11-16 15:14:49 +03:00
forward_str = net . pretty_forward_mode ( )
2011-07-14 21:13:13 +04:00
self . widget ( " net-ip4-forwarding " ) . set_text ( forward_str )
2008-08-26 18:55:03 +04:00
2013-03-29 22:38:28 +04:00
######### IPv6 #########
result = net . get_ipv6_network ( )
network = result [ 0 ]
dhcp = result [ 1 ]
route = result [ 2 ]
if network :
self . widget ( " net-frame-ip6 " ) . show ( )
iconsize = Gtk . IconSize . MENU
icon = Gtk . STOCK_CONNECT
self . widget ( " net-ip6-forwarding-icon " ) . set_from_stock ( icon , iconsize )
self . widget ( " net-ip6-forwarding " ) . set_text ( _ ( " Routed network " ) )
else :
self . widget ( " net-frame-ip6 " ) . hide ( )
iconsize = Gtk . IconSize . MENU
icon = Gtk . STOCK_DISCONNECT
self . widget ( " net-ip6-forwarding-icon " ) . set_from_stock ( icon , iconsize )
2013-05-14 20:15:02 +04:00
ipv6 = net . get_ipv6_routing ( )
2013-03-29 22:38:28 +04:00
if ipv6 :
self . widget ( " net-ip6-forwarding " ) . set_text (
_ ( " Isolated network, internal and host routing only " ) )
elif ipv6 == ' yes ' :
self . widget ( " net-ip6-forwarding " ) . set_text (
_ ( " Isolated network, internal routing only " ) )
else :
self . widget ( " net-ip6-forwarding " ) . set_text (
_ ( " Isolated network, routing disabled " ) )
self . widget ( " net-ip6-network " ) . set_text ( str ( network ) )
start = dhcp and str ( dhcp [ 0 ] ) or _ ( " Disabled " )
end = dhcp and str ( dhcp [ 1 ] ) or _ ( " Disabled " )
self . widget ( " net-ip6-dhcp-start " ) . set_text ( start )
self . widget ( " net-ip6-dhcp-end " ) . set_text ( end )
if route and route [ 0 ] and route [ 1 ] :
2013-05-14 20:15:02 +04:00
routeVia = str ( route [ 0 ] ) + " , gateway= " + str ( route [ 1 ] )
2013-03-29 22:38:28 +04:00
self . widget ( " net-ip6-route-label " ) . show ( )
else :
routeVia = " "
self . widget ( " net-ip6-route-label " ) . hide ( )
self . widget ( " net-ip6-route-via " ) . set_text ( routeVia )
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-device " ) . set_sensitive ( False )
self . widget ( " net-state " ) . set_text ( _ ( " Inactive " ) )
self . widget ( " net-state-icon " ) . set_from_icon_name ( self . ICON_SHUTOFF ,
2012-05-14 17:24:56 +04:00
Gtk . IconSize . MENU )
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 )
self . widget ( " net-ip4-network " ) . set_text ( " " )
self . widget ( " net-ip4-dhcp-start " ) . set_text ( " " )
self . widget ( " net-ip4-dhcp-end " ) . set_text ( " " )
2013-03-29 22:38:28 +04:00
self . widget ( " net-ip4-route-label " ) . hide ( )
self . widget ( " net-ip4-route-via " ) . set_text ( " " )
2011-07-14 21:13:13 +04:00
self . widget ( " net-ip4-forwarding-icon " ) . set_from_stock (
2012-05-14 17:24:56 +04:00
Gtk . STOCK_DISCONNECT , Gtk . IconSize . MENU )
2011-07-14 21:13:13 +04:00
self . widget ( " net-ip4-forwarding " ) . set_text (
2013-03-29 22:38:28 +04:00
_ ( " Isolated network " ) )
self . widget ( " net-ip6-network " ) . set_text ( " " )
self . widget ( " net-ip6-dhcp-start " ) . set_text ( " " )
self . widget ( " net-ip6-dhcp-end " ) . set_text ( " " )
self . widget ( " net-ip6-route-label " ) . hide ( )
self . widget ( " net-ip6-route-via " ) . set_text ( " " )
self . widget ( " net-ip6-forwarding " ) . set_text (
_ ( " Isolated network " ) )
2011-07-14 21:13:13 +04:00
self . widget ( " net-apply " ) . set_sensitive ( False )
2007-03-28 03:52:00 +04:00
2013-06-30 20:42:49 +04:00
def repopulate_networks ( self , src_ignore = None , uuid_ignore = None ) :
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 ) :
2011-07-14 21:13:13 +04:00
net_list = self . widget ( " net-list " )
2007-03-28 03:52:00 +04:00
model . clear ( )
for uuid in self . conn . list_net_uuids ( ) :
net = self . conn . get_net ( uuid )
2009-07-20 23:09:32 +04:00
model . append ( [ uuid , 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
2009-03-08 22:34:15 +03:00
_iter = model . get_iter_first ( )
if _iter :
net_list . get_selection ( ) . select_iter ( _iter )
net_list . get_selection ( ) . emit ( " changed " )
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
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 ( )
self . populate_storage_volumes ( )
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 ( )
2011-07-22 21:54:40 +04:00
self . refresh_storage_pool ( None , cp . get_uuid ( ) )
2008-08-15 19:07:45 +04:00
def current_pool ( self ) :
2011-07-14 21:13:13 +04:00
sel = self . widget ( " pool-list " ) . get_selection ( )
2008-08-15 19:07:45 +04:00
active = sel . get_selected ( )
2012-11-08 17:15:02 +04:00
if active [ 1 ] is not None :
2008-08-15 19:07:45 +04:00
curruuid = active [ 0 ] . get_value ( active [ 1 ] , 0 )
return self . conn . get_pool ( curruuid )
return None
def current_vol ( self ) :
pool = self . current_pool ( )
if not pool :
return None
2011-07-14 21:13:13 +04:00
sel = self . widget ( " vol-list " ) . get_selection ( )
2008-08-15 19:07:45 +04:00
active = sel . get_selected ( )
2012-11-08 17:15:02 +04:00
if active [ 1 ] is not None :
2008-08-15 19:07:45 +04:00
curruuid = active [ 0 ] . get_value ( active [ 1 ] , 0 )
return pool . get_volume ( curruuid )
return None
2010-12-09 19:22:35 +03:00
def pool_apply ( self , src_ignore ) :
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 :
2011-07-14 21:13:13 +04:00
do_auto = self . widget ( " pool-autostart " ) . get_active ( )
2010-12-09 19:22:35 +03:00
pool . set_autostart ( do_auto )
2008-08-15 19:07:45 +04:00
except Exception , e :
2011-04-06 19:22:03 +04:00
self . err . show_err ( _ ( " Error setting pool autostart: %s " ) % str ( e ) )
2008-08-15 19:07:45 +04:00
return
2011-07-14 21:13:13 +04:00
self . widget ( " pool-apply " ) . set_sensitive ( False )
2008-08-15 19:07:45 +04:00
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 " ) )
self . widget ( " pool-apply " ) . set_sensitive ( True )
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 ) :
selected = src . get_selected ( )
if selected [ 1 ] is None or \
selected [ 0 ] . get_value ( selected [ 1 ] , 0 ) 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 )
2008-08-15 19:07:45 +04:00
uuid = selected [ 0 ] . get_value ( selected [ 1 ] , 0 )
2010-02-26 01:42:00 +03:00
try :
self . populate_pool_state ( uuid )
except Exception , e :
logging . exception ( e )
self . set_storage_error_page ( _ ( " Error selecting pool: %s " ) % e )
2011-07-14 21:13:13 +04:00
self . widget ( " pool-apply " ) . set_sensitive ( False )
2010-02-26 03:42:08 +03:00
2010-02-26 01:42:00 +03:00
def populate_pool_state ( self , uuid ) :
2008-08-15 19:07:45 +04:00
pool = self . conn . get_pool ( uuid )
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 ( ) )
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 (
2011-07-12 19:50:11 +04:00
Storage . 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 ) ,
2012-05-14 17:24:56 +04:00
Gtk . IconSize . MENU )
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 )
2008-08-15 19:07:45 +04:00
self . populate_storage_volumes ( )
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 )
self . widget ( " vol-delete " ) . set_sensitive ( False )
2008-08-15 19:07:45 +04:00
2011-07-15 01:07:21 +04:00
if active :
try :
Storage . StoragePool . get_volume_for_pool ( pool . get_type ( ) )
except Exception , e :
self . widget ( " vol-add " ) . set_sensitive ( False )
2012-05-14 17:24:56 +04:00
self . widget ( " vol-add " ) . set_tooltip_text ( str ( e ) )
2011-07-15 01:07:21 +04:00
2011-07-22 21:54:40 +04:00
def refresh_storage_pool ( self , src_ignore , uuid ) :
2011-07-14 21:13:13 +04:00
refresh_pool_in_list ( self . widget ( " pool-list " ) , self . conn , uuid )
2009-03-08 22:34:15 +03:00
curpool = self . current_pool ( )
2013-07-07 16:42:57 +04:00
if curpool . get_uuid ( ) != uuid :
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 ( " " )
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 ,
2012-05-14 17:24:56 +04:00
Gtk . IconSize . MENU )
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 ( " pool-apply " ) . set_sensitive ( False )
self . widget ( " vol-add " ) . set_sensitive ( False )
self . widget ( " vol-delete " ) . set_sensitive ( False )
self . widget ( " vol-list " ) . set_sensitive ( False )
2008-08-15 19:07:45 +04:00
def vol_selected ( self , src ) :
selected = src . get_selected ( )
if selected [ 1 ] is None or \
selected [ 0 ] . get_value ( selected [ 1 ] , 0 ) 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
2013-06-30 20:42:49 +04:00
def repopulate_storage_pools ( self , src_ignore = None , uuid_ignore = None ) :
2011-07-14 21:13:13 +04:00
pool_list = self . widget ( " pool-list " )
2009-03-08 22:34:15 +03:00
populate_storage_pools ( pool_list , self . conn )
2008-08-15 19:07:45 +04:00
def populate_storage_volumes ( self ) :
pool = self . current_pool ( )
2011-07-14 21:13:13 +04:00
model = self . widget ( " vol-list " ) . get_model ( )
2008-08-15 19:07:45 +04:00
model . clear ( )
vols = pool . get_volumes ( )
for key in vols . keys ( ) :
vol = vols [ key ]
2010-12-17 18:32:54 +03:00
2012-01-30 07:23:45 +04:00
try :
path = vol . get_target_path ( )
name = vol . get_name ( )
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
2010-12-17 18:32:54 +03:00
namestr = None
try :
if path :
2013-07-05 16:59:58 +04:00
names = VirtualDisk . path_in_use_by ( self . conn . get_backend ( ) ,
path )
2010-12-17 18:32:54 +03:00
namestr = " , " . join ( names )
if not namestr :
namestr = None
except :
logging . exception ( " Failed to determine if storage volume in "
" use. " )
2012-01-30 07:23:45 +04:00
model . append ( [ key , name , cap , fmt , namestr ] )
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
2013-08-09 17:23:01 +04:00
if not uihelpers . chkbox_helper ( self , 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
2013-08-09 17:23:01 +04:00
if not uihelpers . chkbox_helper ( self , 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 ) :
2011-07-14 21:13:13 +04:00
sel = self . widget ( " interface-list " ) . get_selection ( )
2010-02-09 01:13:36 +03:00
active = sel . get_selected ( )
2012-11-08 17:15:02 +04:00
if active [ 1 ] is not None :
2010-02-09 01:13:36 +03:00
currname = active [ 0 ] . get_value ( active [ 1 ] , 0 )
return self . conn . get_interface ( currname )
return None
2010-12-09 19:22:35 +03:00
def interface_apply ( self , src_ignore ) :
2010-02-09 01:13:36 +03:00
interface = self . current_interface ( )
if interface is None :
return
2011-07-14 21:13:13 +04:00
start_list = self . widget ( " interface-startmode " )
2010-02-09 01:13:36 +03:00
model = start_list . get_model ( )
newmode = model [ start_list . get_active ( ) ] [ 0 ]
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
2011-07-14 21:13:13 +04:00
self . widget ( " interface-apply " ) . set_sensitive ( False )
2010-02-09 01:13:36 +03:00
2010-12-09 19:22:35 +03:00
def interface_startmode_changed ( self , src_ignore ) :
2011-07-14 21:13:13 +04:00
self . widget ( " interface-apply " ) . set_sensitive ( True )
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 ) :
selected = src . get_selected ( )
if selected [ 1 ] is None or \
selected [ 0 ] . get_value ( selected [ 1 ] , 0 ) is None :
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 )
2010-02-09 01:13:36 +03:00
name = selected [ 0 ] . get_value ( selected [ 1 ] , 0 )
2010-02-26 01:42:00 +03:00
try :
self . populate_interface_state ( name )
except Exception , e :
logging . exception ( e )
self . set_interface_error_page ( _ ( " Error selecting interface: %s " ) %
e )
2011-07-14 21:13:13 +04:00
self . widget ( " interface-apply " ) . set_sensitive ( False )
2010-02-26 03:42:08 +03:00
2010-02-26 01:42:00 +03:00
def populate_interface_state ( self , name ) :
2010-02-09 01:13:36 +03:00
interface = self . conn . get_interface ( name )
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 ) ,
2012-05-14 17:24:56 +04:00
Gtk . IconSize . MENU )
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 :
2013-08-09 17:23:01 +04:00
used_by = uihelpers . 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 ( )
2011-07-22 21:54:40 +04:00
def refresh_interface ( self , src_ignore , name ) :
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 ( )
active = sel . get_selected ( )
2013-07-07 19:06:15 +04:00
iface = self . conn . get_interface ( name )
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
2012-11-08 17:15:02 +04:00
if active [ 1 ] is not None :
2010-02-09 01:13:36 +03:00
currname = active [ 0 ] . get_value ( active [ 1 ] , 0 )
if currname == name :
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
2013-06-30 20:42:49 +04:00
def repopulate_interfaces ( self , src_ignore = None , name_ignore = None ) :
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 ) :
2011-07-14 21:13:13 +04:00
iface_list = self . widget ( " interface-list " )
2010-02-09 01:13:36 +03:00
model . clear ( )
for name in self . conn . list_interface_names ( ) :
iface = self . conn . get_interface ( name )
model . append ( [ name , iface . get_name ( ) , " network-idle " ,
2012-05-14 17:24:56 +04:00
Gtk . IconSize . LARGE_TOOLBAR ,
2010-02-09 01:13:36 +03:00
bool ( iface . is_active ( ) ) ] )
_iter = model . get_iter_first ( )
if _iter :
iface_list . get_selection ( ) . select_iter ( _iter )
iface_list . get_selection ( ) . emit ( " changed " )
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 ( )
model . clear ( )
if not interface :
return
for name , itype in interface . get_slaves ( ) :
row = [ name , itype ]
model . append ( row )
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
2009-03-08 22:34:15 +03:00
def refresh_pool_in_list ( pool_list , conn , uuid ) :
for row in pool_list . get_model ( ) :
if row [ 0 ] == uuid :
# Update active sensitivity and percent available for passed uuid
row [ 3 ] = get_pool_size_percent ( conn , uuid )
row [ 2 ] = conn . get_pool ( uuid ) . is_active ( )
return
2013-04-13 22:34:52 +04:00
2009-03-08 22:34:15 +03:00
def populate_storage_pools ( pool_list , conn ) :
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 )
2009-03-08 22:34:15 +03:00
model . clear ( )
for uuid in conn . list_pool_uuids ( ) :
per = get_pool_size_percent ( conn , uuid )
pool = conn . get_pool ( uuid )
name = pool . get_name ( )
typ = Storage . StoragePool . get_pool_type_desc ( pool . get_type ( ) )
label = " %s \n <span size= ' small ' > %s </span> " % ( name , typ )
model . append ( [ uuid , label , pool . is_active ( ) , per ] )
_iter = model . get_iter_first ( )
2013-08-13 16:26:27 +04:00
pool_list . set_model ( model )
2009-03-08 22:34:15 +03:00
if _iter :
pool_list . get_selection ( ) . select_iter ( _iter )
pool_list . get_selection ( ) . emit ( " changed " )
2013-04-13 22:34:52 +04:00
2009-03-08 22:34:15 +03:00
def get_pool_size_percent ( conn , uuid ) :
pool = conn . get_pool ( uuid )
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 )