2014-07-23 15:48:17 +02:00
# Copyright (C) 2007, 2013-2014 Red Hat, Inc.
2007-03-27 19:52:00 -04:00
# Copyright (C) 2007 Daniel P. Berrange <berrange@redhat.com>
#
2018-04-04 14:35:41 +01:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 15:00:02 -04:00
# See the COPYING file in the top-level directory.
2007-03-27 19:52:00 -04:00
2010-02-25 17:42:00 -05:00
import logging
2008-08-15 11:07:45 -04:00
2012-05-14 14:24:56 +01:00
from gi . repository import Gtk
2011-04-18 12:39:53 -04:00
2017-09-22 19:39:10 +08:00
from virtinst import NodeDevice
2015-05-04 16:33:56 -04:00
from virtinst import util
2007-03-27 19:52:00 -04:00
2014-09-12 16:10:45 -04:00
from . import uiutil
from . asyncjob import vmmAsyncJob
2015-04-08 18:29:48 -04:00
from . baseclass import vmmGObjectUI
2014-09-12 16:10:45 -04:00
from . createnet import vmmCreateNetwork
2018-03-14 18:58:22 -04:00
from . engine import vmmEngine
2014-09-12 16:10:45 -04:00
from . graphwidgets import Sparkline
2015-04-08 18:29:48 -04:00
from . storagelist import vmmStorageList
2007-03-29 21:23:17 -04:00
2014-07-23 15:48:17 +02:00
EDIT_NET_IDS = (
EDIT_NET_NAME ,
2013-09-29 12:28:01 -04:00
EDIT_NET_AUTOSTART ,
2014-06-25 12:36:46 +02:00
EDIT_NET_QOS ,
2017-10-11 12:35:57 +01:00
) = list ( range ( 3 ) )
2013-09-29 12:28:01 -04:00
2013-04-13 14:34:52 -04:00
2010-12-08 17:26:19 -05:00
class vmmHost ( vmmGObjectUI ) :
2018-03-15 05:53:58 -04:00
@classmethod
def show_instance ( cls , parentobj , conn ) :
try :
# Maintain one dialog per connection
uri = conn . get_uri ( )
2018-03-17 19:42:19 -04:00
if cls . _instances is None :
cls . _instances = { }
2018-03-15 05:53:58 -04:00
if uri not in cls . _instances :
2018-03-17 16:08:20 -04:00
cls . _instances [ uri ] = vmmHost ( conn )
2018-03-15 05:53:58 -04:00
cls . _instances [ uri ] . show ( )
except Exception as e :
2018-03-16 18:58:11 -04:00
if not parentobj :
raise
2018-03-15 05:53:58 -04:00
parentobj . err . show_err (
_ ( " Error launching host dialog: %s " ) % str ( e ) )
2012-05-14 14:24:56 +01:00
2011-04-13 10:47:31 -04:00
def __init__ ( self , conn ) :
2013-09-22 16:10:16 -04:00
vmmGObjectUI . __init__ ( self , " host.ui " , " vmm-host " )
2007-03-27 19:52:00 -04:00
self . conn = conn
2015-04-11 13:39:25 -04:00
self . _orig_title = self . topwin . get_title ( )
2011-07-12 11:50:11 -04:00
self . ICON_RUNNING = " state_running "
self . ICON_SHUTOFF = " state_shutoff "
2008-08-15 11:07:45 -04:00
2009-11-17 15:44:27 -05:00
self . addnet = None
2007-03-27 19:52:00 -04:00
2013-09-29 12:28:01 -04:00
self . active_edits = [ ]
2013-09-29 12:14:00 -04:00
2009-11-17 15:44:27 -05:00
self . cpu_usage_graph = None
self . memory_usage_graph = None
self . init_conn_state ( )
2007-03-27 19:52:00 -04:00
2015-04-08 18:29:48 -04:00
self . storagelist = None
2009-11-19 17:29:20 -05:00
self . init_storage_state ( )
2015-04-08 18:29:48 -04:00
self . init_net_state ( )
2009-11-19 17:29:20 -05:00
2013-02-16 13:31:46 -05:00
self . builder . connect_signals ( {
2017-08-05 14:39:32 +08:00
" on_menu_file_view_manager_activate " : self . view_manager ,
" on_menu_file_quit_activate " : self . exit_app ,
2007-03-27 19:52:00 -04:00
" on_menu_file_close_activate " : self . close ,
" on_vmm_host_delete_event " : self . close ,
2013-07-07 11:06:15 -04:00
" on_host_page_switch " : self . page_changed ,
2009-11-17 15:18:38 -05:00
2007-03-29 21:23:17 -04:00
" on_net_add_clicked " : self . add_network ,
2007-04-03 14: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 15:48:17 +02:00
" on_net_apply_clicked " : ( lambda * x : self . net_apply ( ) ) ,
2013-09-22 16:29:58 -04:00
" on_net_list_changed " : self . net_selected ,
2013-09-29 12: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-08 17:13:36 -05:00
2015-04-11 13:39:25 -04:00
" on_overview_name_changed " : self . _overview_name_changed ,
2008-03-24 11:39:19 -04:00
" on_config_autoconnect_toggled " : self . toggle_autoconnect ,
2014-06-25 12:36:46 +02: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 14:15:02 +01:00
} )
2007-03-27 19:52:00 -04:00
2015-04-11 11:40:47 -04:00
self . populate_networks ( )
2013-09-23 12:37:03 -04:00
2015-04-11 11:40:47 -04:00
self . conn . connect ( " net-added " , self . populate_networks )
self . conn . connect ( " net-removed " , self . populate_networks )
2013-09-23 12:37:03 -04:00
self . conn . connect ( " state-changed " , self . conn_state_changed )
2007-03-27 19:52:00 -04:00
self . conn . connect ( " resources-sampled " , self . refresh_resources )
2015-04-08 18:29:48 -04:00
self . refresh_resources ( )
self . conn_state_changed ( )
self . widget ( " config-autoconnect " ) . set_active (
self . conn . get_autoconnect ( ) )
2007-03-27 19:52:00 -04:00
2018-03-15 07:43:56 -04:00
self . _cleanup_on_conn_removed ( )
2009-03-08 15:34:15 -04:00
2009-11-17 15:44:27 -05:00
def init_net_state ( self ) :
2011-07-14 13:13:13 -04:00
self . widget ( " network-pages " ) . set_show_tabs ( False )
2010-02-25 17:31:27 -05:00
2009-11-19 17:29:20 -05:00
# [ unique, label, icon name, icon size, is_active ]
2012-05-14 14:24:56 +01:00
netListModel = Gtk . ListStore ( str , str , str , int , bool )
2011-07-14 13:13:13 -04:00
self . widget ( " net-list " ) . set_model ( netListModel )
2009-11-17 15:44:27 -05:00
2014-07-23 15:48:17 +02:00
sel = self . widget ( " net-list " ) . get_selection ( )
sel . set_select_function ( ( lambda * x : self . confirm_changes ( ) ) , None )
2016-02-05 16:18:16 +01:00
netCol = Gtk . TreeViewColumn ( _ ( " Networks " ) )
2009-11-17 15:44:27 -05:00
netCol . set_spacing ( 6 )
2012-05-14 14:24:56 +01:00
net_txt = Gtk . CellRendererText ( )
net_img = Gtk . CellRendererPixbuf ( )
2009-11-17 15:44:27 -05:00
netCol . pack_start ( net_img , False )
netCol . pack_start ( net_txt , True )
netCol . add_attribute ( net_txt , ' text ' , 1 )
2009-11-19 17:29:20 -05:00
netCol . add_attribute ( net_txt , ' sensitive ' , 4 )
2009-11-17 15:44:27 -05:00
netCol . add_attribute ( net_img , ' icon-name ' , 2 )
netCol . add_attribute ( net_img , ' stock-size ' , 3 )
2011-07-14 13:13:13 -04:00
self . widget ( " net-list " ) . append_column ( netCol )
2012-05-14 14:24:56 +01:00
netListModel . set_sort_column_id ( 1 , Gtk . SortType . ASCENDING )
2009-11-17 15:44:27 -05:00
2017-09-22 19:39:10 +08: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 15:44:27 -05:00
def init_storage_state ( self ) :
2015-04-08 18:29:48 -04:00
self . storagelist = vmmStorageList ( self . conn , self . builder , self . topwin )
self . widget ( " storage-align " ) . add ( self . storagelist . top_box )
2009-11-17 15:44:27 -05:00
def init_conn_state ( self ) :
uri = self . conn . get_uri ( )
auto = self . conn . get_autoconnect ( )
2011-07-14 13:13:13 -04:00
self . widget ( " overview-uri " ) . set_text ( uri )
self . widget ( " config-autoconnect " ) . set_active ( auto )
2009-11-17 15:44:27 -05:00
self . cpu_usage_graph = Sparkline ( )
self . cpu_usage_graph . show ( )
2013-09-27 14:17:57 -04:00
self . widget ( " performance-cpu-align " ) . add ( self . cpu_usage_graph )
2009-11-17 15:44:27 -05:00
self . memory_usage_graph = Sparkline ( )
self . memory_usage_graph . show ( )
2013-09-27 14:17:57 -04:00
self . widget ( " performance-memory-align " ) . add ( self . memory_usage_graph )
2009-11-17 15:44:27 -05:00
2007-03-27 19:52:00 -04:00
def show ( self ) :
2012-01-31 18:16:54 -05:00
logging . debug ( " Showing host details: %s " , self . conn )
2010-12-08 17:26:19 -05:00
vis = self . is_visible ( )
2010-02-23 14:18:12 -05:00
self . topwin . present ( )
2010-12-08 17:26:19 -05:00
if vis :
return
2007-03-27 19:52:00 -04:00
2018-03-14 19:06:30 -04:00
vmmEngine . get_instance ( ) . increment_window_counter ( )
2009-11-17 15:18:38 -05:00
2007-03-27 19:52:00 -04:00
def is_visible ( self ) :
2012-05-14 14:24:56 +01:00
return self . topwin . get_visible ( )
2007-03-27 19:52:00 -04:00
2010-11-29 14:06:43 -05:00
def close ( self , ignore1 = None , ignore2 = None ) :
2018-03-15 07:43:56 -04:00
logging . debug ( " Closing host window for %s " , self . conn )
2010-12-08 17:26:19 -05:00
if not self . is_visible ( ) :
return
2014-07-23 15:48:17 +02:00
self . confirm_changes ( )
2010-12-08 17:26:19 -05:00
self . topwin . hide ( )
2018-03-14 19:06:30 -04:00
vmmEngine . get_instance ( ) . decrement_window_counter ( )
2011-04-13 10:47:31 -04:00
2008-08-15 11:07:45 -04:00
return 1
2007-08-28 21:43:27 -04:00
2011-07-23 21:16:54 -04:00
def _cleanup ( self ) :
self . conn = None
2011-04-13 09:27:02 -04:00
2015-04-08 18:29:48 -04:00
self . storagelist . cleanup ( )
self . storagelist = None
2011-07-23 21:16:54 -04:00
if self . addnet :
self . addnet . cleanup ( )
self . addnet = None
2011-04-13 09:27:02 -04:00
2011-07-23 21:16:54 -04:00
self . cpu_usage_graph . destroy ( )
self . cpu_usage_graph = None
2011-04-13 09:27:02 -04:00
2011-07-23 21:16:54 -04:00
self . memory_usage_graph . destroy ( )
self . memory_usage_graph = None
2011-04-13 09:27:02 -04:00
2018-03-15 05:53:58 -04:00
def view_manager ( self , _src ) :
from . manager import vmmManager
vmmManager . get_instance ( self ) . show ( )
2009-11-17 15:18:38 -05:00
2018-03-14 18:58:22 -04:00
def exit_app ( self , _src ) :
vmmEngine . get_instance ( ) . exit_app ( )
2009-11-17 15:18:38 -05:00
2008-09-18 10:33:53 -04:00
2013-07-07 11:06:15 -04:00
def page_changed ( self , src , child , pagenum ) :
ignore = src
ignore = child
2014-07-23 15:48:17 +02:00
self . confirm_changes ( )
2013-07-07 11:06:15 -04:00
if pagenum == 1 :
2015-04-11 11:40:47 -04:00
self . populate_networks ( )
2013-07-07 11:06:15 -04:00
self . conn . schedule_priority_tick ( pollnet = True )
elif pagenum == 2 :
2015-04-08 18:29:48 -04:00
self . storagelist . refresh_page ( )
2013-07-07 11:06:15 -04:00
2007-03-27 19:52:00 -04:00
def refresh_resources ( self , ignore = None ) :
2015-05-04 16:33:56 -04:00
vm_memory = util . pretty_mem ( self . conn . stats_memory ( ) )
host_memory = util . pretty_mem ( self . conn . host_memory_size ( ) )
2011-07-11 21:22:50 -04:00
cpu_vector = self . conn . host_cpu_time_vector ( )
memory_vector = self . conn . stats_memory_vector ( )
2007-03-27 19:52:00 -04:00
cpu_vector . reverse ( )
memory_vector . reverse ( )
2011-07-11 21:22:50 -04:00
2011-07-14 13:13:13 -04:00
self . widget ( " performance-cpu " ) . set_text ( " %d %% " %
2011-07-11 21:22:50 -04:00
self . conn . host_cpu_time_percentage ( ) )
2011-07-14 13:13:13 -04:00
self . widget ( " performance-memory " ) . set_text (
2011-07-11 21: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-27 19:52:00 -04:00
self . memory_usage_graph . set_property ( " data_array " , memory_vector )
2008-09-18 10:33:53 -04:00
def conn_state_changed ( self , ignore1 = None ) :
2014-09-11 18:16:21 -04:00
conn_active = self . conn . is_active ( )
2015-04-11 13:39:25 -04: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 12:42:49 -04:00
self . widget ( " net-add " ) . set_sensitive ( conn_active and
self . conn . is_network_capable ( ) )
2015-04-10 09:31:13 -04:00
if conn_active and not self . conn . is_network_capable ( ) :
2010-03-20 18:42:32 -04:00
self . set_net_error_page (
_ ( " Libvirt connection does not support virtual network "
" management. " ) )
2015-04-09 15:07:16 -04:00
if conn_active :
2015-05-19 18:13:33 -04:00
uiutil . set_list_selection_by_number ( self . widget ( " net-list " ) , 0 )
2015-04-09 15:07:16 -04:00
return
self . set_net_error_page ( _ ( " Connection not active. " ) )
2015-04-11 11:40:47 -04:00
self . populate_networks ( )
2015-04-09 15:07:16 -04:00
self . storagelist . close ( )
if self . addnet :
self . addnet . close ( )
2010-03-20 18:42:32 -04:00
2015-04-11 13:39:25 -04:00
def _overview_name_changed ( self , src ) :
src = self . widget ( " overview-name " )
self . conn . set_config_pretty_name ( src . get_text ( ) )
2009-11-25 14:16:31 -05:00
def toggle_autoconnect ( self , src ) :
self . conn . set_autoconnect ( src . get_active ( ) )
2009-11-17 15:44:27 -05:00
2013-09-30 18:46:54 -04:00
2015-04-11 13:39:25 -04:00
#############################
# Virtual Network functions #
#############################
2008-08-15 11:07:45 -04:00
2010-12-09 11:22:35 -05:00
def delete_network ( self , src_ignore ) :
2008-08-15 11:07:45 -04:00
net = self . current_network ( )
2008-08-26 12:10:25 -04:00
if net is None :
return
2009-01-23 16:34:33 -05:00
result = self . err . yes_no ( _ ( " Are you sure you want to permanently "
" delete the network %s ? " ) % net . get_name ( ) )
2008-08-26 12:10:25 -04:00
if not result :
return
2010-12-10 14:02:11 -05:00
2012-01-16 22:04:40 -05:00
logging . debug ( " Deleting network ' %s ' " , net . get_name ( ) )
2011-04-15 15:23:13 -04:00
vmmAsyncJob . simple_async_noshow ( net . delete , [ ] , self ,
_ ( " Error deleting network ' %s ' " ) % net . get_name ( ) )
2008-08-15 11:07:45 -04:00
2010-12-09 11:22:35 -05:00
def start_network ( self , src_ignore ) :
2008-08-15 11:07:45 -04:00
net = self . current_network ( )
2008-08-26 12:10:25 -04:00
if net is None :
return
2012-01-16 22:04:40 -05:00
logging . debug ( " Starting network ' %s ' " , net . get_name ( ) )
2011-04-15 15:23:13 -04:00
vmmAsyncJob . simple_async_noshow ( net . start , [ ] , self ,
_ ( " Error starting network ' %s ' " ) % net . get_name ( ) )
2008-08-15 11:07:45 -04:00
2010-12-09 11:22:35 -05:00
def stop_network ( self , src_ignore ) :
2008-08-15 11:07:45 -04:00
net = self . current_network ( )
2008-08-26 12:10:25 -04:00
if net is None :
return
2012-01-16 22:04:40 -05:00
logging . debug ( " Stopping network ' %s ' " , net . get_name ( ) )
2017-09-22 19:39:10 +08:00
self . widget ( " vf-list " ) . get_model ( ) . clear ( )
2011-04-15 15:23:13 -04:00
vmmAsyncJob . simple_async_noshow ( net . stop , [ ] , self ,
_ ( " Error stopping network ' %s ' " ) % net . get_name ( ) )
2008-08-15 11:07:45 -04:00
2010-12-09 11:22:35 -05:00
def add_network ( self , src_ignore ) :
2010-12-10 14:02:11 -05:00
logging . debug ( " Launching ' Add Network ' " )
2008-08-26 12:10:25 -04:00
try :
if self . addnet is None :
2010-12-08 17:26:19 -05:00
self . addnet = vmmCreateNetwork ( self . conn )
2011-04-14 08:47:42 -04:00
self . addnet . show ( self . topwin )
2017-05-05 12:47:21 -04:00
except Exception as e :
2011-04-06 11:22:03 -04:00
self . err . show_err ( _ ( " Error launching network wizard: %s " ) % str ( e ) )
2008-08-15 11:07:45 -04:00
2014-07-23 15:48:17 +02:00
def net_apply ( self ) :
2008-08-26 11:17:31 -04:00
net = self . current_network ( )
if net is None :
return
2012-01-16 22:04:40 -05:00
logging . debug ( " Applying changes for network ' %s ' " , net . get_name ( ) )
2008-08-26 11:17:31 -04:00
try :
2013-09-29 12:28:01 -04:00
if EDIT_NET_AUTOSTART in self . active_edits :
2013-09-29 12:14:00 -04:00
auto = self . widget ( " net-autostart " ) . get_active ( )
net . set_autostart ( auto )
2013-09-29 12:28:01 -04:00
if EDIT_NET_NAME in self . active_edits :
2013-09-29 12:14:00 -04:00
net . define_name ( self . widget ( " net-name " ) . get_text ( ) )
2015-04-11 11:40:47 -04:00
self . idle_add ( self . populate_networks )
2014-06-25 12:36:46 +02: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 12:47:21 -04:00
except Exception as e :
2013-09-30 18:46:54 -04:00
self . err . show_err ( _ ( " Error changing network settings: %s " ) % str ( e ) )
2008-08-26 11:17:31 -04:00
return
2013-09-29 12:14:00 -04:00
finally :
self . disable_net_apply ( )
def disable_net_apply ( self ) :
2014-07-23 15:48:17 +02:00
for i in EDIT_NET_IDS :
if i in self . active_edits :
self . active_edits . remove ( i )
2011-07-14 13:13:13 -04:00
self . widget ( " net-apply " ) . set_sensitive ( False )
2008-08-26 11:17:31 -04:00
2013-09-29 12:14:00 -04:00
def enable_net_apply ( self , * arglist ) :
edittype = arglist [ - 1 ]
self . widget ( " net-apply " ) . set_sensitive ( True )
2013-09-29 12:28:01 -04:00
if edittype not in self . active_edits :
self . active_edits . append ( edittype )
2013-09-29 12:14:00 -04:00
2010-12-09 11:22:35 -05:00
def net_autostart_changed ( self , src_ignore ) :
2013-09-29 12:14:00 -04:00
self . enable_net_apply ( EDIT_NET_AUTOSTART )
2008-08-26 11:17:31 -04:00
2007-04-03 14:01:45 -04:00
def current_network ( self ) :
2015-05-19 17:17:53 -04:00
connkey = uiutil . get_list_selection ( self . widget ( " net-list " ) )
2015-05-07 11:23:00 -04:00
return connkey and self . conn . get_net ( connkey )
2007-04-03 14:01:45 -04:00
2015-04-09 16:07:09 -04:00
def refresh_network ( self , net ) :
connkey = net . get_connkey ( )
2011-07-14 13:13:13 -04:00
uilist = self . widget ( " net-list " )
2010-12-10 14:02:11 -05:00
sel = uilist . get_selection ( )
2014-01-26 20:21:12 -05:00
model , treeiter = sel . get_selected ( )
2010-12-10 14:02:11 -05:00
for row in uilist . get_model ( ) :
2014-06-02 17:17:47 -04:00
if row [ 0 ] == connkey :
2013-07-07 11:06:15 -04:00
row [ 4 ] = net . is_active ( )
2010-12-10 14:02:11 -05:00
2014-01-26 20:21:12 -05:00
if treeiter is not None :
2014-06-02 17:17:47 -04:00
if model [ treeiter ] [ 0 ] == connkey :
2007-04-03 14:01:45 -04:00
self . net_selected ( sel )
2007-03-27 19:52:00 -04:00
2010-02-25 17:31:27 -05:00
def set_net_error_page ( self , msg ) :
self . reset_net_state ( )
2011-07-14 13:13:13 -04:00
self . widget ( " network-pages " ) . set_current_page ( 1 )
self . widget ( " network-error-label " ) . set_text ( msg )
2010-02-25 17:31:27 -05:00
2007-03-27 19:52:00 -04:00
def net_selected ( self , src ) :
2014-01-26 20:21:12 -05:00
model , treeiter = src . get_selected ( )
if treeiter is None :
2010-02-25 17:31:27 -05:00
self . set_net_error_page ( _ ( " No virtual network selected. " ) )
2008-08-26 10:55:03 -04:00
return
2009-03-08 15:34:15 -04:00
2011-07-14 13:13:13 -04:00
self . widget ( " network-pages " ) . set_current_page ( 0 )
2014-06-02 17:17:47 -04:00
connkey = model [ treeiter ] [ 0 ]
2013-03-29 14:38:28 -04:00
try :
2014-06-02 17:17:47 -04:00
net = self . conn . get_net ( connkey )
2010-02-25 17:42:00 -05:00
self . populate_net_state ( net )
2017-05-05 12:47:21 -04:00
except Exception as e :
2010-02-25 17:42:00 -05:00
logging . exception ( e )
self . set_net_error_page ( _ ( " Error selecting network: %s " ) % e )
2013-09-29 12:14:00 -04:00
finally :
self . disable_net_apply ( )
2010-02-25 19:42:08 -05:00
2013-09-20 20: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-26 18:15:50 -05:00
uiutil . set_grid_row_visible (
2013-09-20 20: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-26 18:15:50 -05:00
uiutil . set_grid_row_visible (
2013-09-20 20: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 12:36:46 +02: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 19:39:10 +08: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-25 17:42:00 -05:00
def populate_net_state ( self , net ) :
2008-08-26 10:55:03 -04:00
active = net . is_active ( )
2011-07-14 13:13:13 -04:00
self . widget ( " net-details " ) . set_sensitive ( True )
2013-09-29 12:14:00 -04:00
self . widget ( " net-name " ) . set_text ( net . get_name ( ) )
self . widget ( " net-name " ) . set_editable ( not active )
2013-09-20 20: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-26 18:15:50 -05:00
uiutil . set_grid_row_visible ( self . widget ( " net-name-domain " ) ,
2013-09-20 20:40:07 -04:00
bool ( net . get_name_domain ( ) ) )
2008-08-26 10:55:03 -04:00
2009-11-16 07:14:49 -05:00
state = active and _ ( " Active " ) or _ ( " Inactive " )
2011-07-12 11:50:11 -04:00
icon = ( active and self . ICON_RUNNING or
self . ICON_SHUTOFF )
2011-07-14 13:13:13 -04:00
self . widget ( " net-state " ) . set_text ( state )
self . widget ( " net-state-icon " ) . set_from_icon_name ( icon ,
2014-01-12 14:36:03 -05:00
Gtk . IconSize . BUTTON )
2008-08-26 10:55:03 -04:00
2011-07-14 13: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 10:55:03 -04:00
autostart = net . get_autostart ( )
2011-07-14 13:13:13 -04:00
self . widget ( " net-autostart " ) . set_active ( autostart )
2017-03-21 10:19:05 -05:00
self . widget ( " net-autostart " ) . set_label ( _ ( " On Boot " ) )
2008-08-26 10:55:03 -04:00
2013-09-20 20:40:07 -04:00
self . _populate_net_ipv4_state ( net )
self . _populate_net_ipv6_state ( net )
2014-06-25 12:36:46 +02:00
self . _populate_qos_state ( net )
2017-09-22 19:39:10 +08:00
self . _populate_sriov_state ( net )
2013-03-29 14:38:28 -04:00
2008-08-26 11:17:31 -04:00
2008-08-26 10:55:03 -04:00
def reset_net_state ( self ) :
2011-07-14 13: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 14:36:03 -05:00
Gtk . IconSize . BUTTON )
2011-07-14 13: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 10:19:05 -05:00
self . widget ( " net-autostart " ) . set_label ( _ ( " On Boot " ) )
2011-07-14 13:13:13 -04:00
self . widget ( " net-autostart " ) . set_active ( False )
2013-09-20 20: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 14:24:56 +01:00
Gtk . STOCK_DISCONNECT , Gtk . IconSize . MENU )
2013-09-20 20:40:07 -04:00
self . widget ( " net-ipv4-forwarding " ) . set_text (
2013-03-29 14:38:28 -04:00
_ ( " Isolated network " ) )
2013-09-20 20: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 14:38:28 -04:00
_ ( " Isolated network " ) )
2013-09-29 12:14:00 -04:00
self . disable_net_apply ( )
2007-03-27 19:52:00 -04:00
2015-04-11 11:40:47 -04:00
def populate_networks ( self , src = None , connkey = None ) :
2014-06-02 17:17:47 -04:00
ignore = src
ignore = connkey
2007-03-29 21:23:17 -04:00
2015-04-11 11:40:47 -04:00
net_list = self . widget ( " net-list " )
2013-09-30 18:46:54 -04:00
curnet = self . current_network ( )
2015-04-11 11:40:47 -04: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 ( ) :
2018-03-15 07:43:56 -04:00
net . disconnect_by_obj ( self )
2015-04-11 11:40:47 -04:00
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-27 19:52:00 -04:00
2015-05-19 18:13:33 -04:00
uiutil . set_list_selection ( net_list ,
2014-06-02 17:17:47 -04:00
curnet and curnet . get_connkey ( ) or None )
2009-03-08 15:34:15 -04:00
2007-03-27 19:52:00 -04:00
2014-07-23 15:48:17 +02: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-20 17:30:36 -04:00
2015-04-08 18:29:48 -04:00
if all ( [ edit in EDIT_NET_IDS for edit in self . active_edits ] ) :
2014-09-20 17:30:36 -04:00
self . net_apply ( )
2014-07-23 15:48:17 +02:00
self . active_edits = [ ]
return True