def write_lxc_net_config(self):
        """Finds and configures a new subnet for the host container,
        to avoid overlapping with IPs used for Neutron.
        """
        lxc_net_template = utils.load_template('lxc-net')
        lxc_net_container_filename = os.path.join(self.container_abspath,
                                                  'rootfs/etc/default/lxc-net')

        network = netutils.get_unique_lxc_network()
        self.config.setopt('lxc_network', network)

        nw = IPv4Network(network)
        addr = nw[1]
        netmask = nw.with_netmask.split('/')[-1]
        net_low, net_high = netutils.ip_range_max(nw, [addr])
        dhcp_range = "{},{}".format(net_low, net_high)
        render_parts = dict(addr=addr,
                            netmask=netmask,
                            network=network,
                            dhcp_range=dhcp_range)
        lxc_net = lxc_net_template.render(render_parts)
        name = self.container_name
        log.info("Writing lxc-net config for {}".format(name))
        utils.spew(lxc_net_container_filename, lxc_net)

        return network
Example #2
0
    def write_lxc_net_config(self):
        """Finds and configures a new subnet for the host container,
        to avoid overlapping with IPs used for Neutron.
        """
        lxc_net_template = utils.load_template('lxc-net')
        lxc_net_container_filename = os.path.join(
            self.container_abspath, 'rootfs/etc/default/lxc-net')

        network = netutils.get_unique_lxc_network()
        self.config.setopt('lxc_network', network)

        nw = IPv4Network(network)
        addr = nw[1]
        netmask = nw.with_netmask.split('/')[-1]
        net_low, net_high = netutils.ip_range_max(nw, [addr])
        dhcp_range = "{},{}".format(net_low, net_high)
        render_parts = dict(addr=addr,
                            netmask=netmask,
                            network=network,
                            dhcp_range=dhcp_range)
        lxc_net = lxc_net_template.render(render_parts)
        name = self.container_name
        log.info("Writing lxc-net config for {}".format(name))
        utils.spew(lxc_net_container_filename, lxc_net)

        return network
    def prompt_for_bridge(self):
        # TODO prompt user to ask about bridging maas nw interface
        self.should_bridge_maasnw = True
        self.display_controller.info_message("Configuring MAAS Network")

        if self.should_bridge_maasnw:
            log.debug("bridging maas network")
            self.configure_nat(get_network('br0'))
            log.debug("configured NAT")
            self.enable_ipv4_forwarding()
            log.debug("enabled forwarding")
            self.gateway = get_ip_addr('br0')
            excludes = [self.iface_ip]
        else:
            self.gateway = get_default_gateway()
            excludes = [self.iface_ip, self.gateway]

        excludes = list(map(ip_address, excludes))
        nw = ip_network(self.iface_network, strict=False)
        self.dhcp_range = ip_range_max(nw, excludes)
        # TODO: allow customization

        self.display_controller.info_message("Detecting Existing DHCP server")
        self.start_task("Searching for existing DHCP servers")
        # TODO Handle existing dhcp with another dialog or user interaction
        # to accept the consequences.
        if self.detect_existing_dhcp(self.target_iface):
            log.error("An existing DHCP server was found on this interface, "
                      "the network may be incorrectly configured.")
            pass
    def prompt_for_dhcp_range(self):
        """ Prompts for configurable dhcp ranges

        :returns: Tuple of low/high ranges
        """
        self.display_controller.info_message(
            "Set the minimum and maximum DHCP ranges for your environment and "
            "optionally set static ip ranges. Both ranges must be the same "
            "network and cannot overlap")

        def set_dhcp_range(ranges):
            self.dhcp_range = (ranges['dhcp_low'].value,
                               ranges['dhcp_high'].value)
            self.static_range = (ranges['static_low'].value,
                                 ranges['static_high'].value)

            self.update_progress()
            self.continue_with_interface()
        nw = ip_network(self.iface_network, strict=False)
        excludes = list(map(ip_address, [self.iface_ip]))
        dhcp_range = ip_range_max(nw, excludes)
        self.display_controller.show_dhcp_range(str(dhcp_range[0]),
                                                str(dhcp_range[1]),
                                                "Define DHCP Range",
                                                set_dhcp_range)
    def prompt_for_dhcp_range(self):
        """ Prompts for configurable dhcp ranges

        :returns: Tuple of low/high ranges
        """
        self.display_controller.status_info_message(
            "Set the minimum and maximum DHCP ranges for your environment and "
            "optionally set static ip ranges. Both ranges must be the same "
            "network and cannot overlap")

        def set_dhcp_range(ranges):
            self.dhcp_range = (ranges['dhcp_low'].value,
                               ranges['dhcp_high'].value)
            self.static_range = (ranges['static_low'].value,
                                 ranges['static_high'].value)

            self.continue_with_interface()

        nw = ip_network(self.iface_network, strict=False)
        excludes = list(map(ip_address, [self.iface_ip]))
        dhcp_range = ip_range_max(nw, excludes)
        self.display_controller.show_dhcp_range(str(dhcp_range[0]),
                                                str(dhcp_range[1]),
                                                "Define DHCP Range",
                                                set_dhcp_range)