2013-05-22 20:59:27 +08:00
|
|
|
# Copyright (C) 2006-2007, 2013 Red Hat, Inc.
|
2007-03-30 21:03:32 +08:00
|
|
|
# Copyright (C) 2006 Hugh O. Brock <hbrock@redhat.com>
|
|
|
|
#
|
2018-03-21 03:00:02 +08:00
|
|
|
# This work is licensed under the GNU GPLv2.
|
|
|
|
# See the COPYING file in the top-level directory.
|
2007-03-30 21:03:32 +08:00
|
|
|
|
2017-10-11 19:35:48 +08:00
|
|
|
import ipaddress
|
2007-03-30 21:03:32 +08:00
|
|
|
import logging
|
|
|
|
|
2012-05-14 21:24:56 +08:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import Gdk
|
2017-04-04 07:46:16 +08:00
|
|
|
from gi.repository import Pango
|
2011-04-19 00:39:53 +08:00
|
|
|
|
2013-09-24 01:21:35 +08:00
|
|
|
from virtinst import Network
|
|
|
|
|
2014-09-13 04:10:45 +08:00
|
|
|
from . import uiutil
|
|
|
|
from .asyncjob import vmmAsyncJob
|
|
|
|
from .baseclass import vmmGObjectUI
|
2007-03-30 21:03:32 +08:00
|
|
|
|
2013-09-23 21:41:01 +08:00
|
|
|
(PAGE_NAME,
|
|
|
|
PAGE_IPV4,
|
|
|
|
PAGE_IPV6,
|
|
|
|
PAGE_MISC) = range(4)
|
|
|
|
|
2014-06-27 11:10:54 +08:00
|
|
|
PAGE_MAX = PAGE_MISC
|
|
|
|
|
2013-09-23 21:41:01 +08: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:
|
2018-01-28 03:19:12 +08:00
|
|
|
return ipaddress.ip_network(str(addrstr), strict=False)
|
2017-07-24 16:26:48 +08:00
|
|
|
except Exception:
|
2013-09-23 21:41:01 +08:00
|
|
|
return None
|
2007-03-30 21:03:32 +08:00
|
|
|
|
|
|
|
|
2010-12-09 06:26:19 +08:00
|
|
|
class vmmCreateNetwork(vmmGObjectUI):
|
|
|
|
def __init__(self, conn):
|
2013-09-23 04:10:16 +08:00
|
|
|
vmmGObjectUI.__init__(self, "createnet.ui", "vmm-create-net")
|
2007-03-30 21:03:32 +08:00
|
|
|
self.conn = conn
|
2010-12-01 03:33:21 +08:00
|
|
|
|
2013-02-17 02:31:46 +08:00
|
|
|
self.builder.connect_signals({
|
2017-08-05 14:39:32 +08: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,
|
|
|
|
"on_create_back_clicked": self.back,
|
|
|
|
"on_create_finish_clicked": self.finish,
|
2009-12-15 05:26:46 +08:00
|
|
|
|
|
|
|
"on_net_name_activate": self.forward,
|
2017-08-05 14:39:32 +08:00
|
|
|
"on_net_forward_toggled": self.change_forward_type,
|
|
|
|
"on_net_forward_mode_toggled": self.change_forward_mode_type,
|
2013-05-15 00:15:02 +08:00
|
|
|
|
2017-08-05 14:39:32 +08:00
|
|
|
"on_net-ipv4-enable_toggled": self.change_ipv4_enable,
|
2013-05-15 00:15:02 +08:00
|
|
|
"on_net-ipv4-network_changed": self.change_ipv4_network,
|
2013-03-30 02:38:29 +08:00
|
|
|
"on_net-dhcpv4-enable_toggled": self.change_dhcpv4_enable,
|
2013-05-15 00:15:02 +08:00
|
|
|
"on_net-dhcpv4-start_changed": self.change_dhcpv4_start,
|
|
|
|
"on_net-dhcpv4-end_changed": self.change_dhcpv4_end,
|
|
|
|
|
2017-08-05 14:39:32 +08:00
|
|
|
"on_net-ipv6-enable_toggled": self.change_ipv6_enable,
|
2013-05-15 00:15:02 +08:00
|
|
|
"on_net-ipv6-network_changed": self.change_ipv6_network,
|
2013-03-30 02:38:29 +08:00
|
|
|
"on_net-dhcpv6-enable_toggled": self.change_dhcpv6_enable,
|
2013-05-15 00:15:02 +08: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 08:31:46 +08:00
|
|
|
})
|
2011-04-18 23:25:28 +08:00
|
|
|
self.bind_escape_key_close()
|
2007-03-30 21:03:32 +08:00
|
|
|
|
|
|
|
self.set_initial_state()
|
|
|
|
|
2013-09-23 21:41:01 +08:00
|
|
|
|
|
|
|
####################
|
|
|
|
# Standard methods #
|
|
|
|
####################
|
|
|
|
|
2011-04-14 20:47:42 +08:00
|
|
|
def show(self, parent):
|
2012-02-01 07:16:54 +08:00
|
|
|
logging.debug("Showing new network wizard")
|
2007-03-30 21:03:32 +08:00
|
|
|
self.reset_state()
|
2011-04-14 20:47:42 +08:00
|
|
|
self.topwin.set_transient_for(parent)
|
2007-03-30 21:03:32 +08:00
|
|
|
self.topwin.present()
|
|
|
|
|
2011-04-13 21:27:02 +08:00
|
|
|
def close(self, ignore1=None, ignore2=None):
|
2012-02-01 07:16:54 +08:00
|
|
|
logging.debug("Closing new network wizard")
|
2011-04-13 21:27:02 +08:00
|
|
|
self.topwin.hide()
|
|
|
|
return 1
|
|
|
|
|
2011-07-24 09:16:54 +08:00
|
|
|
def _cleanup(self):
|
2011-04-13 21:27:02 +08:00
|
|
|
self.conn = None
|
|
|
|
|
2007-03-30 21:03:32 +08:00
|
|
|
def set_initial_state(self):
|
2011-07-15 01:13:13 +08:00
|
|
|
notebook = self.widget("create-pages")
|
2007-03-30 21:03:32 +08:00
|
|
|
notebook.set_show_tabs(False)
|
|
|
|
|
2013-09-28 01:36:22 +08:00
|
|
|
blue = Gdk.Color.parse("#0072A8")[1]
|
|
|
|
self.widget("header").modify_bg(Gtk.StateType.NORMAL, blue)
|
2007-03-30 21:03:32 +08:00
|
|
|
|
2017-03-31 20:12:01 +08:00
|
|
|
# [ label, dev name ]
|
|
|
|
pf_list = self.widget("pf-list")
|
|
|
|
pf_model = Gtk.ListStore(str, str)
|
|
|
|
pf_list.set_model(pf_model)
|
2017-04-04 07:46:16 +08:00
|
|
|
text = uiutil.init_combo_text_column(pf_list, 0)
|
|
|
|
text.set_property("ellipsize", Pango.EllipsizeMode.MIDDLE)
|
2017-03-31 20:12:01 +08:00
|
|
|
|
2009-12-02 00:49:08 +08:00
|
|
|
# [ label, dev name ]
|
2013-09-23 21:41:01 +08:00
|
|
|
fw_list = self.widget("net-forward")
|
2012-05-14 21:24:56 +08:00
|
|
|
fw_model = Gtk.ListStore(str, str)
|
2007-03-30 21:03:32 +08:00
|
|
|
fw_list.set_model(fw_model)
|
2015-04-11 01:04:02 +08:00
|
|
|
uiutil.init_combo_text_column(fw_list, 0)
|
2009-12-02 00:49:08 +08:00
|
|
|
|
|
|
|
# [ label, mode ]
|
2013-09-23 21:41:01 +08:00
|
|
|
mode_list = self.widget("net-forward-mode")
|
2012-05-14 21:24:56 +08:00
|
|
|
mode_model = Gtk.ListStore(str, str)
|
2009-12-02 00:49:08 +08:00
|
|
|
mode_list.set_model(mode_model)
|
2015-04-11 01:04:02 +08:00
|
|
|
uiutil.init_combo_text_column(mode_list, 0)
|
2009-12-02 00:49:08 +08:00
|
|
|
|
|
|
|
mode_model.append([_("NAT"), "nat"])
|
|
|
|
mode_model.append([_("Routed"), "route"])
|
2017-05-03 23:56:32 +08:00
|
|
|
mode_model.append([_("Open"), "open"])
|
2007-03-30 21:03:32 +08:00
|
|
|
|
|
|
|
def reset_state(self):
|
2011-07-15 01:13:13 +08:00
|
|
|
notebook = self.widget("create-pages")
|
2007-03-30 21:03:32 +08:00
|
|
|
notebook.set_current_page(0)
|
2011-07-13 08:31:46 +08:00
|
|
|
|
|
|
|
self.page_changed(None, None, 0)
|
2007-03-30 21:03:32 +08:00
|
|
|
|
2011-07-15 01:13:13 +08:00
|
|
|
self.widget("net-name").set_text("")
|
2013-03-30 02:38:29 +08:00
|
|
|
self.widget("net-domain-name").set_text("")
|
2013-09-23 21:41:01 +08:00
|
|
|
|
2013-03-30 02:38:29 +08: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 21:41:01 +08: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-30 02:38:29 +08:00
|
|
|
self.widget("net-ipv6-enable").set_active(False)
|
2013-09-23 21:41:01 +08:00
|
|
|
self.widget("net-ipv6-enable").toggled()
|
2013-03-30 02:38:29 +08:00
|
|
|
self.widget("net-ipv6-network").set_text("")
|
|
|
|
self.widget("net-dhcpv6-enable").set_active(False)
|
2013-09-23 21:41:01 +08:00
|
|
|
self.widget("net-dhcpv6-enable").toggled()
|
2013-03-30 02:38:29 +08:00
|
|
|
self.widget("net-dhcpv6-start").set_text("")
|
|
|
|
self.widget("net-dhcpv6-end").set_text("")
|
2013-09-23 21:41:01 +08: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 21:03:32 +08:00
|
|
|
|
2017-03-31 20:12:01 +08:00
|
|
|
|
2017-04-04 07:46:16 +08:00
|
|
|
# Populate physical forward devices
|
2013-08-06 05:20:05 +08:00
|
|
|
fw_model = self.widget("net-forward").get_model()
|
|
|
|
fw_model.clear()
|
|
|
|
fw_model.append([_("Any physical device"), None])
|
2014-06-18 05:04:49 +08:00
|
|
|
|
|
|
|
devnames = []
|
2015-04-10 21:37:03 +08:00
|
|
|
for nodedev in self.conn.filter_nodedevs("net"):
|
2015-04-08 02:12:00 +08:00
|
|
|
devnames.append(nodedev.xmlobj.interface)
|
2014-06-18 05:04:49 +08:00
|
|
|
for iface in self.conn.list_interfaces():
|
2014-06-24 15:44:04 +08:00
|
|
|
if iface.get_name() not in devnames:
|
|
|
|
devnames.append(iface.get_name())
|
2014-06-18 05:04:49 +08:00
|
|
|
|
|
|
|
for name in devnames:
|
|
|
|
fw_model.append([_("Physical device %s") % name, name])
|
2017-04-04 07:46:16 +08:00
|
|
|
self.widget("net-forward").set_active(0)
|
|
|
|
|
|
|
|
self.widget("net-forward-mode").set_active(0)
|
|
|
|
|
|
|
|
|
|
|
|
# Populate hostdev forward devices
|
|
|
|
pf_model = self.widget("pf-list").get_model()
|
|
|
|
pf_model.clear()
|
2013-08-06 05:20:05 +08:00
|
|
|
|
2017-03-31 20:12:01 +08:00
|
|
|
devprettynames = []
|
|
|
|
ifnames = []
|
|
|
|
for pcidev in self.conn.filter_nodedevs("pci"):
|
|
|
|
if pcidev.xmlobj.capability_type != "virt_functions":
|
|
|
|
continue
|
|
|
|
devdesc = pcidev.xmlobj.pretty_name()
|
|
|
|
for netdev in self.conn.filter_nodedevs("net"):
|
|
|
|
if pcidev.xmlobj.name != netdev.xmlobj.parent:
|
|
|
|
continue
|
|
|
|
ifname = netdev.xmlobj.interface
|
|
|
|
devprettyname = "%s (%s)" % (ifname, devdesc)
|
|
|
|
devprettynames.append(devprettyname)
|
|
|
|
ifnames.append(ifname)
|
|
|
|
break
|
2017-04-04 07:46:16 +08:00
|
|
|
for devprettyname, ifname in zip(devprettynames, ifnames):
|
|
|
|
pf_model.append([_("%s") % devprettyname, ifname])
|
|
|
|
if len(pf_model) is 0:
|
2017-03-31 20:12:01 +08:00
|
|
|
pf_model.append([_("No available device"), None])
|
|
|
|
self.widget("pf-list").set_active(0)
|
|
|
|
|
2013-09-23 21:41:01 +08:00
|
|
|
self.widget("net-forward-none").set_active(True)
|
2007-03-30 21:03:32 +08:00
|
|
|
|
2009-12-02 00:49:08 +08:00
|
|
|
|
2017-04-04 07:46:16 +08:00
|
|
|
|
2013-09-23 21:41:01 +08:00
|
|
|
##################
|
|
|
|
# UI get helpers #
|
|
|
|
##################
|
2007-03-30 21:03:32 +08:00
|
|
|
|
2013-03-30 02:38:29 +08: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-15 00:15:02 +08: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 21:41:01 +08: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 22:07:22 +08:00
|
|
|
|
2013-09-23 21:41:01 +08: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-15 00:15:02 +08:00
|
|
|
|
2013-09-23 21:41:01 +08:00
|
|
|
def get_config_forwarding(self):
|
2017-03-31 20:12:01 +08:00
|
|
|
if self.widget("net-forward-mode-hostdev").get_active():
|
|
|
|
name = uiutil.get_list_selection(self.widget("pf-list"), column=1)
|
|
|
|
mode = "hostdev"
|
|
|
|
return [name, mode]
|
|
|
|
|
2013-09-23 21:41:01 +08:00
|
|
|
if self.widget("net-forward-none").get_active():
|
|
|
|
return [None, None]
|
2013-05-15 00:15:02 +08:00
|
|
|
|
2015-05-20 05:17:53 +08: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 21:41:01 +08:00
|
|
|
return [name, mode]
|
2007-03-30 21:03:32 +08:00
|
|
|
|
2013-09-23 21:41:01 +08: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 21:03:32 +08:00
|
|
|
|
2009-12-12 02:45:53 +08:00
|
|
|
|
2013-09-23 21:41:01 +08:00
|
|
|
###################
|
|
|
|
# Page validation #
|
|
|
|
###################
|
2007-03-30 21:03:32 +08:00
|
|
|
|
2011-07-13 08:31:46 +08:00
|
|
|
def validate_name(self):
|
2014-01-18 07:40:30 +08:00
|
|
|
try:
|
|
|
|
net = self._build_xmlstub()
|
|
|
|
net.name = self.widget("net-name").get_text()
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2014-01-18 07:40:30 +08:00
|
|
|
return self.err.val_err(_("Invalid network name"), str(e))
|
|
|
|
|
2011-07-13 08:31:46 +08:00
|
|
|
return True
|
|
|
|
|
|
|
|
def validate_ipv4(self):
|
2013-03-30 02:38:29 +08:00
|
|
|
if not self.get_config_ipv4_enable():
|
|
|
|
return True
|
2011-07-13 08:31:46 +08: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-30 02:38:28 +08:00
|
|
|
if ip.version != 4:
|
2011-07-13 08:31:46 +08:00
|
|
|
return self.err.val_err(_("Invalid Network Address"),
|
|
|
|
_("The network must be an IPv4 address"))
|
|
|
|
|
2017-10-11 19:35:48 +08:00
|
|
|
if ip.num_addresses < 8:
|
2011-07-13 08:31:46 +08:00
|
|
|
return self.err.val_err(_("Invalid Network Address"),
|
2014-06-11 09:51:48 +08:00
|
|
|
_("The network must address at least 8 addresses."))
|
2011-07-13 08:31:46 +08:00
|
|
|
|
2014-05-20 07:23:46 +08:00
|
|
|
if ip.prefixlen < 15:
|
|
|
|
return self.err.val_err(_("Invalid Network Address"),
|
|
|
|
_("The network prefix must be >= 15"))
|
|
|
|
|
2013-03-30 02:38:28 +08:00
|
|
|
if not ip.is_private:
|
2011-07-13 08:31:46 +08: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-30 02:38:29 +08:00
|
|
|
enabled = self.get_config_dhcpv4_enable()
|
|
|
|
if enabled:
|
|
|
|
start = self.get_config_dhcpv4_start()
|
|
|
|
end = self.get_config_dhcpv4_end()
|
2013-05-15 00:15:02 +08:00
|
|
|
if start is None:
|
2013-03-30 02:38:29 +08:00
|
|
|
return self.err.val_err(_("Invalid DHCP Address"),
|
2013-09-23 21:41:01 +08:00
|
|
|
_("The DHCP start address could not be understood"))
|
2013-05-15 00:15:02 +08:00
|
|
|
if end is None:
|
2013-03-30 02:38:29 +08:00
|
|
|
return self.err.val_err(_("Invalid DHCP Address"),
|
2013-09-23 21:41:01 +08:00
|
|
|
_("The DHCP end address could not be understood"))
|
2013-05-15 00:15:02 +08:00
|
|
|
if not ip.overlaps(start):
|
2013-03-30 02:38:29 +08:00
|
|
|
return self.err.val_err(_("Invalid DHCP Address"),
|
2013-09-23 21:41:01 +08:00
|
|
|
(_("The DHCP start address is not with the network %s") %
|
|
|
|
(str(ip))))
|
2013-05-15 00:15:02 +08:00
|
|
|
if not ip.overlaps(end):
|
2013-03-30 02:38:29 +08:00
|
|
|
return self.err.val_err(_("Invalid DHCP Address"),
|
2013-09-23 21:41:01 +08:00
|
|
|
(_("The DHCP end address is not with the network %s") %
|
|
|
|
(str(ip))))
|
2013-03-30 02:38:29 +08:00
|
|
|
|
2013-05-15 00:15:02 +08: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 21:41:01 +08:00
|
|
|
naddr = _make_ipaddr(ntwk)
|
2013-05-15 00:15:02 +08:00
|
|
|
if naddr is None:
|
|
|
|
ntwkbad = True
|
|
|
|
else:
|
|
|
|
if naddr.version != 4:
|
|
|
|
ntwkbad = True
|
|
|
|
if naddr.prefixlen > 28:
|
|
|
|
ntwkbad = True
|
2013-09-23 21:41:01 +08:00
|
|
|
gaddr = _make_ipaddr(gway)
|
2013-05-15 00:15:02 +08: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 08:31:46 +08:00
|
|
|
return True
|
2007-03-30 21:03:32 +08:00
|
|
|
|
2013-03-30 02:38:29 +08: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-28 01:41:45 +08:00
|
|
|
_("For libvirt, the IPv6 network prefix must be /64"))
|
2013-03-30 02:38:29 +08:00
|
|
|
|
|
|
|
if not ip.is_private:
|
|
|
|
res = self.err.yes_no(_("Check Network Address"),
|
2015-09-22 00:27:59 +08:00
|
|
|
_("The network should normally use a private IPv6 "
|
2013-03-30 02:38:29 +08: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 21:41:01 +08:00
|
|
|
_("The DHCPv6 start address could not be understood"))
|
2013-03-30 02:38:29 +08:00
|
|
|
if end is None:
|
|
|
|
return self.err.val_err(_("Invalid DHCPv6 Address"),
|
2013-09-23 21:41:01 +08:00
|
|
|
_("The DHCPv6 end address could not be understood"))
|
2013-03-30 02:38:29 +08:00
|
|
|
if not ip.overlaps(start):
|
|
|
|
return self.err.val_err(_("Invalid DHCPv6 Address"),
|
2013-09-23 21:41:01 +08:00
|
|
|
(_("The DHCPv6 start address is not with the network %s") %
|
|
|
|
(str(ip))))
|
2013-03-30 02:38:29 +08:00
|
|
|
if not ip.overlaps(end):
|
|
|
|
return self.err.val_err(_("Invalid DHCPv6 Address"),
|
2013-09-23 21:41:01 +08:00
|
|
|
(_("The DHCPv6 end address is not with the network %s") %
|
|
|
|
(str(ip))))
|
2013-03-30 02:38:29 +08:00
|
|
|
|
2013-05-15 00:15:02 +08: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 21:41:01 +08:00
|
|
|
naddr = _make_ipaddr(ntwk)
|
2013-05-15 00:15:02 +08:00
|
|
|
if naddr is None:
|
|
|
|
ntwkbad = True
|
|
|
|
else:
|
|
|
|
if naddr.version != 6:
|
|
|
|
ntwkbad = True
|
|
|
|
if naddr.prefixlen > 64:
|
|
|
|
ntwkbad = True
|
2013-09-23 21:41:01 +08:00
|
|
|
gaddr = _make_ipaddr(gway)
|
2013-05-15 00:15:02 +08: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 08:31:46 +08:00
|
|
|
return True
|
|
|
|
|
2013-03-30 02:38:29 +08:00
|
|
|
def validate_miscellaneous(self):
|
2011-07-13 08:31:46 +08:00
|
|
|
return True
|
|
|
|
|
|
|
|
def validate(self, page_num):
|
|
|
|
if page_num == PAGE_NAME:
|
|
|
|
return self.validate_name()
|
2007-03-30 21:03:32 +08:00
|
|
|
elif page_num == PAGE_IPV4:
|
2011-07-13 08:31:46 +08:00
|
|
|
return self.validate_ipv4()
|
2013-03-30 02:38:29 +08:00
|
|
|
elif page_num == PAGE_IPV6:
|
|
|
|
return self.validate_ipv6()
|
|
|
|
elif page_num == PAGE_MISC:
|
|
|
|
return self.validate_miscellaneous()
|
2007-03-30 21:03:32 +08:00
|
|
|
return True
|
2013-09-23 21:41:01 +08: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-28 01:36:22 +08: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 21:41:01 +08: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):
|
2017-04-04 07:46:16 +08:00
|
|
|
sriov_capable = bool(len(self.widget("pf-list").get_model()))
|
2017-03-31 20:12:01 +08:00
|
|
|
self.widget("net-forward-mode-hostdev").set_sensitive(sriov_capable)
|
2017-05-03 23:56:32 +08:00
|
|
|
mode = uiutil.get_list_selection(self.widget("net-forward-mode"),
|
|
|
|
column=1)
|
2017-04-04 07:46:16 +08:00
|
|
|
|
|
|
|
is_hostdev = self.widget("net-forward-mode-hostdev").get_active()
|
|
|
|
fwd_sensitive = False
|
|
|
|
if not is_hostdev:
|
|
|
|
fwd_sensitive = not self.widget("net-forward-none").get_active()
|
|
|
|
|
|
|
|
self.widget("net-forward-mode").set_sensitive(fwd_sensitive)
|
2017-05-03 23:56:32 +08:00
|
|
|
self.widget("net-forward").set_sensitive(fwd_sensitive and
|
|
|
|
mode != "open")
|
2017-04-04 07:46:16 +08:00
|
|
|
self.widget("net-forward-hostdev-table").set_sensitive(is_hostdev)
|
|
|
|
self.widget("net-enable-ipv6-networking-box").set_sensitive(
|
|
|
|
not is_hostdev)
|
|
|
|
self.widget("dns-domain-name-box").set_sensitive(not is_hostdev)
|
2013-09-23 21:41:01 +08:00
|
|
|
|
2017-05-03 23:56:32 +08:00
|
|
|
def change_forward_mode_type(self, ignore):
|
|
|
|
mode = uiutil.get_list_selection(self.widget("net-forward-mode"),
|
|
|
|
column=1)
|
|
|
|
self.widget("net-forward").set_sensitive(mode != "open")
|
|
|
|
|
2013-09-23 21:41:01 +08:00
|
|
|
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 07:15:50 +08:00
|
|
|
uiutil.set_grid_row_visible(ntwk, enabled)
|
|
|
|
uiutil.set_grid_row_visible(gway, enabled)
|
2013-09-23 21:41:01 +08:00
|
|
|
def change_routev6_enable(self, ignore):
|
2013-09-24 01:21:35 +08:00
|
|
|
enabled = self.get_config_routev6_enable()
|
2013-09-23 21:41:01 +08:00
|
|
|
ntwk = self.widget("net-routev6-network")
|
|
|
|
gway = self.widget("net-routev6-gateway")
|
2014-01-27 07:15:50 +08:00
|
|
|
uiutil.set_grid_row_visible(ntwk, enabled)
|
|
|
|
uiutil.set_grid_row_visible(gway, enabled)
|
2013-09-23 21:41:01 +08: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 07:15:50 +08:00
|
|
|
uiutil.set_grid_row_visible(start, enabled)
|
|
|
|
uiutil.set_grid_row_visible(end, enabled)
|
2013-09-23 21:41:01 +08:00
|
|
|
def change_dhcpv6_enable(self, ignore):
|
2013-09-24 01:21:35 +08:00
|
|
|
enabled = self.get_config_dhcpv6_enable()
|
2013-09-23 21:41:01 +08:00
|
|
|
start = self.widget("net-dhcpv6-start")
|
|
|
|
end = self.widget("net-dhcpv6-end")
|
2014-01-27 07:15:50 +08:00
|
|
|
uiutil.set_grid_row_visible(start, enabled)
|
|
|
|
uiutil.set_grid_row_visible(end, enabled)
|
2013-09-23 21:41:01 +08: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
|
|
|
|
|
2017-10-11 19:35:48 +08:00
|
|
|
valid_ip = (ip.num_addresses >= 8 and ip.is_private)
|
|
|
|
gateway = (ip.prefixlen != 32 and str(ip.network_address + 1) or "")
|
2013-09-23 21:41:01 +08:00
|
|
|
info = (ip.is_private and _("Private") or _("Other/Public"))
|
2017-10-11 19:35:48 +08:00
|
|
|
start = int(ip.num_addresses // 2)
|
|
|
|
end = int(ip.num_addresses - 2)
|
2013-09-23 21:41:01 +08:00
|
|
|
|
|
|
|
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)
|
2017-10-11 19:35:48 +08:00
|
|
|
self.widget("net-dhcpv4-start").set_text(
|
|
|
|
str(ip.network_address + start)
|
|
|
|
)
|
|
|
|
self.widget("net-dhcpv4-end").set_text(str(ip.network_address + end))
|
2013-09-23 21:41:01 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-10-11 19:35:48 +08:00
|
|
|
valid_ip = (ip.num_addresses == 64 and ip.is_private)
|
|
|
|
gateway = (ip.prefixlen != 64 and str(ip.network_address + 1) or "")
|
2013-09-23 21:41:01 +08:00
|
|
|
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)
|
2017-10-11 19:35:48 +08:00
|
|
|
self.widget("net-dhcpv6-start").set_text(
|
|
|
|
str(ip.network_address + start)
|
|
|
|
)
|
|
|
|
self.widget("net-dhcpv6-end").set_text(str(ip.network_address + end))
|
2013-09-23 21:41:01 +08:00
|
|
|
|
|
|
|
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 07:40:30 +08:00
|
|
|
def _build_xmlstub(self):
|
|
|
|
return Network(self.conn.get_backend())
|
|
|
|
|
2013-09-24 01:21:35 +08:00
|
|
|
def _build_xmlobj(self):
|
2014-01-18 07:40:30 +08:00
|
|
|
net = self._build_xmlstub()
|
2013-09-23 21:41:01 +08:00
|
|
|
|
2013-09-24 01:21:35 +08:00
|
|
|
net.name = self.widget("net-name").get_text()
|
|
|
|
net.domain_name = self.widget("net-domain-name").get_text() or None
|
2013-09-23 21:41:01 +08:00
|
|
|
|
2013-09-24 01:21:35 +08:00
|
|
|
if self.widget("net-enable-ipv6-networking").get_active():
|
|
|
|
net.ipv6 = True
|
2013-09-23 21:41:01 +08:00
|
|
|
|
2013-09-24 01:21:35 +08:00
|
|
|
dev, mode = self.get_config_forwarding()
|
2013-09-23 21:41:01 +08:00
|
|
|
if mode:
|
2013-09-24 01:21:35 +08:00
|
|
|
net.forward.mode = mode
|
2017-05-03 23:56:32 +08:00
|
|
|
if mode == "open":
|
|
|
|
net.forward.dev = None
|
|
|
|
else:
|
|
|
|
net.forward.dev = dev or None
|
2013-09-23 21:41:01 +08:00
|
|
|
|
2017-03-31 20:12:01 +08:00
|
|
|
if net.forward.mode == "hostdev":
|
|
|
|
net.forward.managed = "yes"
|
2018-02-08 06:27:56 +08:00
|
|
|
pfobj = net.forward.pfs.add_new()
|
2017-03-31 20:12:01 +08:00
|
|
|
pfobj.dev = net.forward.dev
|
|
|
|
net.forward.dev = None
|
|
|
|
net.domain_name = None
|
|
|
|
net.ipv6 = None
|
|
|
|
return net
|
|
|
|
|
2013-09-23 21:41:01 +08:00
|
|
|
if self.get_config_ipv4_enable():
|
|
|
|
ip = self.get_config_ip4()
|
2018-02-08 06:27:56 +08:00
|
|
|
ipobj = net.ips.add_new()
|
2017-10-11 19:35:48 +08:00
|
|
|
ipobj.address = str(ip.network_address + 1)
|
2013-09-24 01:21:35 +08:00
|
|
|
ipobj.netmask = str(ip.netmask)
|
2013-09-23 21:41:01 +08:00
|
|
|
|
|
|
|
if self.get_config_dhcpv4_enable():
|
2018-02-08 06:27:56 +08:00
|
|
|
dhcpobj = ipobj.ranges.add_new()
|
2017-10-11 19:35:48 +08:00
|
|
|
dhcpobj.start = str(
|
|
|
|
self.get_config_dhcpv4_start().network_address
|
|
|
|
)
|
|
|
|
dhcpobj.end = str(self.get_config_dhcpv4_end().network_address)
|
2013-09-23 21:41:01 +08:00
|
|
|
|
|
|
|
if self.get_config_ipv6_enable():
|
|
|
|
ip = self.get_config_ip6()
|
2018-02-08 06:27:56 +08:00
|
|
|
ipobj = net.ips.add_new()
|
2013-09-24 01:21:35 +08:00
|
|
|
ipobj.family = "ipv6"
|
2017-10-11 19:35:48 +08:00
|
|
|
ipobj.address = str(ip.network_address + 1)
|
2013-09-24 01:21:35 +08:00
|
|
|
ipobj.prefix = str(ip.prefixlen)
|
2013-09-23 21:41:01 +08:00
|
|
|
|
|
|
|
if self.get_config_dhcpv6_enable():
|
2018-02-08 06:27:56 +08:00
|
|
|
dhcpobj = ipobj.ranges.add_new()
|
2017-10-11 19:35:48 +08:00
|
|
|
dhcpobj.start = str(
|
|
|
|
self.get_config_dhcpv6_start().network_address
|
|
|
|
)
|
|
|
|
dhcpobj.end = str(
|
|
|
|
self.get_config_dhcpv6_end().network_address
|
|
|
|
)
|
2013-09-23 21:41:01 +08:00
|
|
|
|
2013-09-24 01:21:35 +08:00
|
|
|
netaddr = _make_ipaddr(self.get_config_routev4_network())
|
|
|
|
gwaddr = _make_ipaddr(self.get_config_routev4_gateway())
|
2013-09-23 21:41:01 +08:00
|
|
|
if netaddr and gwaddr:
|
2018-02-08 06:27:56 +08:00
|
|
|
route = net.routes.add_new()
|
2013-09-24 01:21:35 +08:00
|
|
|
route.family = "ipv4"
|
2017-10-11 19:35:48 +08:00
|
|
|
route.address = netaddr.network_address
|
2013-09-24 01:21:35 +08:00
|
|
|
route.prefix = netaddr.prefixlen
|
2017-10-11 19:35:48 +08:00
|
|
|
route.gateway = gwaddr.network_address
|
2013-09-24 01:21:35 +08:00
|
|
|
|
|
|
|
netaddr = _make_ipaddr(self.get_config_routev6_network())
|
|
|
|
gwaddr = _make_ipaddr(self.get_config_routev6_gateway())
|
2013-09-23 21:41:01 +08:00
|
|
|
if netaddr and gwaddr:
|
2018-02-08 06:27:56 +08:00
|
|
|
route = net.routes.add_new()
|
2013-09-24 01:21:35 +08:00
|
|
|
route.family = "ipv6"
|
2017-10-11 19:35:48 +08:00
|
|
|
route.address = netaddr.network_address
|
2013-09-24 01:21:35 +08:00
|
|
|
route.prefix = netaddr.prefixlen
|
2017-10-11 19:35:48 +08:00
|
|
|
route.gateway = gwaddr.network_address
|
2013-09-24 01:21:35 +08:00
|
|
|
|
|
|
|
return net
|
|
|
|
|
|
|
|
def _finish_cb(self, error, details):
|
2017-04-28 03:00:17 +08:00
|
|
|
self.reset_finish_cursor()
|
2013-09-24 01:21:35 +08:00
|
|
|
|
|
|
|
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 21:41:01 +08:00
|
|
|
|
2013-10-01 03:06:52 +08:00
|
|
|
def _async_net_create(self, asyncjob, net):
|
2013-09-24 01:21:35 +08:00
|
|
|
ignore = asyncjob
|
2013-10-01 03:06:52 +08:00
|
|
|
net.install()
|
2013-09-23 21:41:01 +08:00
|
|
|
|
|
|
|
def finish(self, ignore):
|
2014-06-25 18:35:46 +08:00
|
|
|
if not self.validate(PAGE_MAX):
|
|
|
|
return
|
|
|
|
|
2013-09-23 21:41:01 +08:00
|
|
|
try:
|
2013-09-24 01:21:35 +08:00
|
|
|
net = self._build_xmlobj()
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2015-06-02 20:21:58 +08:00
|
|
|
self.err.show_err(_("Error generating network xml: %s") % str(e))
|
2013-09-23 21:41:01 +08:00
|
|
|
return
|
|
|
|
|
2017-04-28 03:00:17 +08:00
|
|
|
self.set_finish_cursor()
|
2013-10-01 03:06:52 +08:00
|
|
|
progWin = vmmAsyncJob(self._async_net_create, [net],
|
2013-09-24 01:21:35 +08:00
|
|
|
self._finish_cb, [],
|
|
|
|
_("Creating virtual network..."),
|
|
|
|
_("Creating the virtual network may take a "
|
|
|
|
"while..."),
|
|
|
|
self.topwin)
|
|
|
|
progWin.run()
|