diff --git a/tests/xmlparse.py b/tests/xmlparse.py index ac787c11..958eaa3e 100644 --- a/tests/xmlparse.py +++ b/tests/xmlparse.py @@ -1040,8 +1040,12 @@ class XMLParseTest(unittest.TestCase): check("family", "ipv6", "ipv6") check("prefix", 64, 63) - net.add_route("192.168.8.0", "24", "192.168.8.10") - check = self._make_checker(net.routes[0]) + r = net.add_route() + r.family = "ipv4" + r.address = "192.168.8.0" + r.prefix = "24" + r.gateway = "192.168.8.10" + check = self._make_checker(r) check("netmask", None, "foo", None) utils.diff_compare(net.get_xml_config(), outfile) diff --git a/virtManager/createnet.py b/virtManager/createnet.py index 8427fcbc..7a60845c 100644 --- a/virtManager/createnet.py +++ b/virtManager/createnet.py @@ -28,7 +28,10 @@ from gi.repository import Gtk from gi.repository import Gdk # pylint: enable=E0611 +from virtinst import Network + from virtManager import uihelpers +from virtManager.asyncjob import vmmAsyncJob from virtManager.baseclass import vmmGObjectUI (PAGE_NAME, @@ -505,7 +508,7 @@ class vmmCreateNetwork(vmmGObjectUI): uihelpers.set_grid_row_visible(ntwk, enabled) uihelpers.set_grid_row_visible(gway, enabled) def change_routev6_enable(self, ignore): - enabled = self.get_config_routev4_enable() + enabled = self.get_config_routev6_enable() ntwk = self.widget("net-routev6-network") gway = self.widget("net-routev6-gateway") uihelpers.set_grid_row_visible(ntwk, enabled) @@ -518,7 +521,7 @@ class vmmCreateNetwork(vmmGObjectUI): uihelpers.set_grid_row_visible(start, enabled) uihelpers.set_grid_row_visible(end, enabled) def change_dhcpv6_enable(self, ignore): - enabled = self.get_config_dhcpv4_enable() + enabled = self.get_config_dhcpv6_enable() start = self.widget("net-dhcpv6-start") end = self.widget("net-dhcpv6-end") uihelpers.set_grid_row_visible(start, enabled) @@ -674,99 +677,97 @@ class vmmCreateNetwork(vmmGObjectUI): # XML build and install # ######################### - def _build_xml(self): - name = self.widget("net-name").get_text() - dev, mode = self.get_config_forwarding() + def _build_xmlobj(self): + net = Network(self.conn.get_backend()) + + net.name = self.widget("net-name").get_text() + net.domain_name = self.widget("net-domain-name").get_text() or None if self.widget("net-enable-ipv6-networking").get_active(): - xml = "\n" - else: - xml = "\n" - - xml += " %s\n" % name - - domain_name = self.widget("net-domain-name").get_text() - if domain_name: - xml += " \n" % domain_name + net.ipv6 = True + dev, mode = self.get_config_forwarding() if mode: - if dev is not None: - xml += " \n" % (mode, dev) - else: - xml += " \n" % mode + net.forward.mode = mode + net.forward.dev = dev or None if self.get_config_ipv4_enable(): ip = self.get_config_ip4() - xml += " \n" % (str(ip.network + 1), - str(ip.netmask)) + ipobj = net.add_ip() + ipobj.address = str(ip.network + 1) + ipobj.netmask = str(ip.netmask) if self.get_config_dhcpv4_enable(): - start = self.get_config_dhcpv4_start() - end = self.get_config_dhcpv4_end() - xml += " \n" - xml += " \n" % (str(start.network), - str(end.network)) - xml += " \n" - xml += " \n" + dhcpobj = ipobj.add_range() + dhcpobj.start = str(self.get_config_dhcpv4_start().network) + dhcpobj.end = str(self.get_config_dhcpv4_end().network) if self.get_config_ipv6_enable(): ip = self.get_config_ip6() - xml += " \n" % (str(ip.network + 1), - str(ip.prefixlen)) + ipobj = net.add_ip() + ipobj.family = "ipv6" + ipobj.address = str(ip.network + 1) + ipobj.prefix = str(ip.prefixlen) if self.get_config_dhcpv6_enable(): - start = self.get_config_dhcpv6_start() - end = self.get_config_dhcpv6_end() - xml += " \n" - xml += " \n" % (str(start.network), - str(end.network)) - xml += " \n" - xml += " \n" + dhcpobj = ipobj.add_range() + dhcpobj.start = str(self.get_config_dhcpv6_start().network) + dhcpobj.end = str(self.get_config_dhcpv6_end().network) - ntwk = self.get_config_routev4_network() - try: - netaddr = ipaddr.IPNetwork(ntwk) - except: - netaddr = None - gway = self.get_config_routev4_gateway() - try: - gwaddr = ipaddr.IPNetwork(gway) - except: - gwaddr = None + netaddr = _make_ipaddr(self.get_config_routev4_network()) + gwaddr = _make_ipaddr(self.get_config_routev4_gateway()) if netaddr and gwaddr: - xml += "