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
#
2017-10-11 14:35:59 +03:00
import functools
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
2011-04-18 20:39:53 +04:00
2010-02-09 01:13:36 +03:00
from virtinst import Interface
2017-09-22 14:39:10 +03:00
from virtinst import NodeDevice
2015-05-04 23:33:56 +03:00
from virtinst import util
2007-03-28 03:52:00 +04:00
2014-09-13 00:10:45 +04:00
from . import uiutil
from . asyncjob import vmmAsyncJob
2015-04-09 01:29:48 +03:00
from . baseclass import vmmGObjectUI
2014-09-13 00:10:45 +04:00
from . createnet import vmmCreateNetwork
from . createinterface import vmmCreateInterface
from . graphwidgets import Sparkline
2015-04-09 01:29:48 +03:00
from . storagelist import vmmStorageList
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 ,
2017-10-11 14:35:57 +03:00
) = list ( range ( 3 ) )
2013-09-29 20:28:01 +04:00
2014-07-23 17:48:17 +04:00
EDIT_INTERFACE_IDS = (
EDIT_INTERFACE_STARTMODE ,
2017-10-11 14:35:57 +03:00
) = list ( 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 , [ ] ) ,
" 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
2015-04-11 20:39:25 +03:00
self . _orig_title = self . topwin . get_title ( )
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
2010-02-09 01:13:36 +03:00
self . addinterface = None
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
2015-04-09 01:29:48 +03:00
self . storagelist = None
2009-11-20 01:29:20 +03:00
self . init_storage_state ( )
2015-04-09 01:29:48 +03:00
self . init_net_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 ( {
2017-08-05 09:39:32 +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
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
2017-08-05 09:39:32 +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 ,
2010-02-09 01:13:36 +03:00
" on_interface_startmode_changed " : self . interface_startmode_changed ,
2017-08-05 09:39:32 +03: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
2015-04-11 20:39:25 +03:00
" on_overview_name_changed " : self . _overview_name_changed ,
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
2015-04-11 18:40:47 +03:00
self . populate_networks ( )
self . populate_interfaces ( )
2013-09-23 20:37:03 +04:00
2015-04-11 18:40:47 +03:00
self . conn . connect ( " net-added " , self . populate_networks )
self . conn . connect ( " net-removed " , self . populate_networks )
2013-09-23 20:37:03 +04:00
2015-04-11 18:40:47 +03:00
self . conn . connect ( " interface-added " , self . populate_interfaces )
self . conn . connect ( " interface-removed " , self . populate_interfaces )
2013-09-23 20:37:03 +04:00
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 )
2015-04-09 01:29:48 +03:00
self . refresh_resources ( )
self . conn_state_changed ( )
self . widget ( " config-autoconnect " ) . set_active (
self . conn . get_autoconnect ( ) )
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 )
2016-02-05 18:18:16 +03: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
2017-09-22 14:39:10 +03:00
# Virtual Function list
# [vf-name]
vf_list = self . widget ( " vf-list " )
vf_list_model = Gtk . ListStore ( str )
vf_list . set_model ( vf_list_model )
vf_list . set_headers_visible ( False )
vfTextCol = Gtk . TreeViewColumn ( )
vf_txt = Gtk . CellRendererText ( )
vfTextCol . pack_start ( vf_txt , True )
vfTextCol . add_attribute ( vf_txt , ' text ' , 0 )
vf_list . append_column ( vfTextCol )
2009-11-17 23:44:27 +03:00
def init_storage_state ( self ) :
2015-04-09 01:29:48 +03:00
self . storagelist = vmmStorageList ( self . conn , self . builder , self . topwin )
self . widget ( " storage-align " ) . add ( self . storagelist . top_box )
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 )
2016-02-05 18:18:16 +03: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 )
2016-02-05 18:18:16 +03:00
childNameCol = Gtk . TreeViewColumn ( _ ( " Name " ) )
2012-05-14 17:24:56 +04:00
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 )
2016-02-05 18:18:16 +03:00
childTypeCol = Gtk . TreeViewColumn ( _ ( " Interface Type " ) )
2012-05-14 17:24:56 +04:00
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 ( )
auto = self . conn . get_autoconnect ( )
2011-07-14 21:13:13 +04:00
self . widget ( " overview-uri " ) . set_text ( uri )
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
2015-04-09 01:29:48 +03:00
self . storagelist . cleanup ( )
self . storagelist = None
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 . addinterface :
self . addinterface . cleanup ( )
self . addinterface = 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 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
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 :
2015-04-11 18:40:47 +03:00
self . populate_networks ( )
2013-07-07 19:06:15 +04:00
self . conn . schedule_priority_tick ( pollnet = True )
elif pagenum == 2 :
2015-04-09 01:29:48 +03:00
self . storagelist . refresh_page ( )
2013-07-07 19:06:15 +04:00
elif pagenum == 3 :
2015-04-11 18:40:47 +03:00
self . populate_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 ) :
2015-05-04 23:33:56 +03:00
vm_memory = util . pretty_mem ( self . conn . stats_memory ( ) )
host_memory = util . pretty_mem ( self . conn . 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 ( )
2015-04-11 20:39:25 +03:00
self . topwin . set_title (
self . conn . get_pretty_desc ( ) + " " + self . _orig_title )
if not self . widget ( " overview-name " ) . has_focus ( ) :
self . widget ( " overview-name " ) . set_text ( self . conn . get_pretty_desc ( ) )
2013-06-30 20:42:49 +04:00
self . widget ( " net-add " ) . set_sensitive ( conn_active and
self . conn . is_network_capable ( ) )
self . widget ( " interface-add " ) . set_sensitive ( conn_active and
self . conn . is_interface_capable ( ) )
2015-04-10 16:31:13 +03:00
if conn_active and 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. " ) )
2015-04-10 16:31:13 +03:00
if conn_active and 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. " ) )
2015-04-09 22:07:16 +03:00
if conn_active :
2015-05-20 01:13:33 +03:00
uiutil . set_list_selection_by_number ( self . widget ( " net-list " ) , 0 )
uiutil . set_list_selection_by_number ( self . widget ( " interface-list " ) , 0 )
2015-04-09 22:07:16 +03:00
return
self . set_net_error_page ( _ ( " Connection not active. " ) )
self . set_interface_error_page ( _ ( " Connection not active. " ) )
2015-04-11 18:40:47 +03:00
self . populate_networks ( )
self . populate_interfaces ( )
2015-04-09 22:07:16 +03:00
self . storagelist . close ( )
if self . addinterface :
self . addinterface . close ( )
if self . addnet :
self . addnet . close ( )
2010-03-21 01:42:32 +03:00
2015-04-11 20:39:25 +03:00
def _overview_name_changed ( self , src ) :
src = self . widget ( " overview-name " )
self . conn . set_config_pretty_name ( src . get_text ( ) )
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
2015-04-11 20:39:25 +03:00
#############################
# Virtual Network functions #
#############################
2008-08-15 19:07:45 +04:00
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 ( ) )
2017-09-22 14:39:10 +03:00
self . widget ( " vf-list " ) . get_model ( ) . clear ( )
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 )
2017-05-05 19:47:21 +03:00
except Exception as 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 ( ) )
2015-04-11 18:40:47 +03:00
self . idle_add ( self . populate_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 )
2017-05-05 19:47:21 +03:00
except Exception as 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 ) :
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 ) :
2015-05-20 00:17:53 +03:00
connkey = uiutil . get_list_selection ( self . widget ( " net-list " ) )
2015-05-07 18:23:00 +03:00
return connkey and self . conn . get_net ( connkey )
2007-04-03 22:01:45 +04:00
2015-04-09 23:07:09 +03:00
def refresh_network ( self , net ) :
connkey = net . get_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 ( )
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 )
2010-02-26 01:42:00 +03:00
self . populate_net_state ( net )
2017-05-05 19:47:21 +03:00
except Exception as e :
2010-02-26 01:42:00 +03:00
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 " " )
2017-09-22 14:39:10 +03:00
def _populate_sriov_state ( self , net ) :
( is_vf_pool , pf_name , vfs ) = net . get_sriov_vf_networks ( )
self . widget ( " net-sriov-expander " ) . set_visible ( is_vf_pool )
if not pf_name :
self . widget ( " pf-name " ) . set_text ( " N/A " )
return
self . widget ( " pf-name " ) . set_text ( pf_name )
vf_list_model = self . widget ( " vf-list " ) . get_model ( )
vf_list_model . clear ( )
for vf in vfs :
addrStr = " %x : %x : %x . %x " % ( vf . domain , vf . bus , vf . slot , vf . function )
pcidev = NodeDevice . lookupNodedevFromString ( self . conn . get_backend ( ) ,
addrStr )
vf_name = None
netdevs = self . conn . filter_nodedevs ( " net " )
for netdev in netdevs :
logging . debug ( netdev . xmlobj . parent )
if pcidev . name == netdev . xmlobj . parent :
vf_name = netdev . xmlobj . interface
break
vf_list_model . append ( [ vf_name or addrStr ] )
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 ( )
2011-07-14 21:13:13 +04:00
self . widget ( " net-autostart " ) . set_active ( autostart )
2017-03-21 18:19:05 +03:00
self . widget ( " net-autostart " ) . set_label ( _ ( " On Boot " ) )
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 )
2017-09-22 14:39:10 +03:00
self . _populate_sriov_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 )
2017-03-21 18:19:05 +03:00
self . widget ( " net-autostart " ) . set_label ( _ ( " On Boot " ) )
2011-07-14 21:13:13 +04:00
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
2015-04-11 18:40:47 +03:00
def populate_networks ( self , src = None , connkey = None ) :
2014-06-03 01:17:47 +04:00
ignore = src
ignore = connkey
2007-03-30 05:23:17 +04:00
2015-04-11 18:40:47 +03:00
net_list = self . widget ( " net-list " )
2013-10-01 02:46:54 +04:00
curnet = self . current_network ( )
2015-04-11 18:40:47 +03:00
model = net_list . get_model ( )
# Prevent events while the model is modified
net_list . set_model ( None )
try :
net_list . get_selection ( ) . unselect_all ( )
model . clear ( )
for net in self . conn . list_nets ( ) :
try :
net . disconnect_by_func ( self . refresh_network )
2017-07-24 11:26:48 +03:00
except Exception :
2015-04-11 18:40:47 +03:00
pass
net . connect ( " state-changed " , self . refresh_network )
model . append ( [ net . get_connkey ( ) , net . get_name ( ) , " network-idle " ,
Gtk . IconSize . LARGE_TOOLBAR ,
bool ( net . is_active ( ) ) ] )
finally :
net_list . set_model ( model )
2007-03-28 03:52:00 +04:00
2015-05-20 01:13:33 +03:00
uiutil . set_list_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
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 )
2017-05-05 19:47:21 +03:00
except Exception as e :
2010-02-09 01:13:36 +03:00
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
2015-04-09 23:07:09 +03:00
self . refresh_interface ( cp )
2010-02-09 01:13:36 +03:00
def current_interface ( self ) :
2015-05-20 00:17:53 +03:00
connkey = uiutil . get_list_selection ( self . widget ( " interface-list " ) )
2015-05-07 18:23:00 +03:00
return connkey and self . conn . get_interface ( connkey )
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-01-27 05:21:12 +04:00
newmode = uiutil . get_list_selection (
2015-05-20 00:17:53 +03:00
self . widget ( " interface-startmode " ) )
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 )
2017-05-05 19:47:21 +03:00
except Exception as e :
2010-02-09 01:13:36 +03:00
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
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 )
2017-05-05 19:47:21 +03:00
except Exception as e :
2010-02-26 01:42:00 +03:00
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 )
2017-05-05 19:47:21 +03:00
except Exception as e :
2012-02-08 16:24:58 +04:00
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 :
2016-02-05 18:18:16 +03:00
mode = ipv4 [ 0 ] and " DHCP " or _ ( " Static " )
2010-02-26 05:13:33 +03:00
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 ] :
2016-02-05 18:18:16 +03:00
mode = _ ( " Autoconf " ) + " "
2010-02-26 05:13:33 +03:00
if ipv6 [ 0 ] :
mode + = " DHCP "
else :
2016-02-05 18:18:16 +03:00
mode = _ ( " Static " )
2010-02-26 05:13:33 +03:00
addrstr = " - "
if ipv6 [ 2 ] :
2017-10-11 14:35:59 +03:00
addrstr = functools . 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 ( )
2015-04-09 23:07:09 +03:00
def refresh_interface ( self , iface ) :
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
name = iface . get_name ( )
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
2015-04-11 18:40:47 +03:00
def populate_interfaces ( self , src = None , connkey = None ) :
2014-06-03 01:17:47 +04:00
ignore = src
ignore = connkey
2015-04-11 18:40:47 +03:00
iface_list = self . widget ( " interface-list " )
2013-10-01 02:46:54 +04:00
curiface = self . current_interface ( )
2015-04-11 18:40:47 +03:00
model = iface_list . get_model ( )
# Prevent events while the model is modified
iface_list . set_model ( None )
try :
model . clear ( )
iface_list . get_selection ( ) . unselect_all ( )
for iface in self . conn . list_interfaces ( ) :
try :
iface . disconnect_by_func ( self . refresh_interface )
2017-07-24 11:26:48 +03:00
except Exception :
2015-04-11 18:40:47 +03:00
pass
iface . connect ( " state-changed " , self . refresh_interface )
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 ( ) ) ] )
2015-04-11 18:40:47 +03:00
finally :
iface_list . set_model ( model )
2010-02-09 01:13:36 +03:00
2015-05-20 01:13:33 +03:00
uiutil . set_list_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 ) :
2014-09-21 01:30:36 +04:00
2015-04-09 01:29:48 +03:00
if all ( [ edit in EDIT_NET_IDS for edit in self . active_edits ] ) :
2014-09-21 01:30:36 +04:00
self . net_apply ( )
elif all ( [ edit in EDIT_INTERFACE_IDS
for edit in self . active_edits ] ) :
self . interface_apply ( )
2014-07-23 17:48:17 +04:00
self . active_edits = [ ]
return True