Example #1
0
    def validate_name(self):
        try:
            name = self.widget("net-name").get_text()
            Network.validate_name(self.conn.get_backend(), name)
        except Exception as e:
            return self.err.val_err(_("Invalid network name"), str(e))

        return True
Example #2
0
    def validate_name(self):
        try:
            name = self.widget("net-name").get_text()
            Network.validate_name(self.conn.get_backend(), name)
        except Exception as e:
            return self.err.val_err(_("Invalid network name"), str(e))

        return True
Example #3
0
    def _build_xmlobj_from_ui(self):
        net = Network(self.conn.get_backend())

        net.name = self.widget("net-name").get_text()
        net.domain_name = self.get_config_domain_name()

        mode = uiutil.get_list_selection(self.widget("net-forward-mode"))
        dev = self._get_config_net_forward_dev()

        if mode == "isolated":
            mode = None

        net.forward.mode = mode
        net.forward.dev = dev

        if net.forward.mode == "hostdev":
            net.forward.managed = "yes"
            pfobj = net.forward.pf.add_new()
            pfobj.dev = uiutil.get_list_selection(
                self.widget("net-hostdevs"))
            return net

        if self.get_config_ipv4_enable():
            ip = self.get_config_ip4()
            ipobj = net.ips.add_new()
            if ip:
                ipobj.address = str(ip.network_address + 1)
                ipobj.netmask = str(ip.netmask)

            if self.get_config_dhcpv4_enable():
                dhcpobj = ipobj.ranges.add_new()
                start = self.get_config_dhcpv4_start()
                end = self.get_config_dhcpv4_end()
                if start:
                    dhcpobj.start = str(start.network_address)
                if end:
                    dhcpobj.end = str(end.network_address)

        if self.get_config_ipv6_enable():
            ip = self.get_config_ip6()
            ipobj = net.ips.add_new()
            ipobj.family = "ipv6"
            if ip:
                ipobj.address = str(ip.network_address + 1)
                ipobj.prefix = str(ip.prefixlen)

            if self.get_config_dhcpv6_enable():
                dhcpobj = ipobj.ranges.add_new()
                start = self.get_config_dhcpv6_start()
                end = self.get_config_dhcpv6_end()
                if start:
                    dhcpobj.start = str(start.network_address)
                if end:
                    dhcpobj.end = str(end.network_address)

        return net
Example #4
0
    def _build_xmlobj_from_ui(self):
        net = Network(self.conn.get_backend())

        net.name = self.widget("net-name").get_text()
        net.domain_name = self.get_config_domain_name()

        dev, mode = self.get_config_forwarding()
        if mode:
            net.forward.mode = mode
            if mode == "open":
                net.forward.dev = None
            else:
                net.forward.dev = dev or None

        if net.forward.mode == "hostdev":
            net.forward.managed = "yes"
            pfobj = net.forward.pf.add_new()
            pfobj.dev = net.forward.dev
            net.forward.dev = None
            return net

        if self.get_config_ipv4_enable():
            ip = self.get_config_ip4()
            ipobj = net.ips.add_new()
            if ip:
                ipobj.address = str(ip.network_address + 1)
                ipobj.netmask = str(ip.netmask)

            if self.get_config_dhcpv4_enable():
                dhcpobj = ipobj.ranges.add_new()
                start = self.get_config_dhcpv4_start()
                end = self.get_config_dhcpv4_end()
                if start:
                    dhcpobj.start = str(start.network_address)
                if end:
                    dhcpobj.end = str(end.network_address)

        if self.get_config_ipv6_enable():
            ip = self.get_config_ip6()
            ipobj = net.ips.add_new()
            ipobj.family = "ipv6"
            if ip:
                ipobj.address = str(ip.network_address + 1)
                ipobj.prefix = str(ip.prefixlen)

            if self.get_config_dhcpv6_enable():
                dhcpobj = ipobj.ranges.add_new()
                start = self.get_config_dhcpv6_start()
                end = self.get_config_dhcpv6_end()
                if start:
                    dhcpobj.start = str(start.network_address)
                if end:
                    dhcpobj.end = str(end.network_address)

        return net
Example #5
0
    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():
            net.ipv6 = True

        dev, mode = self.get_config_forwarding()
        if mode:
            net.forward.mode = mode
            if mode == "open":
                net.forward.dev = None
            else:
                net.forward.dev = dev or None

        if net.forward.mode == "hostdev":
            net.forward.managed = "yes"
            pfobj = net.forward.pf.add_new()
            pfobj.dev = net.forward.dev
            net.forward.dev = None
            net.domain_name = None
            net.ipv6 = None
            return net

        if self.get_config_ipv4_enable():
            ip = self.get_config_ip4()
            ipobj = net.ips.add_new()
            ipobj.address = str(ip.network_address + 1)
            ipobj.netmask = str(ip.netmask)

            if self.get_config_dhcpv4_enable():
                dhcpobj = ipobj.ranges.add_new()
                dhcpobj.start = str(
                    self.get_config_dhcpv4_start().network_address)
                dhcpobj.end = str(self.get_config_dhcpv4_end().network_address)

        if self.get_config_ipv6_enable():
            ip = self.get_config_ip6()
            ipobj = net.ips.add_new()
            ipobj.family = "ipv6"
            ipobj.address = str(ip.network_address + 1)
            ipobj.prefix = str(ip.prefixlen)

            if self.get_config_dhcpv6_enable():
                dhcpobj = ipobj.ranges.add_new()
                dhcpobj.start = str(
                    self.get_config_dhcpv6_start().network_address)
                dhcpobj.end = str(self.get_config_dhcpv6_end().network_address)

        netaddr = _make_ipaddr(self.get_config_routev4_network())
        gwaddr = _make_ipaddr(self.get_config_routev4_gateway())
        if netaddr and gwaddr:
            route = net.routes.add_new()
            route.family = "ipv4"
            route.address = netaddr.network_address
            route.prefix = netaddr.prefixlen
            route.gateway = gwaddr.network_address

        netaddr = _make_ipaddr(self.get_config_routev6_network())
        gwaddr = _make_ipaddr(self.get_config_routev6_gateway())
        if netaddr and gwaddr:
            route = net.routes.add_new()
            route.family = "ipv6"
            route.address = netaddr.network_address
            route.prefix = netaddr.prefixlen
            route.gateway = gwaddr.network_address

        return net
Example #6
0
 def _build_xmlstub(self):
     return Network(self.conn.get_backend())
Example #7
0
 def _build_xmlobj_from_xmleditor(self):
     xml = self._xmleditor.get_xml()
     log.debug("Using XML from xmleditor:\n%s", xml)
     return Network(self.conn.get_backend(), parsexml=xml)
Example #8
0
    def reset_state(self):
        default_name = Network.find_free_name(self.conn.get_backend(),
                                              "network")
        self.widget("net-name").set_text(default_name)

        self.widget("net-dns-use-netname").set_active(True)

        self.widget("net-ipv4-expander").set_visible(True)
        self.widget("net-ipv4-expander").set_expanded(False)
        self.widget("net-ipv6-expander").set_visible(True)
        self.widget("net-ipv6-expander").set_expanded(False)
        self.widget("net-dns-expander").set_visible(True)
        self.widget("net-dns-expander").set_expanded(False)

        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")

        self.widget("net-ipv6-enable").set_active(False)
        self.widget("net-ipv6-network").set_text("")
        self.widget("net-dhcpv6-enable").set_active(False)
        self.widget("net-dhcpv6-start").set_text("")
        self.widget("net-dhcpv6-end").set_text("")

        # Populate physical forward devices
        devnames = []
        for nodedev in self.conn.filter_nodedevs("net"):
            devnames.append(nodedev.xmlobj.interface)
        for iface in self.conn.list_interfaces():
            if iface.get_name() not in devnames:
                devnames.append(iface.get_name())

        fw_model = self.widget("net-forward-device").get_model()
        fw_model.clear()
        fw_model.append([None, _("Any physical device")])

        for name in devnames:
            fw_model.append([name, _("Physical device %s") % name])
        self.widget("net-forward-device").set_active(0)

        self.widget("net-forward-mode").set_active(0)

        # Populate hostdev forward devices
        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

        pf_model = self.widget("net-hostdevs").get_model()
        pf_model.clear()
        for devprettyname, ifname in zip(devprettynames, ifnames):
            pf_model.append([ifname, devprettyname])
        if len(pf_model) == 0:
            pf_model.append([None, _("No available device")])
        self.widget("net-hostdevs").set_active(0)
Example #9
0
    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():
            net.ipv6 = True

        dev, mode = self.get_config_forwarding()
        if mode:
            net.forward.mode = mode
            if mode == "open":
                net.forward.dev = None
            else:
                net.forward.dev = dev or None

        if net.forward.mode == "hostdev":
            net.forward.managed = "yes"
            pfobj = net.forward.pf.add_new()
            pfobj.dev = net.forward.dev
            net.forward.dev = None
            net.domain_name = None
            net.ipv6 = None
            return net

        if self.get_config_ipv4_enable():
            ip = self.get_config_ip4()
            ipobj = net.ips.add_new()
            ipobj.address = str(ip.network_address + 1)
            ipobj.netmask = str(ip.netmask)

            if self.get_config_dhcpv4_enable():
                dhcpobj = ipobj.ranges.add_new()
                dhcpobj.start = str(
                    self.get_config_dhcpv4_start().network_address
                )
                dhcpobj.end = str(self.get_config_dhcpv4_end().network_address)

        if self.get_config_ipv6_enable():
            ip = self.get_config_ip6()
            ipobj = net.ips.add_new()
            ipobj.family = "ipv6"
            ipobj.address = str(ip.network_address + 1)
            ipobj.prefix = str(ip.prefixlen)

            if self.get_config_dhcpv6_enable():
                dhcpobj = ipobj.ranges.add_new()
                dhcpobj.start = str(
                    self.get_config_dhcpv6_start().network_address
                )
                dhcpobj.end = str(
                    self.get_config_dhcpv6_end().network_address
                )

        netaddr = _make_ipaddr(self.get_config_routev4_network())
        gwaddr = _make_ipaddr(self.get_config_routev4_gateway())
        if netaddr and gwaddr:
            route = net.routes.add_new()
            route.family = "ipv4"
            route.address = netaddr.network_address
            route.prefix = netaddr.prefixlen
            route.gateway = gwaddr.network_address

        netaddr = _make_ipaddr(self.get_config_routev6_network())
        gwaddr = _make_ipaddr(self.get_config_routev6_gateway())
        if netaddr and gwaddr:
            route = net.routes.add_new()
            route.family = "ipv6"
            route.address = netaddr.network_address
            route.prefix = netaddr.prefixlen
            route.gateway = gwaddr.network_address

        return net