2010-02-09 01:18:06 +03:00
#
2013-10-28 00:59:46 +04:00
# Copyright (C) 2008, 2013 Red Hat, Inc.
2010-02-09 01:18:06 +03:00
# Copyright (C) 2008 Cole Robinson <crobinso@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
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
#
2012-05-14 17:24:56 +04:00
from gi . repository import Gtk
from gi . repository import Gdk
2010-02-09 01:18:06 +03:00
import logging
2013-09-10 01:14:16 +04:00
from virtinst import Interface , InterfaceProtocol
2010-02-09 01:18:06 +03:00
2014-09-13 00:10:45 +04:00
from . import uiutil
from . baseclass import vmmGObjectUI
from . asyncjob import vmmAsyncJob
2010-02-09 01:18:06 +03:00
PAGE_TYPE = 0
PAGE_DETAILS = 1
DETAILS_BOND = 0
DETAILS_BRIDGE = 1
DETAILS_VLAN = 2
DETAILS_ETHERNET = 3
INTERFACE_ROW_KEY = 0
INTERFACE_ROW_SELECT = 1
INTERFACE_ROW_CANT_SELECT = 2
INTERFACE_ROW_NAME = 3
INTERFACE_ROW_TYPE = 4
INTERFACE_ROW_IS_DEFINED = 5
INTERFACE_ROW_IS_ACTIVE = 6
INTERFACE_ROW_IN_USE_BY = 7
INTERFACE_ROW_MAC = 8
BOND_PAGE_ARP = 0
BOND_PAGE_MII = 1
BOND_PAGE_DEFAULT = 2
2010-02-27 02:49:18 +03:00
IP_DHCP = 0
IP_STATIC = 1
IP_NONE = 2
2013-04-13 22:34:52 +04:00
2010-12-09 01:26:19 +03:00
class vmmCreateInterface ( vmmGObjectUI ) :
2012-11-09 12:49:29 +04:00
__gsignals__ = { }
2012-05-14 17:24:56 +04:00
2010-12-09 01:26:19 +03:00
def __init__ ( self , conn ) :
vmmGObjectUI . __init__ ( self ,
2013-09-23 00:10:16 +04:00
" createinterface.ui " , " vmm-create-interface " )
2010-02-09 01:18:06 +03:00
self . conn = conn
self . interface = None
2012-02-02 02:26:46 +04:00
self . bridge_config = self . widget ( " bridge-config " )
2011-04-14 16:47:42 +04:00
self . bridge_config . set_transient_for ( self . topwin )
2010-02-09 01:18:06 +03:00
2012-02-02 02:26:46 +04:00
self . bond_config = self . widget ( " bond-config " )
2011-04-14 16:47:42 +04:00
self . bond_config . set_transient_for ( self . topwin )
2010-02-09 01:18:06 +03:00
2012-02-02 02:26:46 +04:00
self . ip_config = self . widget ( " ip-config " )
2011-04-14 16:47:42 +04:00
self . ip_config . set_transient_for ( self . topwin )
2010-02-27 02:49:18 +03:00
self . ip_manually_changed = False
2010-02-09 01:18:06 +03:00
2013-02-16 22:31:46 +04:00
self . builder . connect_signals ( {
2010-02-09 01:18:06 +03:00
" on_vmm_create_interface_delete_event " : self . close ,
" on_cancel_clicked " : self . close ,
" on_back_clicked " : self . back ,
" on_forward_clicked " : self . forward ,
" on_finish_clicked " : self . finish ,
" on_pages_switch_page " : self . page_changed ,
" on_bridge_config_button_clicked " : self . show_bridge_config ,
" on_bond_config_button_clicked " : self . show_bond_config ,
2010-02-27 02:49:18 +03:00
" on_ip_config_button_clicked " : self . show_ip_config ,
2010-02-09 01:18:06 +03:00
" on_vlan_tag_changed " : self . update_interface_name ,
2012-02-02 02:26:46 +04:00
# Bridge config dialog
" on_bridge_config_delete_event " : self . bridge_config_finish ,
" on_bridge_ok_clicked " : self . bridge_config_finish ,
# IP config dialog
" on_ip_config_delete_event " : self . ip_config_finish ,
" on_ip_ok_clicked " : self . ip_config_finish ,
" on_ip_copy_interface_toggled " : self . ip_copy_interface_toggled ,
" on_ipv4_mode_changed " : self . ipv4_mode_changed ,
" on_ipv6_mode_changed " : self . ipv6_mode_changed ,
" on_ipv6_address_add_clicked " : self . ipv6_address_add ,
" on_ipv6_address_remove_clicked " : self . ipv6_address_remove ,
2013-09-23 00:29:58 +04:00
" on_ipv6_address_list_changed " : self . ipv6_address_selected ,
2012-02-02 02:26:46 +04:00
# Bond config dialog
" on_bond_config_delete_event " : self . bond_config_finish ,
" on_bond_ok_clicked " : self . bond_config_finish ,
" on_bond_monitor_mode_changed " : self . bond_monitor_mode_changed ,
2010-02-09 01:18:06 +03:00
} )
2011-04-18 19:25:28 +04:00
self . bind_escape_key_close ( )
2010-02-09 01:18:06 +03:00
self . set_initial_state ( )
2011-04-14 16:47:42 +04:00
def show ( self , parent ) :
2012-02-01 03:16:54 +04:00
logging . debug ( " Showing new interface wizard " )
2010-02-09 01:18:06 +03:00
self . reset_state ( )
2011-04-14 16:47:42 +04:00
self . topwin . set_transient_for ( parent )
2010-02-09 01:18:06 +03:00
self . topwin . present ( )
def show_bond_config ( self , src ) :
2012-02-01 03:16:54 +04:00
logging . debug ( " Showing new interface bond config " )
2010-02-09 01:18:06 +03:00
self . bond_config . show_all ( )
def show_bridge_config ( self , src ) :
2012-02-01 03:16:54 +04:00
logging . debug ( " Showing new interface bridge config " )
2010-02-09 01:18:06 +03:00
self . bridge_config . show_all ( )
2010-02-27 02:49:18 +03:00
def show_ip_config ( self , src ) :
2012-02-01 03:16:54 +04:00
logging . debug ( " Showing new interface ip config " )
2010-02-27 02:49:18 +03:00
self . ip_manually_changed = True
self . ip_config . show_all ( )
2010-02-09 01:18:06 +03:00
def close ( self , ignore1 = None , ignore2 = None ) :
2015-06-06 21:32:04 +03:00
if self . topwin . is_visible ( ) :
logging . debug ( " Closing new interface wizard " )
2010-12-09 22:46:15 +03:00
self . ip_config . hide ( )
self . bridge_config . hide ( )
self . bond_config . hide ( )
2010-02-09 01:18:06 +03:00
self . topwin . hide ( )
return 1
2011-07-24 05:16:54 +04:00
def _cleanup ( self ) :
self . conn = None
self . interface = None
2011-04-13 17:27:02 +04:00
2011-07-24 05:16:54 +04:00
self . ip_config . destroy ( )
self . ip_config = None
2011-04-13 17:27:02 +04:00
2011-07-24 05:16:54 +04:00
self . bridge_config . destroy ( )
self . bridge_config = None
2011-04-13 17:27:02 +04:00
2011-07-24 05:16:54 +04:00
self . bond_config . destroy ( )
self . bond_config = None
2011-04-13 17:27:02 +04:00
2014-01-27 02:09:07 +04:00
2010-02-09 01:18:06 +03:00
###########################
# Initialization routines #
###########################
2014-01-27 02:42:24 +04:00
@staticmethod
def iface_in_use_by ( conn , name ) :
use_str = " "
2014-06-03 01:17:47 +04:00
for iface in conn . list_interfaces ( ) :
2014-01-27 02:42:24 +04:00
if name in iface . get_slave_names ( ) :
if use_str :
use_str + = " , "
use_str + = iface . get_name ( )
return use_str
2014-01-27 02:09:07 +04:00
@staticmethod
def build_interface_startmode_combo ( combo ) :
model = Gtk . ListStore ( str )
combo . set_model ( model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( combo , 0 )
2014-01-27 02:09:07 +04:00
model . append ( [ " none " ] )
model . append ( [ " onboot " ] )
model . append ( [ " hotplug " ] )
2010-02-09 01:18:06 +03:00
def set_initial_state ( self ) :
2011-07-14 21:13:13 +04:00
self . widget ( " pages " ) . set_show_tabs ( False )
2012-02-02 02:26:46 +04:00
self . widget ( " bond-pages " ) . set_show_tabs ( False )
2010-02-09 01:18:06 +03:00
2012-05-14 17:24:56 +04:00
blue = Gdk . Color . parse ( " #0072A8 " ) [ 1 ]
self . widget ( " header " ) . modify_bg ( Gtk . StateType . NORMAL , blue )
2010-02-09 01:18:06 +03:00
# Interface type
2011-07-14 21:13:13 +04:00
type_list = self . widget ( " interface-type " )
2012-05-14 17:24:56 +04:00
type_model = Gtk . ListStore ( str , str )
2010-02-09 01:18:06 +03:00
type_list . set_model ( type_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( type_list , 1 )
2013-09-10 01:14:16 +04:00
type_model . append ( [ Interface . INTERFACE_TYPE_BRIDGE ,
2010-02-09 01:18:06 +03:00
_ ( " Bridge " ) ] )
2013-09-10 01:14:16 +04:00
type_model . append ( [ Interface . INTERFACE_TYPE_BOND ,
2010-02-09 01:18:06 +03:00
_ ( " Bond " ) ] )
2013-09-10 01:14:16 +04:00
type_model . append ( [ Interface . INTERFACE_TYPE_ETHERNET ,
2010-02-09 01:18:06 +03:00
_ ( " Ethernet " ) ] )
2013-09-10 01:14:16 +04:00
type_model . append ( [ Interface . INTERFACE_TYPE_VLAN ,
2010-02-09 01:18:06 +03:00
_ ( " VLAN " ) ] )
# Start mode
2014-01-27 02:09:07 +04:00
self . build_interface_startmode_combo (
2011-07-14 21:13:13 +04:00
self . widget ( " interface-startmode " ) )
2010-02-09 01:18:06 +03:00
# Parent/slave Interface list
2011-07-14 21:13:13 +04:00
slave_list = self . widget ( " interface-list " )
2015-06-04 06:12:19 +03:00
# [ vmmInterface, selected, selectable, name, type, is defined,
2010-02-09 01:18:06 +03:00
# is active, in use by str, mac]
2012-05-14 17:24:56 +04:00
slave_model = Gtk . ListStore ( object , bool , bool , str , str , bool , bool ,
2010-02-09 01:18:06 +03:00
str , str )
slave_list . set_model ( slave_model )
2012-05-14 17:24:56 +04:00
selectCol = Gtk . TreeViewColumn ( )
nameCol = Gtk . TreeViewColumn ( _ ( " Name " ) )
typeCol = Gtk . TreeViewColumn ( _ ( " Type " ) )
useCol = Gtk . TreeViewColumn ( _ ( " In use by " ) )
2010-02-09 01:18:06 +03:00
slave_list . append_column ( selectCol )
slave_list . append_column ( nameCol )
slave_list . append_column ( typeCol )
slave_list . append_column ( useCol )
2012-05-14 17:24:56 +04:00
chk = Gtk . CellRendererToggle ( )
2010-02-09 01:18:06 +03:00
chk . connect ( " toggled " , self . interface_item_toggled , slave_list )
selectCol . pack_start ( chk , False )
selectCol . add_attribute ( chk , " active " , INTERFACE_ROW_SELECT )
selectCol . add_attribute ( chk , " inconsistent " , INTERFACE_ROW_CANT_SELECT )
selectCol . set_sort_column_id ( INTERFACE_ROW_CANT_SELECT )
2012-05-14 17:24:56 +04:00
txt = Gtk . CellRendererText ( )
2010-02-09 01:18:06 +03:00
nameCol . pack_start ( txt , True )
nameCol . add_attribute ( txt , " text " , INTERFACE_ROW_NAME )
nameCol . set_sort_column_id ( INTERFACE_ROW_NAME )
2012-05-14 17:24:56 +04:00
txt = Gtk . CellRendererText ( )
2010-02-09 01:18:06 +03:00
typeCol . pack_start ( txt , True )
typeCol . add_attribute ( txt , " text " , INTERFACE_ROW_TYPE )
typeCol . set_sort_column_id ( INTERFACE_ROW_TYPE )
slave_model . set_sort_column_id ( INTERFACE_ROW_CANT_SELECT ,
2012-05-14 17:24:56 +04:00
Gtk . SortType . ASCENDING )
2010-02-09 01:18:06 +03:00
2012-05-14 17:24:56 +04:00
txt = Gtk . CellRendererText ( )
2010-02-09 01:18:06 +03:00
useCol . pack_start ( txt , True )
useCol . add_attribute ( txt , " text " , INTERFACE_ROW_IN_USE_BY )
useCol . set_sort_column_id ( INTERFACE_ROW_IN_USE_BY )
# Bond config
2012-02-02 02:26:46 +04:00
mode_list = self . widget ( " bond-mode " )
2012-05-14 17:24:56 +04:00
mode_model = Gtk . ListStore ( str , str )
2010-02-09 01:18:06 +03:00
mode_list . set_model ( mode_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( mode_list , 0 )
2010-02-09 01:18:06 +03:00
mode_model . append ( [ _ ( " System default " ) , None ] )
2013-09-10 01:14:16 +04:00
for m in Interface . INTERFACE_BOND_MODES :
2010-02-09 01:18:06 +03:00
mode_model . append ( [ m , m ] )
2012-02-02 02:26:46 +04:00
mon_list = self . widget ( " bond-monitor-mode " )
2012-05-14 17:24:56 +04:00
mon_model = Gtk . ListStore ( str , str )
2010-02-09 01:18:06 +03:00
mon_list . set_model ( mon_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( mon_list , 0 )
2010-02-09 01:18:06 +03:00
mon_model . append ( [ _ ( " System default " ) , None ] )
2013-09-10 01:14:16 +04:00
for m in Interface . INTERFACE_BOND_MONITOR_MODES :
2010-02-09 01:18:06 +03:00
mon_model . append ( [ m , m ] )
2012-02-02 02:26:46 +04:00
validate_list = self . widget ( " arp-validate " )
2012-05-14 17:24:56 +04:00
validate_model = Gtk . ListStore ( str )
2010-02-09 01:18:06 +03:00
validate_list . set_model ( validate_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( validate_list , 0 )
2013-09-10 01:14:16 +04:00
for m in Interface . INTERFACE_BOND_MONITOR_MODE_ARP_VALIDATE_MODES :
2010-02-09 01:18:06 +03:00
validate_model . append ( [ m ] )
2012-02-02 02:26:46 +04:00
carrier_list = self . widget ( " mii-carrier " )
2012-05-14 17:24:56 +04:00
carrier_model = Gtk . ListStore ( str )
2010-02-09 01:18:06 +03:00
carrier_list . set_model ( carrier_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( carrier_list , 0 )
2013-09-10 01:14:16 +04:00
for m in Interface . INTERFACE_BOND_MONITOR_MODE_MII_CARRIER_TYPES :
2010-02-09 01:18:06 +03:00
carrier_model . append ( [ m ] )
2010-02-27 02:49:18 +03:00
# IP config
2012-02-02 02:26:46 +04:00
copy_iface = self . widget ( " ip-copy-interface-combo " )
2012-05-14 17:24:56 +04:00
copy_model = Gtk . ListStore ( str , object , bool )
2010-02-27 02:49:18 +03:00
copy_iface . set_model ( copy_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( copy_iface , 0 )
2010-02-27 02:49:18 +03:00
2012-02-02 02:26:46 +04:00
ip_mode = self . widget ( " ipv4-mode " )
2012-05-14 17:24:56 +04:00
ip_model = Gtk . ListStore ( str )
2010-02-27 02:49:18 +03:00
ip_mode . set_model ( ip_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( ip_mode , 0 )
2010-02-27 02:49:18 +03:00
ip_model . insert ( IP_DHCP , [ " DHCP " ] )
ip_model . insert ( IP_STATIC , [ " Static " ] )
ip_model . insert ( IP_NONE , [ " No configuration " ] )
2012-02-02 02:26:46 +04:00
ip_mode = self . widget ( " ipv6-mode " )
2012-05-14 17:24:56 +04:00
ip_model = Gtk . ListStore ( str )
2010-02-27 02:49:18 +03:00
ip_mode . set_model ( ip_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( ip_mode , 0 )
2010-02-27 02:49:18 +03:00
ip_model . insert ( IP_DHCP , [ " DHCP " ] )
ip_model . insert ( IP_STATIC , [ " Static " ] )
ip_model . insert ( IP_NONE , [ " No configuration " ] )
2012-02-02 02:26:46 +04:00
v6_addr = self . widget ( " ipv6-address-list " )
2012-05-14 17:24:56 +04:00
addr_model = Gtk . ListStore ( str )
2010-02-27 02:49:18 +03:00
v6_addr . set_model ( addr_model )
2012-05-14 17:24:56 +04:00
txt_col = Gtk . TreeViewColumn ( " " )
2010-02-27 02:49:18 +03:00
v6_addr . append_column ( txt_col )
2012-05-14 17:24:56 +04:00
txt = Gtk . CellRendererText ( )
2010-02-27 02:49:18 +03:00
txt . set_property ( " editable " , True )
2013-08-18 19:11:15 +04:00
txt . connect ( " edited " , self . ipv6_address_edited )
2010-02-27 02:49:18 +03:00
txt_col . pack_start ( txt , True )
txt_col . add_attribute ( txt , " text " , 0 )
2010-02-09 01:18:06 +03:00
def reset_state ( self ) :
2011-07-14 21:13:13 +04:00
self . widget ( " pages " ) . set_current_page ( PAGE_TYPE )
2010-02-09 01:18:06 +03:00
self . page_changed ( None , None , PAGE_TYPE )
2011-07-14 21:13:13 +04:00
self . widget ( " interface-type " ) . set_active ( 0 )
2010-02-09 01:18:06 +03:00
# General details
2011-07-14 21:13:13 +04:00
self . widget ( " interface-name-entry " ) . set_text ( " " )
self . widget ( " interface-name-label " ) . set_text ( " " )
self . widget ( " interface-startmode " ) . set_active ( 0 )
self . widget ( " interface-activate " ) . set_active ( False )
2010-02-09 01:18:06 +03:00
# Bridge config
2012-02-02 02:26:46 +04:00
self . widget ( " bridge-delay " ) . set_value ( 0 )
self . widget ( " bridge-stp " ) . set_active ( True )
2010-02-09 01:18:06 +03:00
# Bond config
2012-02-02 02:26:46 +04:00
self . widget ( " bond-mode " ) . set_active ( 0 )
self . widget ( " bond-monitor-mode " ) . set_active ( 0 )
2010-02-09 01:18:06 +03:00
2012-02-02 02:26:46 +04:00
self . widget ( " arp-interval " ) . set_value ( 0 )
self . widget ( " arp-target " ) . set_text ( " " )
self . widget ( " arp-validate " ) . set_active ( 0 )
2010-02-09 01:18:06 +03:00
2012-02-02 02:26:46 +04:00
self . widget ( " mii-frequency " ) . set_value ( 0 )
self . widget ( " mii-updelay " ) . set_value ( 0 )
self . widget ( " mii-downdelay " ) . set_value ( 0 )
self . widget ( " mii-carrier " ) . set_active ( 0 )
2010-02-09 01:18:06 +03:00
2010-02-27 02:49:18 +03:00
# IP config
self . ip_manually_changed = False
2012-02-02 02:26:46 +04:00
self . widget ( " ip-do-manual " ) . set_active ( True )
self . widget ( " ip-do-manual-box " ) . set_current_page ( 0 )
2010-02-27 02:49:18 +03:00
2012-02-02 02:26:46 +04:00
self . widget ( " ipv4-mode " ) . set_active ( IP_DHCP )
self . widget ( " ipv4-address " ) . set_text ( " " )
self . widget ( " ipv4-gateway " ) . set_text ( " " )
2010-02-27 02:49:18 +03:00
2012-02-02 02:26:46 +04:00
self . widget ( " ipv6-mode " ) . set_active ( IP_NONE )
self . widget ( " ipv6-autoconf " ) . set_active ( False )
2013-09-10 01:14:16 +04:00
self . widget ( " ipv6-gateway " ) . set_text ( " " )
self . widget ( " ipv6-address-list " ) . get_model ( ) . clear ( )
2010-02-27 02:49:18 +03:00
self . ipv6_address_selected ( )
2010-02-09 01:18:06 +03:00
def populate_details_page ( self ) :
itype = self . get_config_interface_type ( )
# Set up default interface name
2011-07-14 21:13:13 +04:00
self . widget ( " interface-name-entry " ) . hide ( )
self . widget ( " interface-name-label " ) . hide ( )
2010-02-09 01:18:06 +03:00
2013-09-10 01:14:16 +04:00
if itype in [ Interface . INTERFACE_TYPE_BRIDGE ,
Interface . INTERFACE_TYPE_BOND ] :
2010-02-09 01:18:06 +03:00
widget = " interface-name-entry "
else :
widget = " interface-name-label "
2011-07-14 21:13:13 +04:00
self . widget ( widget ) . show ( )
2010-02-09 01:18:06 +03:00
default_name = self . get_default_name ( )
self . set_interface_name ( default_name )
# Make sure interface type specific fields are shown
type_dict = {
2013-09-10 01:14:16 +04:00
Interface . INTERFACE_TYPE_BRIDGE : " bridge " ,
Interface . INTERFACE_TYPE_BOND : " bond " ,
Interface . INTERFACE_TYPE_VLAN : " vlan " ,
2010-02-09 01:18:06 +03:00
}
for key , value in type_dict . items ( ) :
do_show = ( key == itype )
2013-09-02 04:18:14 +04:00
self . widget ( " %s -label " % value ) . set_visible ( do_show )
self . widget ( " %s -box " % value ) . set_visible ( do_show )
2010-02-09 01:18:06 +03:00
2013-09-10 01:14:16 +04:00
if itype == Interface . INTERFACE_TYPE_BRIDGE :
2010-02-09 01:18:06 +03:00
self . update_bridge_desc ( )
2013-09-10 01:14:16 +04:00
elif itype == Interface . INTERFACE_TYPE_BOND :
2010-02-09 01:18:06 +03:00
self . update_bond_desc ( )
# Populate device list
self . populate_interface_list ( itype )
2010-02-27 02:49:18 +03:00
self . update_ip_config ( )
def update_ip_config ( self ) :
( is_manual , current_name ,
ignore , ignore , ignore ) = self . get_config_ip_info ( )
2010-02-09 01:18:06 +03:00
itype = self . get_config_interface_type ( )
2010-02-27 02:49:18 +03:00
ifaces = self . get_config_selected_interfaces ( )
2010-02-09 01:18:06 +03:00
2012-02-02 02:26:46 +04:00
copy_radio = self . widget ( " ip-copy-interface " )
copy_combo = self . widget ( " ip-copy-interface-combo " )
2010-02-27 02:49:18 +03:00
copy_model = copy_combo . get_model ( )
2010-02-09 01:18:06 +03:00
2010-12-02 23:23:29 +03:00
# Only select 'copy from' option if using bridge/bond/vlan
2013-09-10 01:14:16 +04:00
enable_copy = ( itype in [ Interface . INTERFACE_TYPE_BRIDGE ,
Interface . INTERFACE_TYPE_BOND ,
Interface . INTERFACE_TYPE_VLAN ] )
2010-02-09 01:18:06 +03:00
2010-02-27 02:49:18 +03:00
# Set defaults if required
copy_model . clear ( )
active_rows = [ ]
inactive_rows = [ ]
for row in ifaces :
is_defined = row [ INTERFACE_ROW_IS_DEFINED ]
name = row [ INTERFACE_ROW_NAME ]
label = name
sensitive = False
iface_obj = None
if is_defined :
iface_obj = self . conn . get_interface ( name )
# We only want configured (aka interface API) interfaces with
# actually present <protocol> info
if not is_defined or not iface_obj :
label + = " (Not configured) "
elif not iface_obj . get_protocol_xml ( ) :
label + = " (No IP configuration) "
else :
sensitive = True
row = [ label , iface_obj , sensitive ]
if sensitive :
active_rows . append ( row )
else :
inactive_rows . append ( row )
# Make sure inactive rows are listed after active rows
for row in active_rows + inactive_rows :
copy_model . append ( row )
if len ( copy_model ) == 0 :
copy_model . append ( [ " No child interfaces selected. " , None , False ] )
if not enable_copy :
copy_model . clear ( )
copy_model . append ( [ " " , None , False ] )
# Find default model selection
have_valid_copy = bool ( active_rows )
# Re select previous selection, 0 otherwise
idx = 0
if not is_manual and current_name :
found_idx = 0
for row in copy_model :
if row [ 1 ] == current_name :
idx = found_idx
break
found_idx + = 1
copy_combo . set_active ( idx )
copy_radio . set_sensitive ( enable_copy )
if not self . ip_manually_changed :
if ( enable_copy and have_valid_copy ) :
copy_radio . set_active ( True )
else :
2012-02-02 02:26:46 +04:00
self . widget ( " ip-do-manual " ) . set_active ( True )
2010-02-27 02:49:18 +03:00
self . update_ip_desc ( )
2010-02-09 01:18:06 +03:00
def populate_interface_list ( self , itype ) :
2011-07-14 21:13:13 +04:00
iface_list = self . widget ( " interface-list " )
2010-02-09 01:18:06 +03:00
model = iface_list . get_model ( )
model . clear ( )
2013-09-10 01:14:16 +04:00
ifilter = [ Interface . INTERFACE_TYPE_ETHERNET ]
2010-02-09 01:18:06 +03:00
msg = None
2013-09-10 01:14:16 +04:00
if itype == Interface . INTERFACE_TYPE_BRIDGE :
ifilter . append ( Interface . INTERFACE_TYPE_VLAN )
ifilter . append ( Interface . INTERFACE_TYPE_BOND )
2010-02-09 01:18:06 +03:00
msg = _ ( " Choose interface(s) to bridge: " )
2013-09-10 01:14:16 +04:00
elif itype == Interface . INTERFACE_TYPE_VLAN :
2010-02-09 01:18:06 +03:00
msg = _ ( " Choose parent interface: " )
2013-09-10 01:14:16 +04:00
elif itype == Interface . INTERFACE_TYPE_BOND :
2010-02-09 01:18:06 +03:00
msg = _ ( " Choose interfaces to bond: " )
2013-09-10 01:14:16 +04:00
elif itype == Interface . INTERFACE_TYPE_ETHERNET :
2010-02-09 01:18:06 +03:00
msg = _ ( " Choose an unconfigured interface: " )
2011-07-14 21:13:13 +04:00
self . widget ( " interface-list-text " ) . set_text ( msg )
2010-02-09 01:18:06 +03:00
2014-01-18 05:25:08 +04:00
nodedevs = { }
2015-04-10 16:37:03 +03:00
for phys in self . conn . filter_nodedevs ( " net " ) :
2015-04-07 21:12:00 +03:00
nodedevs [ phys . xmlobj . interface ] = [ None ,
False , False , phys . xmlobj . interface ,
" ethernet " , False , True , None ,
phys . xmlobj . address ]
2010-02-09 01:18:06 +03:00
2014-01-18 05:25:08 +04:00
row_dict = { }
2014-06-03 01:17:47 +04:00
for iface in self . conn . list_interfaces ( ) :
name = iface . get_name ( )
2014-01-18 05:25:08 +04:00
key = iface . get_xmlobj ( )
2010-02-09 01:18:06 +03:00
iface_type = iface . get_type ( )
active = iface . is_active ( )
name = iface . get_name ( )
if iface_type not in ifilter :
continue
2013-09-10 01:14:16 +04:00
if itype == Interface . INTERFACE_TYPE_ETHERNET :
2014-01-18 05:25:08 +04:00
# When adding an ethernet definition, we only want
# 'unconfigured' interfaces, so stuff in nodedevs that's
# not in returned by the interface APIs
if name in nodedevs :
del ( nodedevs [ name ] )
2010-02-09 01:18:06 +03:00
# We only want 'unconfigured' interfaces here
continue
2014-01-18 05:25:08 +04:00
if name in nodedevs :
2010-02-09 01:18:06 +03:00
# Interface was listed via nodedev APIs
2014-01-18 05:25:08 +04:00
row = nodedevs . pop ( name )
2010-02-09 01:18:06 +03:00
row [ INTERFACE_ROW_KEY ] = key
row [ INTERFACE_ROW_IS_DEFINED ] = True
row [ INTERFACE_ROW_IS_ACTIVE ] = True
else :
# Brand new row
row = [ key , False , False ,
iface . get_name ( ) , iface . get_type ( ) , True ,
active , None , iface . get_mac ( ) ]
2014-01-18 05:25:08 +04:00
row_dict [ name ] = row
for name , row in nodedevs . items ( ) :
2014-02-14 18:27:56 +04:00
try :
key = Interface ( self . conn . get_backend ( ) )
key . type = Interface . INTERFACE_TYPE_ETHERNET
key . name = name
except Exception , e :
logging . debug ( " Error creating stub interface ' %s ' : %s " ,
name , e )
continue
2014-01-18 05:25:08 +04:00
row [ INTERFACE_ROW_KEY ] = key
row_dict [ name ] = row
2010-02-09 01:18:06 +03:00
for row in row_dict . values ( ) :
name = row [ INTERFACE_ROW_NAME ]
2014-01-27 02:42:24 +04:00
row [ INTERFACE_ROW_IN_USE_BY ] = self . iface_in_use_by ( self . conn ,
name )
2010-02-09 01:18:06 +03:00
for row in row_dict . values ( ) :
model . append ( row )
def get_default_name ( self ) :
itype = self . get_config_interface_type ( )
name = _ ( " No interface selected " )
2013-09-10 01:14:16 +04:00
if itype == Interface . INTERFACE_TYPE_BRIDGE :
2013-10-01 00:21:23 +04:00
name = Interface . find_free_name ( self . conn . get_backend ( ) , " br " )
2013-09-10 01:14:16 +04:00
elif itype == Interface . INTERFACE_TYPE_BOND :
2013-10-01 00:21:23 +04:00
name = Interface . find_free_name ( self . conn . get_backend ( ) , " bond " )
2010-02-09 01:18:06 +03:00
else :
ifaces = self . get_config_selected_interfaces ( )
if len ( ifaces ) > 0 :
iface = ifaces [ 0 ] [ INTERFACE_ROW_NAME ]
2013-09-10 01:14:16 +04:00
if itype == Interface . INTERFACE_TYPE_VLAN :
2014-01-27 03:15:50 +04:00
tag = uiutil . spin_get_helper ( self . widget ( " vlan-tag " ) )
2010-02-09 01:18:06 +03:00
name = " %s . %s " % ( iface , int ( tag ) )
2013-09-10 01:14:16 +04:00
elif itype == Interface . INTERFACE_TYPE_ETHERNET :
2010-02-09 01:18:06 +03:00
name = iface
return name
#########################
# get_config_* routines #
#########################
def get_config_interface_type ( self ) :
2015-05-20 00:17:53 +03:00
return uiutil . get_list_selection ( self . widget ( " interface-type " ) )
2010-02-09 01:18:06 +03:00
def set_interface_name ( self , name ) :
2013-09-09 19:02:34 +04:00
if self . widget ( " interface-name-entry " ) . get_visible ( ) :
2010-02-09 01:18:06 +03:00
widget = " interface-name-entry "
else :
widget = " interface-name-label "
2011-07-14 21:13:13 +04:00
self . widget ( widget ) . set_text ( name )
2010-02-09 01:18:06 +03:00
def get_config_interface_name ( self ) :
2013-09-09 19:02:34 +04:00
if self . widget ( " interface-name-entry " ) . get_visible ( ) :
2011-07-14 21:13:13 +04:00
return self . widget ( " interface-name-entry " ) . get_text ( )
2010-02-09 01:18:06 +03:00
else :
2011-07-14 21:13:13 +04:00
return self . widget ( " interface-name-label " ) . get_text ( )
2010-02-09 01:18:06 +03:00
def get_config_interface_startmode ( self ) :
2015-05-20 00:17:53 +03:00
return uiutil . get_list_selection ( self . widget ( " interface-startmode " ) )
2010-02-09 01:18:06 +03:00
def get_config_selected_interfaces ( self ) :
2011-07-14 21:13:13 +04:00
iface_list = self . widget ( " interface-list " )
2010-02-09 01:18:06 +03:00
model = iface_list . get_model ( )
ret = [ ]
for row in model :
active = row [ INTERFACE_ROW_SELECT ]
if active :
ret . append ( row )
return ret
def get_config_bridge_params ( self ) :
2012-02-02 02:26:46 +04:00
delay = self . widget ( " bridge-delay " ) . get_value ( )
stp = self . widget ( " bridge-stp " ) . get_active ( )
2010-02-09 01:18:06 +03:00
return [ delay , stp ]
2010-02-27 02:49:18 +03:00
def get_config_ipv6_address_selection ( self ) :
2012-02-02 02:26:46 +04:00
src = self . widget ( " ipv6-address-list " )
2010-02-27 02:49:18 +03:00
selection = src . get_selection ( )
ignore , treepath = selection . get_selected ( )
return treepath
def get_config_ipv6_addresses ( self ) :
2012-02-02 02:26:46 +04:00
src = self . widget ( " ipv6-address-list " )
2010-02-27 02:49:18 +03:00
model = src . get_model ( )
2013-04-12 00:32:00 +04:00
return [ x [ 0 ] for x in model ]
2010-02-27 02:49:18 +03:00
2010-02-09 01:18:06 +03:00
################
# UI Listeners #
################
2010-02-27 02:49:18 +03:00
def interface_item_toggled ( self , src , index , slave_list ) :
itype = self . get_config_interface_type ( )
active = src . get_active ( )
model = slave_list . get_model ( )
2013-09-10 01:14:16 +04:00
if itype in [ Interface . INTERFACE_TYPE_ETHERNET ,
Interface . INTERFACE_TYPE_VLAN ] :
2010-02-27 02:49:18 +03:00
# Deselect any selected rows
for row in model :
if row == model [ index ] :
continue
row [ INTERFACE_ROW_SELECT ] = False
# Toggle the clicked row
model [ index ] [ INTERFACE_ROW_SELECT ] = not active
self . update_interface_name ( )
self . update_ip_config ( )
2010-02-09 01:18:06 +03:00
def update_interface_name ( self , ignore1 = None , ignore2 = None ) :
itype = self . get_config_interface_type ( )
2013-09-10 01:14:16 +04:00
if itype not in [ Interface . INTERFACE_TYPE_VLAN ,
Interface . INTERFACE_TYPE_ETHERNET ] :
2010-02-09 01:18:06 +03:00
# The rest have editable name fields, so don't overwrite
return
name = self . get_default_name ( )
self . set_interface_name ( name )
def bond_monitor_mode_changed ( self , src ) :
2015-05-20 00:17:53 +03:00
value = uiutil . get_list_selection ( src , column = 1 )
2012-02-02 02:26:46 +04:00
bond_pages = self . widget ( " bond-pages " )
2010-02-09 01:18:06 +03:00
if value == " arpmon " :
page = BOND_PAGE_ARP
elif value == " miimon " :
page = BOND_PAGE_MII
else :
page = BOND_PAGE_DEFAULT
bond_pages . set_current_page ( page )
2010-02-27 02:49:18 +03:00
def ip_copy_interface_toggled ( self , src ) :
active = src . get_active ( )
2012-02-02 02:26:46 +04:00
self . widget ( " ip-copy-interface-box " ) . set_sensitive ( active )
self . widget ( " ip-do-manual-box " ) . set_sensitive ( not active )
2010-02-27 02:49:18 +03:00
def ipv4_mode_changed ( self , src ) :
static = ( src . get_active ( ) == IP_STATIC )
2012-02-02 02:26:46 +04:00
self . widget ( " ipv4-static-box " ) . set_sensitive ( static )
2010-02-27 02:49:18 +03:00
def ipv6_mode_changed ( self , src ) :
static = ( src . get_active ( ) == IP_STATIC )
2012-02-02 02:26:46 +04:00
self . widget ( " ipv6-static-box " ) . set_sensitive ( static )
2010-02-27 02:49:18 +03:00
2010-02-09 01:18:06 +03:00
def update_bridge_desc ( self ) :
delay , stp = self . get_config_bridge_params ( )
txt = " STP %s " % ( stp and " on " or " off " )
2013-06-29 18:07:11 +04:00
txt + = " , delay %.2f sec " % float ( delay )
2010-02-09 01:18:06 +03:00
2011-07-14 21:13:13 +04:00
self . widget ( " bridge-config-label " ) . set_text ( txt )
2010-02-09 01:18:06 +03:00
def update_bond_desc ( self ) :
2015-05-20 00:17:53 +03:00
mode = uiutil . get_list_selection ( self . widget ( " bond-mode " ) )
mon = uiutil . get_list_selection (
self . widget ( " bond-monitor-mode " ) , column = 1 )
2010-02-09 01:18:06 +03:00
txt = mode
if mon :
txt + = " , %s " % mon
2011-07-14 21:13:13 +04:00
self . widget ( " bond-config-label " ) . set_text ( txt )
2010-02-09 01:18:06 +03:00
2010-02-27 02:49:18 +03:00
def update_ip_desc ( self ) :
is_manual , name , ipv4 , ipv6 , ignore = self . get_config_ip_info ( )
label = " "
if is_manual :
if ipv4 :
label + = " IPv4: %s " % ( ipv4 . dhcp and " DHCP " or " Static " )
if ipv6 :
if label :
label + = " , "
label + = " IPv6: "
mode_label = " "
if ipv6 . autoconf and ipv6 . dhcp :
mode_label + = " Autoconf "
if ipv6 . dhcp :
mode_label + = " DHCP "
if not mode_label :
mode_label = " Static "
label + = mode_label
else :
if name :
label = " Copy configuration from ' %s ' " % name
if not label :
label = " No configuration "
2011-07-14 21:13:13 +04:00
self . widget ( " ip-config-label " ) . set_text ( label )
2010-02-27 02:49:18 +03:00
def get_config_ip_info ( self ) :
2013-09-09 19:02:34 +04:00
if not self . widget ( " ip-label " ) . get_visible ( ) :
2010-02-27 02:49:18 +03:00
return [ True , None , None , None , None ]
if not self . validate_ip_info ( ) :
return [ True , None , None , None , None ]
return self . build_ip_info ( )
def build_ip_info ( self ) :
def build_ip ( addr_str ) :
if not addr_str :
2014-03-30 03:47:22 +04:00
raise ValueError ( _ ( " Please enter an IP address " ) )
2010-02-27 02:49:18 +03:00
ret = addr_str . rsplit ( " / " , 1 )
2013-09-10 01:14:16 +04:00
address = ret [ 0 ]
prefix = None
2010-02-27 02:49:18 +03:00
if len ( ret ) > 1 :
2013-09-10 01:14:16 +04:00
prefix = ret [ 1 ]
return address , prefix
2010-02-27 02:49:18 +03:00
2012-02-02 02:26:46 +04:00
is_manual = self . widget ( " ip-do-manual " ) . get_active ( )
2010-02-27 02:49:18 +03:00
2015-05-20 00:17:53 +03:00
copy_row = uiutil . get_list_selected_row (
self . widget ( " ip-copy-interface-combo " ) )
2010-02-27 02:49:18 +03:00
2012-02-02 02:26:46 +04:00
v4_mode = self . widget ( " ipv4-mode " ) . get_active ( )
v4_addr = self . widget ( " ipv4-address " ) . get_text ( )
v4_gate = self . widget ( " ipv4-gateway " ) . get_text ( )
2010-02-27 02:49:18 +03:00
2012-02-02 02:26:46 +04:00
v6_mode = self . widget ( " ipv6-mode " ) . get_active ( )
v6_auto = self . widget ( " ipv6-autoconf " ) . get_active ( )
v6_gate = self . widget ( " ipv6-gateway " ) . get_text ( )
2010-02-27 02:49:18 +03:00
v6_addrlist = self . get_config_ipv6_addresses ( )
copy_name = None
proto_xml = None
ipv4 = None
ipv6 = None
if not is_manual :
2014-09-21 23:02:27 +04:00
copy_vmmiface = copy_row [ 1 ]
copy_cancopy = copy_row [ 2 ]
if copy_vmmiface and copy_cancopy :
copy_name = copy_vmmiface . get_name ( )
# We always want the inactive protocol XML, which
# will list the on disk config, not the run time config,
# which doesn't list DHCP
proto_xml = copy_vmmiface . get_protocol_xml ( inactive = True )
2010-02-27 02:49:18 +03:00
else :
# Build IPv4 Info
if v4_mode != IP_NONE :
2013-09-10 01:14:16 +04:00
ipv4 = InterfaceProtocol ( self . conn . get_backend ( ) )
ipv4 . family = " ipv4 "
2010-02-27 02:49:18 +03:00
ipv4 . dhcp = bool ( v4_mode == IP_DHCP )
if not ipv4 . dhcp :
2013-09-10 01:14:16 +04:00
addr , prefix = build_ip ( v4_addr )
if addr :
ipv4 . add_ip ( addr , prefix )
2010-02-27 02:49:18 +03:00
if v4_gate :
ipv4 . gateway = v4_gate
# Build IPv6 Info
if v6_mode != IP_NONE :
2013-09-10 01:14:16 +04:00
ipv6 = InterfaceProtocol ( self . conn . get_backend ( ) )
ipv6 . family = " ipv6 "
2010-02-27 02:49:18 +03:00
ipv6 . dhcp = bool ( v6_mode == IP_DHCP )
ipv6 . autoconf = bool ( v6_auto )
if not ipv6 . dhcp :
if v6_gate :
ipv6 . gateway = v6_gate
2014-03-27 18:01:21 +04:00
for v6_addr in v6_addrlist :
addr , prefix = build_ip ( v6_addr )
if addr :
ipv6 . add_ip ( addr , prefix )
2010-02-27 02:49:18 +03:00
return [ is_manual , copy_name , ipv4 , ipv6 , proto_xml ]
def ipv6_address_add ( self , src ) :
2012-02-02 02:26:46 +04:00
src = self . widget ( " ipv6-address-list " )
2010-02-27 02:49:18 +03:00
model = src . get_model ( )
model . append ( [ " Insert address/prefix " ] )
def ipv6_address_remove ( self , src ) :
treepath = self . get_config_ipv6_address_selection ( )
2012-02-02 02:26:46 +04:00
src = self . widget ( " ipv6-address-list " )
2010-02-27 02:49:18 +03:00
model = src . get_model ( )
2012-11-08 17:15:02 +04:00
if treepath is not None :
2010-02-27 02:49:18 +03:00
del ( model [ treepath ] )
2013-08-18 19:11:15 +04:00
def ipv6_address_edited ( self , src , path , new_text ) :
2012-02-02 02:26:46 +04:00
src = self . widget ( " ipv6-address-list " )
2010-02-27 02:49:18 +03:00
model = src . get_model ( )
row = model [ path ]
row [ 0 ] = new_text
def ipv6_address_selected ( self , src = None ) :
treepath = self . get_config_ipv6_address_selection ( )
2012-11-08 17:15:02 +04:00
has_selection = ( treepath is not None )
2010-02-27 02:49:18 +03:00
2012-02-02 02:26:46 +04:00
self . widget ( " ipv6-address-remove " ) . set_sensitive ( has_selection )
2010-02-27 02:49:18 +03:00
2010-02-09 01:18:06 +03:00
#######################
# Notebook navigation #
#######################
def back ( self , src ) :
2011-07-14 21:13:13 +04:00
notebook = self . widget ( " pages " )
2010-02-09 01:18:06 +03:00
curpage = notebook . get_current_page ( )
notebook . set_current_page ( curpage - 1 )
def forward ( self , ignore ) :
2011-07-14 21:13:13 +04:00
notebook = self . widget ( " pages " )
2010-02-09 01:18:06 +03:00
curpage = notebook . get_current_page ( )
2012-11-08 17:15:02 +04:00
if self . validate ( notebook . get_current_page ( ) ) is not True :
2010-02-09 01:18:06 +03:00
return
2011-07-14 21:13:13 +04:00
self . widget ( " forward " ) . grab_focus ( )
2010-02-09 01:18:06 +03:00
notebook . set_current_page ( curpage + 1 )
def page_changed ( self , ignore1 , ignore2 , pagenum ) :
next_page = pagenum + 1
# Update page number
page_lbl = ( " <span color= ' #59B0E2 ' > %s </span> " %
_ ( " Step %(current_page)d of %(max_page)d " ) %
2010-12-10 19:47:07 +03:00
{ ' current_page ' : next_page , ' max_page ' : PAGE_DETAILS + 1 } )
2011-07-14 21:13:13 +04:00
self . widget ( " header-pagenum " ) . set_markup ( page_lbl )
2010-02-09 01:18:06 +03:00
if pagenum == 0 :
2011-07-14 21:13:13 +04:00
self . widget ( " back " ) . set_sensitive ( False )
2010-02-09 01:18:06 +03:00
else :
2011-07-14 21:13:13 +04:00
self . widget ( " back " ) . set_sensitive ( True )
2010-02-09 01:18:06 +03:00
if pagenum == PAGE_DETAILS :
self . populate_details_page ( )
2011-07-14 21:13:13 +04:00
self . widget ( " forward " ) . hide ( )
self . widget ( " finish " ) . show ( )
self . widget ( " finish " ) . grab_focus ( )
2010-02-09 01:18:06 +03:00
else :
2011-07-14 21:13:13 +04:00
self . widget ( " forward " ) . show ( )
self . widget ( " finish " ) . hide ( )
2010-02-09 01:18:06 +03:00
def validate ( self , pagenum ) :
try :
if pagenum == PAGE_TYPE :
# Nothing to validate
return True
elif pagenum == PAGE_DETAILS :
return self . validate_details_page ( )
except Exception , e :
self . err . show_err ( _ ( " Uncaught error validating install "
2011-04-06 19:22:03 +04:00
" parameters: %s " ) % str ( e ) )
2010-02-09 01:18:06 +03:00
return
def validate_details_page ( self ) :
itype = self . get_config_interface_type ( )
name = self . get_config_interface_name ( )
start = self . get_config_interface_startmode ( )
ifaces = self . get_config_selected_interfaces ( )
if not name :
return self . err . val_err ( _ ( " An interface name is required. " ) )
2013-09-10 01:14:16 +04:00
if ( itype != Interface . INTERFACE_TYPE_BRIDGE and
2010-02-09 01:18:06 +03:00
len ( ifaces ) == 0 ) :
return self . err . val_err ( _ ( " An interface must be selected " ) )
try :
2013-09-10 01:14:16 +04:00
iobj = Interface ( self . conn . get_backend ( ) )
iobj . type = itype
iobj . name = name
2010-02-09 01:18:06 +03:00
iobj . start_mode = start
check_conflict = False
# Pull info from selected interfaces
2013-09-10 01:14:16 +04:00
if ( itype == Interface . INTERFACE_TYPE_BRIDGE or
itype == Interface . INTERFACE_TYPE_BOND ) :
for row in ifaces :
2014-09-21 23:04:16 +04:00
if row [ INTERFACE_ROW_IS_DEFINED ] :
vmmiface = self . conn . get_interface (
row [ INTERFACE_ROW_NAME ] )
# Use the inactive XML, which drops a bunch
# elements that might cause netcf to choke on
# for a sub-interface
2015-04-07 21:53:28 +03:00
xml = vmmiface . get_xmlobj (
inactive = True ) . get_xml_config ( )
2014-09-21 23:04:16 +04:00
else :
xml = row [ INTERFACE_ROW_KEY ] . get_xml_config ( )
child = Interface ( self . conn . get_backend ( ) , parsexml = xml )
2013-09-10 01:14:16 +04:00
iobj . add_interface ( child )
2010-02-09 01:18:06 +03:00
check_conflict = True
2013-09-10 01:14:16 +04:00
elif itype == Interface . INTERFACE_TYPE_VLAN :
iobj . parent_interface = ifaces [ 0 ] [ INTERFACE_ROW_NAME ]
2010-02-09 01:18:06 +03:00
2013-09-10 01:14:16 +04:00
elif itype == Interface . INTERFACE_TYPE_ETHERNET :
2010-02-09 01:18:06 +03:00
iobj . macaddr = ifaces [ 0 ] [ INTERFACE_ROW_MAC ]
# Warn about defined interfaces
defined_ifaces = " "
if check_conflict :
for row in ifaces :
if not row [ INTERFACE_ROW_IS_DEFINED ] :
continue
if defined_ifaces :
defined_ifaces + = " , "
defined_ifaces + = row [ INTERFACE_ROW_NAME ]
if defined_ifaces :
ret = self . err . yes_no (
_ ( " The following interface(s) are already "
" configured: \n \n %s \n \n Using these may overwrite "
" their existing configuration. Are you sure you "
" want to use the selected interface(s)? " ) %
defined_ifaces )
if not ret :
return ret
2010-02-27 02:49:18 +03:00
# Validate IP info (get_config validates for us)
( is_manual , copy_name , ipv4 ,
ipv6 , proto_xml ) = self . get_config_ip_info ( )
if is_manual :
if ipv4 :
2013-09-10 01:14:16 +04:00
iobj . add_protocol ( ipv4 )
2010-02-27 02:49:18 +03:00
if ipv6 :
2013-09-10 01:14:16 +04:00
iobj . add_protocol ( ipv6 )
2010-02-27 02:49:18 +03:00
else :
2013-09-10 01:14:16 +04:00
for proto in proto_xml :
iobj . add_protocol ( InterfaceProtocol (
self . conn . get_backend ( ) ,
parsexml = proto . get_xml_config ( ) ) )
2010-02-27 02:49:18 +03:00
2013-09-10 01:14:16 +04:00
if itype == Interface . INTERFACE_TYPE_BRIDGE :
2010-02-09 01:18:06 +03:00
ret = self . validate_bridge ( iobj , ifaces )
2013-09-10 01:14:16 +04:00
elif itype == Interface . INTERFACE_TYPE_BOND :
2010-02-09 01:18:06 +03:00
ret = self . validate_bond ( iobj , ifaces )
2013-09-10 01:14:16 +04:00
elif itype == Interface . INTERFACE_TYPE_VLAN :
2010-02-09 01:18:06 +03:00
ret = self . validate_vlan ( iobj , ifaces )
2013-09-10 01:14:16 +04:00
elif itype == Interface . INTERFACE_TYPE_ETHERNET :
2010-02-09 01:18:06 +03:00
ret = self . validate_ethernet ( iobj , ifaces )
if not ret :
return ret
iobj . get_xml_config ( )
2013-09-10 01:14:16 +04:00
iobj . validate ( )
2010-02-09 01:18:06 +03:00
self . interface = iobj
except Exception , e :
2011-08-30 22:50:50 +04:00
return self . err . val_err (
_ ( " Error setting interface parameters. " ) , e )
2010-02-09 01:18:06 +03:00
return True
def validate_bridge ( self , iobj , ifaces ) :
2012-02-02 02:26:46 +04:00
delay = self . widget ( " bridge-delay " ) . get_value ( )
stp = self . widget ( " bridge-stp " ) . get_active ( )
2010-02-09 01:18:06 +03:00
iobj . stp = stp
2013-06-29 18:07:11 +04:00
iobj . delay = float ( delay )
2010-02-09 01:18:06 +03:00
return True
def validate_bond ( self , iobj , ifaces ) :
2015-05-20 00:17:53 +03:00
mode = uiutil . get_list_selection ( self . widget ( " bond-mode " ) , column = 1 )
mon = uiutil . get_list_selection (
self . widget ( " bond-monitor-mode " ) , column = 1 )
arp_val = uiutil . get_list_selection ( self . widget ( " arp-validate " ) )
mii_car = uiutil . get_list_selection ( self . widget ( " mii-carrier " ) )
2010-02-09 01:18:06 +03:00
# ARP params
2012-02-02 02:26:46 +04:00
arp_int = self . widget ( " arp-interval " ) . get_value ( )
arp_tar = self . widget ( " arp-target " ) . get_text ( )
2010-02-09 01:18:06 +03:00
# MII params
2012-02-02 02:26:46 +04:00
mii_freq = self . widget ( " mii-frequency " ) . get_value ( )
mii_up = self . widget ( " mii-updelay " ) . get_value ( )
mii_down = self . widget ( " mii-downdelay " ) . get_value ( )
2010-02-09 01:18:06 +03:00
iobj . bond_mode = mode
if not mon :
# No monitor params, just return
return True
if mon == " arpmon " :
iobj . arp_validate_mode = arp_val
iobj . arp_interval = int ( arp_int )
iobj . arp_target = arp_tar or None
elif mon == " miimon " :
iobj . mii_carrier_mode = mii_car
iobj . mii_frequency = int ( mii_freq )
iobj . mii_updelay = int ( mii_up )
iobj . mii_downdelay = int ( mii_down )
return True
def validate_vlan ( self , iobj , ifaces ) :
2014-01-27 03:15:50 +04:00
idx = uiutil . spin_get_helper ( self . widget ( " vlan-tag " ) )
2010-02-09 01:18:06 +03:00
iobj . tag = int ( idx )
return True
def validate_ethernet ( self , iobj , ifaces ) :
return True
2010-02-27 02:49:18 +03:00
def validate_ip_info ( self ) :
try :
self . build_ip_info ( )
except Exception , e :
self . err . show_err ( _ ( " Error validating IP configuration: %s " ) %
2011-04-06 19:22:03 +04:00
str ( e ) )
2010-02-27 02:49:18 +03:00
return False
return True
2010-02-09 01:18:06 +03:00
####################
# Dialog callbacks #
####################
def bridge_config_finish ( self , ignore1 = None , ignore2 = None ) :
self . update_bridge_desc ( )
self . bridge_config . hide ( )
return 1
def bond_config_finish ( self , ignore1 = None , ignore2 = None ) :
self . update_bond_desc ( )
self . bond_config . hide ( )
return 1
2010-02-27 02:49:18 +03:00
def ip_config_finish ( self , ignore1 = None , ignore2 = None ) :
if not self . validate_ip_info ( ) :
return
self . update_ip_desc ( )
self . ip_config . hide ( )
return 1
2010-02-09 01:18:06 +03:00
#####################
# Creation routines #
#####################
2013-09-07 04:59:01 +04:00
def _finish_cb ( self , error , details ) :
self . topwin . set_sensitive ( True )
self . topwin . get_window ( ) . set_cursor (
Gdk . Cursor . new ( Gdk . CursorType . TOP_LEFT_ARROW ) )
2010-02-09 01:18:06 +03:00
2013-09-07 04:59:01 +04:00
if error :
error = _ ( " Error creating interface: ' %s ' " ) % error
self . err . show_err ( error ,
details = details )
else :
self . conn . schedule_priority_tick ( polliface = True )
self . close ( )
def finish ( self , src ) :
2010-02-09 01:18:06 +03:00
# Validate the final page
2011-07-14 21:13:13 +04:00
page = self . widget ( " pages " ) . get_current_page ( )
2012-11-08 17:15:02 +04:00
if self . validate ( page ) is not True :
2010-02-09 01:18:06 +03:00
return False
2011-07-14 21:13:13 +04:00
activate = self . widget ( " interface-activate " ) . get_active ( )
2010-02-09 01:18:06 +03:00
# Start the install
self . topwin . set_sensitive ( False )
2013-09-07 04:59:01 +04:00
self . topwin . get_window ( ) . set_cursor (
Gdk . Cursor . new ( Gdk . CursorType . WATCH ) )
2010-02-09 01:18:06 +03:00
2010-12-09 20:37:48 +03:00
progWin = vmmAsyncJob ( self . do_install , [ activate ] ,
2013-09-07 04:59:01 +04:00
self . _finish_cb , [ ] ,
2011-04-14 16:47:42 +04:00
_ ( " Creating virtual interface " ) ,
_ ( " The virtual interface is now being created. " ) ,
self . topwin )
2013-09-07 04:59:01 +04:00
progWin . run ( )
2010-02-09 01:18:06 +03:00
2010-12-10 17:57:42 +03:00
def do_install ( self , asyncjob , activate ) :
2012-02-10 19:24:43 +04:00
meter = asyncjob . get_meter ( )
2010-12-10 17:57:42 +03:00
self . interface . install ( meter , create = activate )
logging . debug ( " Install completed " )