2007-03-30 17:03:32 +04:00
#
2013-05-22 16:59:27 +04:00
# Copyright (C) 2006-2007, 2013 Red Hat, Inc.
2007-03-30 17:03:32 +04:00
# Copyright (C) 2006 Hugh O. Brock <hbrock@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-30 17:03:32 +04:00
#
import logging
2012-05-14 17:24:56 +04:00
from gi . repository import Gtk
from gi . repository import Gdk
2011-04-18 20:39:53 +04:00
2016-04-18 23:42:12 +03:00
import ipaddr
2013-09-23 21:21:35 +04:00
from virtinst import Network
2014-09-13 00:10:45 +04:00
from . import uiutil
from . asyncjob import vmmAsyncJob
from . baseclass import vmmGObjectUI
2007-03-30 17:03:32 +04:00
2013-09-23 17:41:01 +04:00
( PAGE_NAME ,
PAGE_IPV4 ,
PAGE_IPV6 ,
PAGE_MISC ) = range ( 4 )
2014-06-27 07:10:54 +04:00
PAGE_MAX = PAGE_MISC
2013-09-23 17:41:01 +04:00
_green = Gdk . Color . parse ( " #c0ffc0 " ) [ 1 ]
_red = Gdk . Color . parse ( " #ffc0c0 " ) [ 1 ]
_black = Gdk . Color . parse ( " #000000 " ) [ 1 ]
_white = Gdk . Color . parse ( " #f0f0f0 " ) [ 1 ]
def _make_ipaddr ( addrstr ) :
if addrstr is None :
return None
try :
return ipaddr . IPNetwork ( addrstr )
except :
return None
2007-03-30 17:03:32 +04:00
2010-12-09 01:26:19 +03:00
class vmmCreateNetwork ( vmmGObjectUI ) :
def __init__ ( self , conn ) :
2013-09-23 00:10:16 +04:00
vmmGObjectUI . __init__ ( self , " createnet.ui " , " vmm-create-net " )
2007-03-30 17:03:32 +04:00
self . conn = conn
2010-11-30 22:33:21 +03:00
2013-02-16 22:31:46 +04:00
self . builder . connect_signals ( {
2007-03-30 17:03:32 +04:00
" on_create_pages_switch_page " : self . page_changed ,
" on_create_cancel_clicked " : self . close ,
" on_vmm_create_delete_event " : self . close ,
" on_create_forward_clicked " : self . forward ,
2011-07-13 04:31:46 +04:00
" on_create_back_clicked " : self . back ,
2007-03-30 17:03:32 +04:00
" on_create_finish_clicked " : self . finish ,
2009-12-15 00:26:46 +03:00
" on_net_name_activate " : self . forward ,
2007-03-30 17:03:32 +04:00
" on_net_forward_toggled " : self . change_forward_type ,
2013-05-14 20:15:02 +04:00
" on_net-ipv4-enable_toggled " : self . change_ipv4_enable ,
" on_net-ipv4-network_changed " : self . change_ipv4_network ,
2013-03-29 22:38:29 +04:00
" on_net-dhcpv4-enable_toggled " : self . change_dhcpv4_enable ,
2013-05-14 20:15:02 +04:00
" on_net-dhcpv4-start_changed " : self . change_dhcpv4_start ,
" on_net-dhcpv4-end_changed " : self . change_dhcpv4_end ,
" on_net-ipv6-enable_toggled " : self . change_ipv6_enable ,
" on_net-ipv6-network_changed " : self . change_ipv6_network ,
2013-03-29 22:38:29 +04:00
" on_net-dhcpv6-enable_toggled " : self . change_dhcpv6_enable ,
2013-05-14 20:15:02 +04:00
" on_net-dhcpv6-start_changed " : self . change_dhcpv6_start ,
" on_net-dhcpv6-end_changed " : self . change_dhcpv6_end ,
" on_net-routev4-enable_toggled " : self . change_routev4_enable ,
" on_net-routev4-network_changed " : self . change_routev4_network ,
" on_net-routev4-gateway_changed " : self . change_routev4_gateway ,
" on_net-routev6-enable_toggled " : self . change_routev6_enable ,
" on_net-routev6-network_changed " : self . change_routev6_network ,
" on_net-routev6-gateway_changed " : self . change_routev6_gateway ,
2011-07-13 04:31:46 +04:00
} )
2011-04-18 19:25:28 +04:00
self . bind_escape_key_close ( )
2007-03-30 17:03:32 +04:00
self . set_initial_state ( )
2013-09-23 17:41:01 +04:00
####################
# Standard methods #
####################
2011-04-14 16:47:42 +04:00
def show ( self , parent ) :
2012-02-01 03:16:54 +04:00
logging . debug ( " Showing new network wizard " )
2007-03-30 17:03:32 +04:00
self . reset_state ( )
2011-04-14 16:47:42 +04:00
self . topwin . set_transient_for ( parent )
2007-03-30 17:03:32 +04:00
self . topwin . present ( )
2011-04-13 17:27:02 +04:00
def close ( self , ignore1 = None , ignore2 = None ) :
2012-02-01 03:16:54 +04:00
logging . debug ( " Closing new network wizard " )
2011-04-13 17:27:02 +04:00
self . topwin . hide ( )
return 1
2011-07-24 05:16:54 +04:00
def _cleanup ( self ) :
2011-04-13 17:27:02 +04:00
self . conn = None
2007-03-30 17:03:32 +04:00
def set_initial_state ( self ) :
2011-07-14 21:13:13 +04:00
notebook = self . widget ( " create-pages " )
2007-03-30 17:03:32 +04:00
notebook . set_show_tabs ( False )
2013-09-27 21:36:22 +04:00
blue = Gdk . Color . parse ( " #0072A8 " ) [ 1 ]
self . widget ( " header " ) . modify_bg ( Gtk . StateType . NORMAL , blue )
2007-03-30 17:03:32 +04:00
2009-12-01 19:49:08 +03:00
# [ label, dev name ]
2013-09-23 17:41:01 +04:00
fw_list = self . widget ( " net-forward " )
2012-05-14 17:24:56 +04:00
fw_model = Gtk . ListStore ( str , str )
2007-03-30 17:03:32 +04:00
fw_list . set_model ( fw_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( fw_list , 0 )
2009-12-01 19:49:08 +03:00
# [ label, mode ]
2013-09-23 17:41:01 +04:00
mode_list = self . widget ( " net-forward-mode " )
2012-05-14 17:24:56 +04:00
mode_model = Gtk . ListStore ( str , str )
2009-12-01 19:49:08 +03:00
mode_list . set_model ( mode_model )
2015-04-10 20:04:02 +03:00
uiutil . init_combo_text_column ( mode_list , 0 )
2009-12-01 19:49:08 +03:00
mode_model . append ( [ _ ( " NAT " ) , " nat " ] )
mode_model . append ( [ _ ( " Routed " ) , " route " ] )
2007-03-30 17:03:32 +04:00
def reset_state ( self ) :
2011-07-14 21:13:13 +04:00
notebook = self . widget ( " create-pages " )
2007-03-30 17:03:32 +04:00
notebook . set_current_page ( 0 )
2011-07-13 04:31:46 +04:00
self . page_changed ( None , None , 0 )
2007-03-30 17:03:32 +04:00
2011-07-14 21:13:13 +04:00
self . widget ( " net-name " ) . set_text ( " " )
2013-03-29 22:38:29 +04:00
self . widget ( " net-domain-name " ) . set_text ( " " )
2013-09-23 17:41:01 +04:00
2013-03-29 22:38:29 +04:00
self . widget ( " net-ipv4-enable " ) . set_active ( True )
self . widget ( " net-ipv4-network " ) . set_text ( " 192.168.100.0/24 " )
self . widget ( " net-dhcpv4-enable " ) . set_active ( True )
self . widget ( " net-dhcpv4-start " ) . set_text ( " 192.168.100.128 " )
self . widget ( " net-dhcpv4-end " ) . set_text ( " 192.168.100.254 " )
2013-09-23 17:41:01 +04:00
self . widget ( " net-routev4-enable " ) . set_active ( False )
self . widget ( " net-routev4-enable " ) . toggled ( )
self . widget ( " net-routev4-network " ) . set_text ( " " )
self . widget ( " net-routev4-gateway " ) . set_text ( " " )
2013-03-29 22:38:29 +04:00
self . widget ( " net-ipv6-enable " ) . set_active ( False )
2013-09-23 17:41:01 +04:00
self . widget ( " net-ipv6-enable " ) . toggled ( )
2013-03-29 22:38:29 +04:00
self . widget ( " net-ipv6-network " ) . set_text ( " " )
self . widget ( " net-dhcpv6-enable " ) . set_active ( False )
2013-09-23 17:41:01 +04:00
self . widget ( " net-dhcpv6-enable " ) . toggled ( )
2013-03-29 22:38:29 +04:00
self . widget ( " net-dhcpv6-start " ) . set_text ( " " )
self . widget ( " net-dhcpv6-end " ) . set_text ( " " )
2013-09-23 17:41:01 +04:00
self . widget ( " net-routev6-enable " ) . set_active ( False )
self . widget ( " net-routev6-enable " ) . toggled ( )
self . widget ( " net-routev6-network " ) . set_text ( " " )
self . widget ( " net-routev6-gateway " ) . set_text ( " " )
self . widget ( " net-enable-ipv6-networking " ) . set_active ( False )
2007-03-30 17:03:32 +04:00
2013-08-06 01:20:05 +04:00
fw_model = self . widget ( " net-forward " ) . get_model ( )
fw_model . clear ( )
fw_model . append ( [ _ ( " Any physical device " ) , None ] )
2014-06-18 01:04:49 +04:00
devnames = [ ]
2015-04-10 16:37:03 +03:00
for nodedev in self . conn . filter_nodedevs ( " net " ) :
2015-04-07 21:12:00 +03:00
devnames . append ( nodedev . xmlobj . interface )
2014-06-18 01:04:49 +04:00
for iface in self . conn . list_interfaces ( ) :
2014-06-24 11:44:04 +04:00
if iface . get_name ( ) not in devnames :
devnames . append ( iface . get_name ( ) )
2014-06-18 01:04:49 +04:00
for name in devnames :
fw_model . append ( [ _ ( " Physical device %s " ) % name , name ] )
2013-08-06 01:20:05 +04:00
2011-07-14 21:13:13 +04:00
self . widget ( " net-forward " ) . set_active ( 0 )
self . widget ( " net-forward-mode " ) . set_active ( 0 )
2013-09-23 17:41:01 +04:00
self . widget ( " net-forward-none " ) . set_active ( True )
2007-03-30 17:03:32 +04:00
2009-12-01 19:49:08 +03:00
2013-09-23 17:41:01 +04:00
##################
# UI get helpers #
##################
2007-03-30 17:03:32 +04:00
2013-03-29 22:38:29 +04:00
def get_config_ipv4_enable ( self ) :
return self . widget ( " net-ipv4-enable " ) . get_active ( )
def get_config_ipv6_enable ( self ) :
return self . widget ( " net-ipv6-enable " ) . get_active ( )
def get_config_dhcpv4_enable ( self ) :
return self . widget ( " net-dhcpv4-enable " ) . get_active ( )
def get_config_dhcpv6_enable ( self ) :
return self . widget ( " net-dhcpv6-enable " ) . get_active ( )
2013-05-14 20:15:02 +04:00
def get_config_routev4_enable ( self ) :
return self . widget ( " net-routev4-enable " ) . get_active ( )
def get_config_routev6_enable ( self ) :
return self . widget ( " net-routev6-enable " ) . get_active ( )
2013-09-23 17:41:01 +04:00
def _get_network_helper ( self , widgetname ) :
widget = self . widget ( widgetname )
if not widget . is_visible ( ) or not widget . is_sensitive ( ) :
return None
return _make_ipaddr ( widget . get_text ( ) )
2009-09-23 18:07:22 +04:00
2013-09-23 17:41:01 +04:00
def get_config_ip4 ( self ) :
return self . _get_network_helper ( " net-ipv4-network " )
def get_config_dhcpv4_start ( self ) :
return self . _get_network_helper ( " net-dhcpv4-start " )
def get_config_dhcpv4_end ( self ) :
return self . _get_network_helper ( " net-dhcpv4-end " )
def get_config_ip6 ( self ) :
return self . _get_network_helper ( " net-ipv6-network " )
def get_config_dhcpv6_start ( self ) :
return self . _get_network_helper ( " net-dhcpv6-start " )
def get_config_dhcpv6_end ( self ) :
return self . _get_network_helper ( " net-dhcpv6-end " )
2013-05-14 20:15:02 +04:00
2013-09-23 17:41:01 +04:00
def get_config_forwarding ( self ) :
if self . widget ( " net-forward-none " ) . get_active ( ) :
return [ None , None ]
2013-05-14 20:15:02 +04:00
2015-05-20 00:17:53 +03:00
name = uiutil . get_list_selection ( self . widget ( " net-forward " ) , column = 1 )
mode = uiutil . get_list_selection (
self . widget ( " net-forward-mode " ) , column = 1 )
2013-09-23 17:41:01 +04:00
return [ name , mode ]
2007-03-30 17:03:32 +04:00
2013-09-23 17:41:01 +04:00
def get_config_routev4_network ( self ) :
if not self . get_config_routev4_enable ( ) :
return None
return self . widget ( " net-routev4-network " ) . get_text ( )
def get_config_routev4_gateway ( self ) :
if not self . get_config_routev4_enable ( ) :
return None
return self . widget ( " net-routev4-gateway " ) . get_text ( )
def get_config_routev6_network ( self ) :
if not self . get_config_routev6_enable ( ) :
return None
return self . widget ( " net-routev6-network " ) . get_text ( )
def get_config_routev6_gateway ( self ) :
if not self . get_config_routev6_enable ( ) :
return None
return self . widget ( " net-routev6-gateway " ) . get_text ( )
2007-03-30 17:03:32 +04:00
2009-12-11 21:45:53 +03:00
2013-09-23 17:41:01 +04:00
###################
# Page validation #
###################
2007-03-30 17:03:32 +04:00
2011-07-13 04:31:46 +04:00
def validate_name ( self ) :
2014-01-18 03:40:30 +04:00
try :
net = self . _build_xmlstub ( )
net . name = self . widget ( " net-name " ) . get_text ( )
except Exception , e :
return self . err . val_err ( _ ( " Invalid network name " ) , str ( e ) )
2011-07-13 04:31:46 +04:00
return True
def validate_ipv4 ( self ) :
2013-03-29 22:38:29 +04:00
if not self . get_config_ipv4_enable ( ) :
return True
2011-07-13 04:31:46 +04:00
ip = self . get_config_ip4 ( )
if ip is None :
return self . err . val_err ( _ ( " Invalid Network Address " ) ,
_ ( " The network address could not be understood " ) )
2013-03-29 22:38:28 +04:00
if ip . version != 4 :
2011-07-13 04:31:46 +04:00
return self . err . val_err ( _ ( " Invalid Network Address " ) ,
_ ( " The network must be an IPv4 address " ) )
2014-06-11 05:51:48 +04:00
if ip . numhosts < 8 :
2011-07-13 04:31:46 +04:00
return self . err . val_err ( _ ( " Invalid Network Address " ) ,
2014-06-11 05:51:48 +04:00
_ ( " The network must address at least 8 addresses. " ) )
2011-07-13 04:31:46 +04:00
2014-05-20 03:23:46 +04:00
if ip . prefixlen < 15 :
return self . err . val_err ( _ ( " Invalid Network Address " ) ,
_ ( " The network prefix must be >= 15 " ) )
2013-03-29 22:38:28 +04:00
if not ip . is_private :
2011-07-13 04:31:46 +04:00
res = self . err . yes_no ( _ ( " Check Network Address " ) ,
_ ( " The network should normally use a private IPv4 "
" address. Use this non-private address anyway? " ) )
if not res :
return False
2013-03-29 22:38:29 +04:00
enabled = self . get_config_dhcpv4_enable ( )
if enabled :
start = self . get_config_dhcpv4_start ( )
end = self . get_config_dhcpv4_end ( )
2013-05-14 20:15:02 +04:00
if start is None :
2013-03-29 22:38:29 +04:00
return self . err . val_err ( _ ( " Invalid DHCP Address " ) ,
2013-09-23 17:41:01 +04:00
_ ( " The DHCP start address could not be understood " ) )
2013-05-14 20:15:02 +04:00
if end is None :
2013-03-29 22:38:29 +04:00
return self . err . val_err ( _ ( " Invalid DHCP Address " ) ,
2013-09-23 17:41:01 +04:00
_ ( " The DHCP end address could not be understood " ) )
2013-05-14 20:15:02 +04:00
if not ip . overlaps ( start ) :
2013-03-29 22:38:29 +04:00
return self . err . val_err ( _ ( " Invalid DHCP Address " ) ,
2013-09-23 17:41:01 +04:00
( _ ( " The DHCP start address is not with the network %s " ) %
( str ( ip ) ) ) )
2013-05-14 20:15:02 +04:00
if not ip . overlaps ( end ) :
2013-03-29 22:38:29 +04:00
return self . err . val_err ( _ ( " Invalid DHCP Address " ) ,
2013-09-23 17:41:01 +04:00
( _ ( " The DHCP end address is not with the network %s " ) %
( str ( ip ) ) ) )
2013-03-29 22:38:29 +04:00
2013-05-14 20:15:02 +04:00
enabled = self . get_config_routev4_enable ( )
if enabled :
ntwk = self . get_config_routev4_network ( )
ntwkbad = False
gway = self . get_config_routev4_gateway ( )
gwaybad = False
if ntwk is None or gway is None :
return True
if ntwk == " " and gway == " " :
return True
2013-09-23 17:41:01 +04:00
naddr = _make_ipaddr ( ntwk )
2013-05-14 20:15:02 +04:00
if naddr is None :
ntwkbad = True
else :
if naddr . version != 4 :
ntwkbad = True
if naddr . prefixlen > 28 :
ntwkbad = True
2013-09-23 17:41:01 +04:00
gaddr = _make_ipaddr ( gway )
2013-05-14 20:15:02 +04:00
if gaddr is None :
gwaybad = True
else :
if gaddr . version != 4 :
gwaybad = True
if gaddr . prefixlen != 32 :
gwaybad = True
if not ip . overlaps ( gaddr ) :
gwaybad = True
if ntwkbad :
return self . err . val_err ( _ ( " Invalid static route " ) ,
_ ( " The network address is incorrect. " ) )
if gwaybad :
return self . err . val_err ( _ ( " Invalid static route " ) ,
_ ( " The gateway address is incorrect. " ) )
2011-07-13 04:31:46 +04:00
return True
2007-03-30 17:03:32 +04:00
2013-03-29 22:38:29 +04:00
def validate_ipv6 ( self ) :
if not self . get_config_ipv6_enable ( ) :
return True
ip = self . get_config_ip6 ( )
if ip is None :
return self . err . val_err ( _ ( " Invalid Network Address " ) ,
_ ( " The network address could not be understood " ) )
if ip . version != 6 :
return self . err . val_err ( _ ( " Invalid Network Address " ) ,
_ ( " The network must be an IPv6 address " ) )
if ip . prefixlen != 64 :
return self . err . val_err ( _ ( " Invalid Network Address " ) ,
2013-05-27 21:41:45 +04:00
_ ( " For libvirt, the IPv6 network prefix must be /64 " ) )
2013-03-29 22:38:29 +04:00
if not ip . is_private :
res = self . err . yes_no ( _ ( " Check Network Address " ) ,
2015-09-21 19:27:59 +03:00
_ ( " The network should normally use a private IPv6 "
2013-03-29 22:38:29 +04:00
" address. Use this non-private address anyway? " ) )
if not res :
return False
enabled = self . get_config_dhcpv6_enable ( )
if enabled :
start = self . get_config_dhcpv6_start ( )
end = self . get_config_dhcpv6_end ( )
if start is None :
return self . err . val_err ( _ ( " Invalid DHCPv6 Address " ) ,
2013-09-23 17:41:01 +04:00
_ ( " The DHCPv6 start address could not be understood " ) )
2013-03-29 22:38:29 +04:00
if end is None :
return self . err . val_err ( _ ( " Invalid DHCPv6 Address " ) ,
2013-09-23 17:41:01 +04:00
_ ( " The DHCPv6 end address could not be understood " ) )
2013-03-29 22:38:29 +04:00
if not ip . overlaps ( start ) :
return self . err . val_err ( _ ( " Invalid DHCPv6 Address " ) ,
2013-09-23 17:41:01 +04:00
( _ ( " The DHCPv6 start address is not with the network %s " ) %
( str ( ip ) ) ) )
2013-03-29 22:38:29 +04:00
if not ip . overlaps ( end ) :
return self . err . val_err ( _ ( " Invalid DHCPv6 Address " ) ,
2013-09-23 17:41:01 +04:00
( _ ( " The DHCPv6 end address is not with the network %s " ) %
( str ( ip ) ) ) )
2013-03-29 22:38:29 +04:00
2013-05-14 20:15:02 +04:00
enabled = self . get_config_routev6_enable ( )
if enabled :
ntwk = self . get_config_routev6_network ( )
ntwkbad = False
gway = self . get_config_routev6_gateway ( )
gwaybad = False
if ntwk is None or gway is None :
return True
if ntwk == " " and gway == " " :
return True
2013-09-23 17:41:01 +04:00
naddr = _make_ipaddr ( ntwk )
2013-05-14 20:15:02 +04:00
if naddr is None :
ntwkbad = True
else :
if naddr . version != 6 :
ntwkbad = True
if naddr . prefixlen > 64 :
ntwkbad = True
2013-09-23 17:41:01 +04:00
gaddr = _make_ipaddr ( gway )
2013-05-14 20:15:02 +04:00
if gaddr is None :
gwaybad = True
else :
if gaddr . version != 6 :
gwaybad = True
if gaddr . prefixlen != 128 :
gwaybad = True
if not ip . overlaps ( gaddr ) :
gwaybad = True
if ntwkbad :
return self . err . val_err ( _ ( " Invalid static route " ) ,
_ ( " The network address is incorrect. " ) )
if gwaybad :
return self . err . val_err ( _ ( " Invalid static route " ) ,
_ ( " The gateway address is incorrect. " ) )
2011-07-13 04:31:46 +04:00
return True
2013-03-29 22:38:29 +04:00
def validate_miscellaneous ( self ) :
2011-07-13 04:31:46 +04:00
return True
def validate ( self , page_num ) :
if page_num == PAGE_NAME :
return self . validate_name ( )
2007-03-30 17:03:32 +04:00
elif page_num == PAGE_IPV4 :
2011-07-13 04:31:46 +04:00
return self . validate_ipv4 ( )
2013-03-29 22:38:29 +04:00
elif page_num == PAGE_IPV6 :
return self . validate_ipv6 ( )
elif page_num == PAGE_MISC :
return self . validate_miscellaneous ( )
2007-03-30 17:03:32 +04:00
return True
2013-09-23 17:41:01 +04:00
#############
# Listeners #
#############
def forward ( self , ignore = None ) :
notebook = self . widget ( " create-pages " )
if self . validate ( notebook . get_current_page ( ) ) is not True :
return
self . widget ( " create-forward " ) . grab_focus ( )
notebook . next_page ( )
def back ( self , ignore = None ) :
notebook = self . widget ( " create-pages " )
notebook . prev_page ( )
def page_changed ( self , ignore1 , ignore2 , page_number ) :
2013-09-27 21:36:22 +04:00
page_lbl = ( " <span color= ' #59B0E2 ' > %s </span> " %
_ ( " Step %(current_page)d of %(max_page)d " ) %
{ ' current_page ' : page_number + 1 ,
' max_page ' : PAGE_MISC + 1 } )
self . widget ( " header-pagenum " ) . set_markup ( page_lbl )
2013-09-23 17:41:01 +04:00
if page_number == PAGE_NAME :
name_widget = self . widget ( " net-name " )
name_widget . set_sensitive ( True )
name_widget . grab_focus ( )
elif page_number == PAGE_MISC :
name = self . widget ( " net-name " ) . get_text ( )
if self . widget ( " net-domain-name " ) . get_text ( ) == " " :
self . widget ( " net-domain-name " ) . set_text ( name )
self . widget ( " create-back " ) . set_sensitive ( page_number != 0 )
is_last_page = (
page_number == ( self . widget ( " create-pages " ) . get_n_pages ( ) - 1 ) )
self . widget ( " create-forward " ) . set_visible ( not is_last_page )
self . widget ( " create-finish " ) . set_visible ( is_last_page )
if is_last_page :
self . widget ( " create-finish " ) . grab_focus ( )
def change_forward_type ( self , ignore ) :
skip_fwd = self . widget ( " net-forward-none " ) . get_active ( )
self . widget ( " net-forward-mode " ) . set_sensitive ( not skip_fwd )
self . widget ( " net-forward " ) . set_sensitive ( not skip_fwd )
def change_ipv4_enable ( self , ignore ) :
enabled = self . get_config_ipv4_enable ( )
self . widget ( " net-ipv4-box " ) . set_visible ( enabled )
def change_ipv6_enable ( self , ignore ) :
enabled = self . get_config_ipv6_enable ( )
self . widget ( " net-ipv6-box " ) . set_visible ( enabled )
def change_routev4_enable ( self , ignore ) :
enabled = self . get_config_routev4_enable ( )
ntwk = self . widget ( " net-routev4-network " )
gway = self . widget ( " net-routev4-gateway " )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( ntwk , enabled )
uiutil . set_grid_row_visible ( gway , enabled )
2013-09-23 17:41:01 +04:00
def change_routev6_enable ( self , ignore ) :
2013-09-23 21:21:35 +04:00
enabled = self . get_config_routev6_enable ( )
2013-09-23 17:41:01 +04:00
ntwk = self . widget ( " net-routev6-network " )
gway = self . widget ( " net-routev6-gateway " )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( ntwk , enabled )
uiutil . set_grid_row_visible ( gway , enabled )
2013-09-23 17:41:01 +04:00
def change_dhcpv4_enable ( self , ignore ) :
enabled = self . get_config_dhcpv4_enable ( )
start = self . widget ( " net-dhcpv4-start " )
end = self . widget ( " net-dhcpv4-end " )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( start , enabled )
uiutil . set_grid_row_visible ( end , enabled )
2013-09-23 17:41:01 +04:00
def change_dhcpv6_enable ( self , ignore ) :
2013-09-23 21:21:35 +04:00
enabled = self . get_config_dhcpv6_enable ( )
2013-09-23 17:41:01 +04:00
start = self . widget ( " net-dhcpv6-start " )
end = self . widget ( " net-dhcpv6-end " )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( start , enabled )
uiutil . set_grid_row_visible ( end , enabled )
2013-09-23 17:41:01 +04:00
def change_dhcpv4_start ( self , src ) :
start = self . get_config_dhcpv4_start ( )
self . change_dhcpv4 ( src , start )
def change_dhcpv4_end ( self , src ) :
end = self . get_config_dhcpv4_end ( )
self . change_dhcpv4 ( src , end )
def change_dhcpv4 ( self , src , addr ) :
ip = self . get_config_ip4 ( )
if ip is None or addr is None :
src . modify_bg ( Gtk . StateType . NORMAL , _white )
return
if addr . version != 4 or not ip . overlaps ( addr ) :
src . modify_bg ( Gtk . StateType . NORMAL , _red )
else :
src . modify_bg ( Gtk . StateType . NORMAL , _green )
def change_dhcpv6_start ( self , src ) :
start = self . get_config_dhcpv6_start ( )
self . change_dhcpv6 ( src , start )
def change_dhcpv6_end ( self , src ) :
end = self . get_config_dhcpv6_end ( )
self . change_dhcpv6 ( src , end )
def change_dhcpv6 ( self , src , addr ) :
ip = self . get_config_ip6 ( )
if ip is None or addr is None :
src . modify_bg ( Gtk . StateType . NORMAL , _white )
return
if addr . version != 6 or not ip . overlaps ( addr ) :
src . modify_bg ( Gtk . StateType . NORMAL , _red )
else :
src . modify_bg ( Gtk . StateType . NORMAL , _green )
def change_ipv4_network ( self , src ) :
ip = self . get_config_ip4 ( )
# No IP specified or invalid IP
if ip is None or ip . version != 4 :
src . modify_bg ( Gtk . StateType . NORMAL , _red )
return
2014-06-11 05:51:48 +04:00
valid_ip = ( ip . numhosts > = 8 and ip . is_private )
2013-09-23 17:41:01 +04:00
gateway = ( ip . prefixlen != 32 and str ( ip . network + 1 ) or " " )
info = ( ip . is_private and _ ( " Private " ) or _ ( " Other/Public " ) )
start = int ( ip . numhosts / 2 )
end = int ( ip . numhosts - 2 )
src . modify_bg ( Gtk . StateType . NORMAL , valid_ip and _green or _red )
self . widget ( " net-info-gateway " ) . set_text ( gateway )
self . widget ( " net-info-type " ) . set_text ( info )
self . widget ( " net-dhcpv4-start " ) . set_text ( str ( ip . network + start ) )
self . widget ( " net-dhcpv4-end " ) . set_text ( str ( ip . network + end ) )
def change_routev4_network ( self , src ) :
ntwk = self . get_config_routev4_network ( )
ipAddr = self . get_config_ip4 ( )
if ipAddr is None or ntwk is None :
src . modify_bg ( Gtk . StateType . NORMAL , _white )
return
addr = _make_ipaddr ( ntwk )
color = _green
if ( addr is None or
addr . version != 4 or
addr . prefixlen > 28 ) :
color = _red
src . modify_bg ( Gtk . StateType . NORMAL , color )
def change_routev4_gateway ( self , src ) :
gway = self . get_config_routev4_gateway ( )
ipAddr = self . get_config_ip4 ( )
if ipAddr is None or gway is None :
src . modify_bg ( Gtk . StateType . NORMAL , _white )
return
addr = _make_ipaddr ( gway )
color = _green
if ( addr is None or
addr . version != 4 or
not ipAddr . overlaps ( addr ) or
addr . prefixlen != 32 ) :
color = _red
src . modify_bg ( Gtk . StateType . NORMAL , color )
def change_ipv6_network ( self , src ) :
ip = self . get_config_ip6 ( )
if ip is None or ip . version != 6 :
src . modify_bg ( Gtk . StateType . NORMAL , _red )
return
valid_ip = ( ip . numhosts == 64 and ip . is_private )
gateway = ( ip . prefixlen != 64 and str ( ip . network + 1 ) or " " )
start = 256
end = 512 - 1
if ip . is_private :
info = _ ( " Private " )
elif ip . is_reserved :
info = _ ( " Reserved " )
elif ip . is_unspecified :
info = _ ( " Unspecified " )
else :
info = _ ( " Other/Public " )
src . modify_bg ( Gtk . StateType . NORMAL , valid_ip and _green or _red )
self . widget ( " net-info-gateway-ip6 " ) . set_text ( gateway )
self . widget ( " net-info-type-ip6 " ) . set_text ( info )
self . widget ( " net-dhcpv6-start " ) . set_text ( str ( ip . network + start ) )
self . widget ( " net-dhcpv6-end " ) . set_text ( str ( ip . network + end ) )
def change_routev6_network ( self , src ) :
ntwk = self . get_config_routev6_network ( )
ip = self . get_config_ip6 ( )
if ip is None or ntwk is None :
src . modify_bg ( Gtk . StateType . NORMAL , _white )
return
addr = _make_ipaddr ( ntwk )
color = _green
if ( addr is None or
addr . version != 6 or
addr . prefixlen > 64 ) :
color = _red
src . modify_bg ( Gtk . StateType . NORMAL , color )
def change_routev6_gateway ( self , src ) :
gway = self . get_config_routev6_gateway ( )
ip = self . get_config_ip6 ( )
if ip is None or gway is None :
src . modify_bg ( Gtk . StateType . NORMAL , _white )
return
addr = _make_ipaddr ( gway )
color = _green
if ( addr is None or
addr . version != 6 or
ip . overlaps ( addr ) or
addr . prefixlen != 128 ) :
color = _red
src . modify_bg ( Gtk . StateType . NORMAL , color )
#########################
# XML build and install #
#########################
2014-01-18 03:40:30 +04:00
def _build_xmlstub ( self ) :
return Network ( self . conn . get_backend ( ) )
2013-09-23 21:21:35 +04:00
def _build_xmlobj ( self ) :
2014-01-18 03:40:30 +04:00
net = self . _build_xmlstub ( )
2013-09-23 17:41:01 +04:00
2013-09-23 21:21:35 +04:00
net . name = self . widget ( " net-name " ) . get_text ( )
net . domain_name = self . widget ( " net-domain-name " ) . get_text ( ) or None
2013-09-23 17:41:01 +04:00
2013-09-23 21:21:35 +04:00
if self . widget ( " net-enable-ipv6-networking " ) . get_active ( ) :
net . ipv6 = True
2013-09-23 17:41:01 +04:00
2013-09-23 21:21:35 +04:00
dev , mode = self . get_config_forwarding ( )
2013-09-23 17:41:01 +04:00
if mode :
2013-09-23 21:21:35 +04:00
net . forward . mode = mode
net . forward . dev = dev or None
2013-09-23 17:41:01 +04:00
if self . get_config_ipv4_enable ( ) :
ip = self . get_config_ip4 ( )
2013-09-23 21:21:35 +04:00
ipobj = net . add_ip ( )
ipobj . address = str ( ip . network + 1 )
ipobj . netmask = str ( ip . netmask )
2013-09-23 17:41:01 +04:00
if self . get_config_dhcpv4_enable ( ) :
2013-09-23 21:21:35 +04:00
dhcpobj = ipobj . add_range ( )
dhcpobj . start = str ( self . get_config_dhcpv4_start ( ) . network )
dhcpobj . end = str ( self . get_config_dhcpv4_end ( ) . network )
2013-09-23 17:41:01 +04:00
if self . get_config_ipv6_enable ( ) :
ip = self . get_config_ip6 ( )
2013-09-23 21:21:35 +04:00
ipobj = net . add_ip ( )
ipobj . family = " ipv6 "
ipobj . address = str ( ip . network + 1 )
ipobj . prefix = str ( ip . prefixlen )
2013-09-23 17:41:01 +04:00
if self . get_config_dhcpv6_enable ( ) :
2013-09-23 21:21:35 +04:00
dhcpobj = ipobj . add_range ( )
dhcpobj . start = str ( self . get_config_dhcpv6_start ( ) . network )
dhcpobj . end = str ( self . get_config_dhcpv6_end ( ) . network )
2013-09-23 17:41:01 +04:00
2013-09-23 21:21:35 +04:00
netaddr = _make_ipaddr ( self . get_config_routev4_network ( ) )
gwaddr = _make_ipaddr ( self . get_config_routev4_gateway ( ) )
2013-09-23 17:41:01 +04:00
if netaddr and gwaddr :
2013-09-23 21:21:35 +04:00
route = net . add_route ( )
route . family = " ipv4 "
route . address = netaddr . network
route . prefix = netaddr . prefixlen
route . gateway = gwaddr . network
netaddr = _make_ipaddr ( self . get_config_routev6_network ( ) )
gwaddr = _make_ipaddr ( self . get_config_routev6_gateway ( ) )
2013-09-23 17:41:01 +04:00
if netaddr and gwaddr :
2013-09-23 21:21:35 +04:00
route = net . add_route ( )
route . family = " ipv6 "
route . address = netaddr . network
route . prefix = netaddr . prefixlen
route . gateway = gwaddr . network
return net
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 ) )
if error :
error = _ ( " Error creating virtual network: %s " ) % str ( error )
self . err . show_err ( error , details = details )
else :
self . conn . schedule_priority_tick ( pollnet = True )
self . close ( )
2013-09-23 17:41:01 +04:00
2013-09-30 23:06:52 +04:00
def _async_net_create ( self , asyncjob , net ) :
2013-09-23 21:21:35 +04:00
ignore = asyncjob
2013-09-30 23:06:52 +04:00
net . install ( )
2013-09-23 17:41:01 +04:00
def finish ( self , ignore ) :
2014-06-25 14:35:46 +04:00
if not self . validate ( PAGE_MAX ) :
return
2013-09-23 17:41:01 +04:00
try :
2013-09-23 21:21:35 +04:00
net = self . _build_xmlobj ( )
2013-09-23 17:41:01 +04:00
except Exception , e :
2015-06-02 15:21:58 +03:00
self . err . show_err ( _ ( " Error generating network xml: %s " ) % str ( e ) )
2013-09-23 17:41:01 +04:00
return
2013-09-23 21:21:35 +04:00
self . topwin . set_sensitive ( False )
self . topwin . get_window ( ) . set_cursor (
Gdk . Cursor . new ( Gdk . CursorType . WATCH ) )
2013-09-30 23:06:52 +04:00
progWin = vmmAsyncJob ( self . _async_net_create , [ net ] ,
2013-09-23 21:21:35 +04:00
self . _finish_cb , [ ] ,
_ ( " Creating virtual network... " ) ,
_ ( " Creating the virtual network may take a "
" while... " ) ,
self . topwin )
progWin . run ( )