def _fill_tfvars(self, running=True):
        tfvars_json_file = os.path.join(self.tf_folder,
                                        consts.TFVARS_JSON_NAME)
        log.info("Filling tfvars")
        with open(tfvars_json_file) as _file:
            tfvars = json.load(_file)

        machine_cidr = self.get_primary_machine_cidr()

        log.info("Machine cidr is: %s", machine_cidr)
        master_starting_ip = str(
            ipaddress.ip_address(
                ipaddress.ip_network(machine_cidr).network_address) + 10)
        worker_starting_ip = str(
            ipaddress.ip_address(
                ipaddress.ip_network(machine_cidr).network_address) + 10 +
            int(tfvars["master_count"]))
        tfvars["image_path"] = self._entity_config.iso_download_path
        tfvars[
            "worker_image_path"] = self._entity_config.worker_iso_download_path or tfvars[
                "image_path"]
        tfvars["master_count"] = self.params.master_count
        self.master_ips = tfvars[
            "libvirt_master_ips"] = self._create_address_list(
                self.params.master_count, starting_ip_addr=master_starting_ip)
        tfvars["libvirt_worker_ips"] = self._create_address_list(
            self.params.worker_count, starting_ip_addr=worker_starting_ip)
        if self._config.ingress_dns:
            for service in [
                    "console-openshift-console", "canary-openshift-ingress",
                    "oauth-openshift"
            ]:
                self.params["libvirt_dns_records"][".".join([
                    service, "apps", self._config.cluster_name,
                    self._entity_config.base_dns_domain
                ])] = tfvars["libvirt_worker_ips"][0][0]
        tfvars["machine_cidr_addresses"] = self.get_all_machine_addresses()
        tfvars[
            "provisioning_cidr_addresses"] = self.get_all_provisioning_addresses(
            )
        tfvars["bootstrap_in_place"] = self._config.bootstrap_in_place

        vips = self.get_ingress_and_api_vips()
        tfvars["api_vip"] = vips["api_vip"]
        tfvars["ingress_vip"] = vips["ingress_vip"]
        tfvars["running"] = running
        tfvars["libvirt_master_macs"] = static_network.generate_macs(
            self.params.master_count)
        tfvars["libvirt_worker_macs"] = static_network.generate_macs(
            self.params.worker_count)
        tfvars["master_boot_devices"] = self.params.master_boot_devices
        tfvars["worker_boot_devices"] = self.params.worker_boot_devices
        tfvars.update(self.params)
        tfvars.update(self._secondary_tfvars())

        with open(tfvars_json_file, "w") as _file:
            json.dump(tfvars, _file)
def fill_tfvars(
        image_path,
        storage_path,
        master_count,
        nodes_details,
        tf_folder,
        machine_net
):
    tfvars_json_file = os.path.join(tf_folder, consts.TFVARS_JSON_NAME)
    with open(tfvars_json_file) as _file:
        tfvars = json.load(_file)

    master_starting_ip = str(
        ipaddress.ip_address(
            ipaddress.IPv4Network(machine_net.cidr_v4).network_address
        )
        + 10
    )
    worker_starting_ip = str(
        ipaddress.ip_address(
            ipaddress.IPv4Network(machine_net.cidr_v4).network_address
        )
        + 10
        + int(tfvars["master_count"])
    )
    master_count = min(master_count, consts.NUMBER_OF_MASTERS)
    worker_count = nodes_details['worker_count']
    tfvars['image_path'] = image_path
    tfvars['master_count'] = master_count
    if machine_net.has_ip_v4:
        tfvars['libvirt_master_ips'] = utils.create_ip_address_nested_list(
            master_count, starting_ip_addr=master_starting_ip
        )
        tfvars['libvirt_worker_ips'] = utils.create_ip_address_nested_list(
            worker_count, starting_ip_addr=worker_starting_ip
        )
    else:
        tfvars['libvirt_master_ips'] = utils.create_empty_nested_list(master_count)
        tfvars['libvirt_worker_ips'] = utils.create_empty_nested_list(worker_count)

    tfvars['machine_cidr_addresses'] = machine_net.machine_cidr_addresses
    tfvars['provisioning_cidr_addresses'] = machine_net.provisioning_cidr_addresses
    tfvars['api_vip'] = _get_vips_ips(machine_net)[0]
    tfvars['libvirt_storage_pool_path'] = storage_path
    tfvars['libvirt_master_macs'] = static_network.generate_macs(master_count)
    tfvars['libvirt_worker_macs'] = static_network.generate_macs(worker_count)
    tfvars.update(nodes_details)

    tfvars.update(_secondary_tfvars(master_count, nodes_details, machine_net))

    with open(tfvars_json_file, "w") as _file:
        json.dump(tfvars, _file)
예제 #3
0
    def set_workers_addresses_by_type(self, tfvars: Any, num_worker_nodes: int,
                                      master_ip_type: str, worker_ip_type: str,
                                      worker_mac_type: str):

        old_worker_ips_list = tfvars[worker_ip_type]
        last_master_addresses = tfvars[master_ip_type][-1]

        if last_master_addresses:
            if old_worker_ips_list:
                worker_starting_ip = ipaddress.ip_address(
                    old_worker_ips_list[-1][0])
            else:
                worker_starting_ip = ipaddress.ip_address(
                    last_master_addresses[0])

            worker_ips_list = old_worker_ips_list + utils.create_ip_address_nested_list(
                num_worker_nodes, worker_starting_ip + 1)
        else:
            log.info(
                "IPv6-only environment. IP addresses are left empty and will be allocated by libvirt "
                "DHCP because of a bug in Terraform plugin")
            worker_ips_list = old_worker_ips_list + utils.create_empty_nested_list(
                num_worker_nodes)

        tfvars[worker_ip_type] = worker_ips_list

        old_worker_mac_addresses = tfvars[worker_mac_type]
        tfvars[
            worker_mac_type] = old_worker_mac_addresses + static_network.generate_macs(
                num_worker_nodes)
def _secondary_tfvars(master_count, nodes_details, machine_net):
    vars_dict = {'libvirt_secondary_master_macs': static_network.generate_macs(master_count)}
    if machine_net.has_ip_v4:
        secondary_master_starting_ip = str(
            ipaddress.ip_address(
                ipaddress.IPv4Network(machine_net.provisioning_cidr_v4).network_address
            )
            + 10
        )
        secondary_worker_starting_ip = str(
            ipaddress.ip_address(
                ipaddress.IPv4Network(machine_net.provisioning_cidr_v4).network_address
            )
            + 10
            + int(master_count)
        )
    else:
        secondary_master_starting_ip = str(
            ipaddress.ip_address(
                ipaddress.IPv6Network(machine_net.provisioning_cidr_v6).network_address
            )
            + 16
        )
        secondary_worker_starting_ip = str(
            ipaddress.ip_address(
                ipaddress.IPv6Network(machine_net.provisioning_cidr_v6).network_address
            )
            + 16
            + int(master_count)
        )

    worker_count = nodes_details['worker_count']
    vars_dict['libvirt_secondary_worker_macs'] = static_network.generate_macs(worker_count)
    if machine_net.has_ip_v4:
        vars_dict['libvirt_secondary_master_ips'] = utils.create_ip_address_nested_list(
            master_count,
            starting_ip_addr=secondary_master_starting_ip
        )
        vars_dict['libvirt_secondary_worker_ips'] = utils.create_ip_address_nested_list(
            worker_count,
            starting_ip_addr=secondary_worker_starting_ip
        )
    else:
        vars_dict['libvirt_secondary_master_ips'] = utils.create_empty_nested_list(master_count)
        vars_dict['libvirt_secondary_worker_ips'] = utils.create_empty_nested_list(worker_count)
    return vars_dict
예제 #5
0
 def _secondary_tfvars(self):
     provisioning_cidr = self.get_provisioning_cidr()
     secondary_master_starting_ip = str(
         ipaddress.ip_address(ipaddress.ip_network(provisioning_cidr).network_address) + 10
     )
     secondary_worker_starting_ip = str(
         ipaddress.ip_address(ipaddress.ip_network(provisioning_cidr).network_address)
         + 10
         + int(self.params.master_count)
     )
     return {
         "libvirt_secondary_worker_ips": self._create_address_list(
             self.params.worker_count, starting_ip_addr=secondary_worker_starting_ip
         ),
         "libvirt_secondary_master_ips": self._create_address_list(
             self.params.master_count, starting_ip_addr=secondary_master_starting_ip
         ),
         "libvirt_secondary_master_macs": static_network.generate_macs(self.params.master_count),
         "libvirt_secondary_worker_macs": static_network.generate_macs(self.params.worker_count),
     }
예제 #6
0
    def _fill_tfvars(self, running=True):
        tfvars_json_file = os.path.join(self.tf_folder, consts.TFVARS_JSON_NAME)
        log.info("Filling tfvars")
        with open(tfvars_json_file) as _file:
            tfvars = json.load(_file)

        machine_cidr = self.get_primary_machine_cidr()

        log.info("Machine cidr is: %s", machine_cidr)
        master_starting_ip = str(ipaddress.ip_address(ipaddress.ip_network(machine_cidr).network_address) + 10)
        worker_starting_ip = str(
            ipaddress.ip_address(ipaddress.ip_network(machine_cidr).network_address) + 10 + int(tfvars["master_count"])
        )
        tfvars["image_path"] = self._entity_config.iso_download_path
        tfvars["master_count"] = self.params.master_count
        self.master_ips = tfvars["libvirt_master_ips"] = self._create_address_list(
            self.params.master_count, starting_ip_addr=master_starting_ip
        )
        tfvars["libvirt_worker_ips"] = self._create_address_list(
            self.params.worker_count, starting_ip_addr=worker_starting_ip
        )
        tfvars["machine_cidr_addresses"] = self.get_all_machine_addresses()
        tfvars["provisioning_cidr_addresses"] = self.get_all_provisioning_addresses()
        tfvars["bootstrap_in_place"] = self._config.bootstrap_in_place

        vips = self.get_ingress_and_api_vips()
        tfvars["api_vip"] = vips["api_vip"]
        tfvars["ingress_vip"] = vips["ingress_vip"]
        tfvars["running"] = running
        tfvars["libvirt_master_macs"] = static_network.generate_macs(self.params.master_count)
        tfvars["libvirt_worker_macs"] = static_network.generate_macs(self.params.worker_count)
        tfvars.update(self.params)
        tfvars.update(self._secondary_tfvars())

        with open(tfvars_json_file, "w") as _file:
            json.dump(tfvars, _file)