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_ips.generate_macs(self.params.master_count), 'libvirt_secondary_worker_macs': static_ips.generate_macs(self.params.worker_count) }
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) machine_cidr_addresses = [] provisioning_cidr_addresses = [] if machine_net.has_ip_v4: machine_cidr_addresses += [machine_net.cidr_v4] provisioning_cidr_addresses += [machine_net.provisioning_cidr_v4] if machine_net.has_ip_v6: machine_cidr_addresses += [machine_net.cidr_v6] provisioning_cidr_addresses += [machine_net.provisioning_cidr_v6] tfvars['machine_cidr_addresses'] = machine_cidr_addresses tfvars['provisioning_cidr_addresses'] = provisioning_cidr_addresses tfvars['api_vip'] = _get_vips_ips(machine_net)[0] tfvars['libvirt_storage_pool_path'] = storage_path tfvars['libvirt_master_macs'] = static_ips.generate_macs(master_count) tfvars['libvirt_worker_macs'] = static_ips.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)
def set_workers_addresses_by_type(tfvars, num_worker_nodes, master_ip_type, worker_ip_type, worker_mac_type): 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_ips.generate_macs( num_worker_nodes)
def _fill_tfvars(self, running=True): tfvars_json_file = os.path.join(self.tf_folder, consts.TFVARS_JSON_NAME) logging.info("Filling tfvars") with open(tfvars_json_file) as _file: tfvars = json.load(_file) machine_cidr = self.get_machine_cidr() provisioning_cidr = self._get_provisioning_cidr() logging.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.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 ) tfvars['machine_cidr_addresses'] = [machine_cidr] tfvars['provisioning_cidr_addresses'] = [provisioning_cidr] tfvars['bootstrap_in_place'] = self.bootstrap_in_place tfvars['api_vip'] = self.get_ingress_and_api_vips()["api_vip"] tfvars['running'] = self.params.running tfvars['libvirt_master_macs'] = static_ips.generate_macs(self.params.master_count) tfvars['libvirt_worker_macs'] = static_ips.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)
def _secondary_tfvars(master_count, nodes_details, machine_net): vars_dict = {} vars_dict['libvirt_secondary_master_macs'] = static_ips.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_ips.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