def fill_tfvars(image_path, storage_path, master_count, nodes_details, tf_folder): 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( nodes_details["machine_cidr"]).network_address) + 10) worker_starting_ip = str( ipaddress.ip_address( ipaddress.IPv4Network( nodes_details["machine_cidr"]).network_address) + 10 + int(tfvars["master_count"])) master_count = min(master_count, consts.NUMBER_OF_MASTERS) tfvars['image_path'] = image_path tfvars['master_count'] = master_count tfvars['libvirt_master_ips'] = utils.create_ip_address_list( master_count, starting_ip_addr=master_starting_ip) tfvars['libvirt_worker_ips'] = utils.create_ip_address_list( nodes_details['worker_count'], starting_ip_addr=worker_starting_ip) tfvars['api_vip'] = _get_vips_ips()[0] tfvars['libvirt_storage_pool_path'] = storage_path tfvars.update(nodes_details) tfvars.update(_secondary_tfvars(master_count, nodes_details)) with open(tfvars_json_file, "w") as _file: json.dump(tfvars, _file)
def _get_vips_ips(): network_subnet_starting_ip = str( ipaddress.ip_address( ipaddress.IPv4Network(args.vm_network_cidr).network_address) + 100) ips = utils.create_ip_address_list( 2, starting_ip_addr=str(ipaddress.ip_address(network_subnet_starting_ip))) return ips[0], ips[1]
def _secondary_tfvars(master_count, nodes_details): secondary_master_starting_ip = str( ipaddress.ip_address( ipaddress.IPv4Network( nodes_details['provisioning_cidr']).network_address) + 10) secondary_worker_starting_ip = str( ipaddress.ip_address( ipaddress.IPv4Network( nodes_details['provisioning_cidr']).network_address) + 10 + int(master_count)) return { 'libvirt_secondary_worker_ips': utils.create_ip_address_list( nodes_details['worker_count'], starting_ip_addr=secondary_worker_starting_ip), 'libvirt_secondary_master_ips': utils.create_ip_address_list( master_count, starting_ip_addr=secondary_master_starting_ip) }
def set_workers_ips_by_type(tfvars, num_worker_nodes, master_ip_type, worker_ip_type): master_end_ip = tfvars[master_ip_type][-1] workers_ip_list = tfvars[worker_ip_type] if not workers_ip_list: worker_starting_ip = ipaddress.ip_address(master_end_ip) else: worker_starting_ip = ipaddress.ip_address(tfvars[worker_ip_type][-1]) worker_ips_list = workers_ip_list + utils.create_ip_address_list( num_worker_nodes, worker_starting_ip + 1) tfvars[worker_ip_type] = worker_ips_list