def apply_static_network_config(cluster_name, kube_client): if not args.with_static_network_config: return None tf_folder = utils.get_tf_folder(cluster_name, args.namespace) static_network_config = static_network.generate_static_network_data_from_tf( tf_folder) if args.kube_api: if args.master_count != 1: raise NotImplementedError( "At the moment, KubeAPI workflow supports only single-node clusters" ) mac_to_interface = static_network_config[0]["mac_interface_map"] interfaces = [{ "name": item["logical_nic_name"], "macAddress": item["mac_address"] } for item in mac_to_interface] nmstate_config = NMStateConfig( kube_api_client=kube_client, name=f"{cluster_name}-nmstate-config", namespace=args.namespace, ) nmstate_config.apply( config=yaml.safe_load(static_network_config[0]["network_yaml"]), interfaces=interfaces, label=cluster_name, ) return static_network_config
def prepare_for_install( self, nodes, iso_download_path=env_variables['iso_download_path'], iso_image_type=env_variables['iso_image_type'], ssh_key=env_variables['ssh_public_key'], nodes_count=env_variables['num_nodes'], vip_dhcp_allocation=env_variables['vip_dhcp_allocation'], download_image=True): if download_image: if env_variables.get('static_network_config'): static_network_config = static_network.generate_static_network_data_from_tf( nodes.controller.tf_folder) else: static_network_config = None self.generate_and_download_image( iso_download_path=iso_download_path, iso_image_type=iso_image_type, ssh_key=ssh_key, static_network_config=static_network_config) nodes.start_all() self.wait_until_hosts_are_discovered(nodes_count=nodes_count, allow_insufficient=True) nodes.set_hostnames(self) if self._high_availability_mode != consts.HighAvailabilityMode.NONE: self.set_host_roles() else: nodes.set_single_node_ip(self) self.set_network_params( controller=nodes.controller, vip_dhcp_allocation=vip_dhcp_allocation, ) self.wait_for_ready_to_install()
def execute_day1_flow(cluster_name): client = None cluster = {} if args.managed_dns_domains: args.base_dns_domain = args.managed_dns_domains.split(":")[0] if not args.vm_network_cidr: net_cidr = IPNetwork('192.168.126.0/24') net_cidr += args.ns_index args.vm_network_cidr = str(net_cidr) if not args.vm_network_cidr6: net_cidr = IPNetwork('1001:db8::/120') net_cidr += args.ns_index args.vm_network_cidr6 = str(net_cidr) if not args.network_bridge: args.network_bridge = f'tt{args.ns_index}' set_tf_config(cluster_name) image_path = None image_type = args.iso_image_type if not args.image: utils.recreate_folder(consts.IMAGE_FOLDER, force_recreate=False) client = assisted_service_api.create_client( url=utils.get_assisted_service_url_by_args(args=args)) if args.cluster_id: cluster = client.cluster_get(cluster_id=args.cluster_id) else: cluster = client.create_cluster(cluster_name, ssh_public_key=args.ssh_key, **_cluster_create_params()) image_path = os.path.join(consts.IMAGE_FOLDER, f'{args.namespace}-installer-image.iso') if args.with_static_network_config: tf_folder = utils.get_tf_folder(cluster_name, args.namespace) static_network_config = static_network.generate_static_network_data_from_tf( tf_folder) else: static_network_config = None client.generate_and_download_image( cluster_id=cluster.id, image_path=image_path, image_type=image_type, ssh_key=args.ssh_key, static_network_config=static_network_config, ) # Iso only, cluster will be up and iso downloaded but vm will not be created if not args.iso_only: try: nodes_flow(client, cluster_name, cluster) finally: if not image_path or args.keep_iso: return log.info('deleting iso: %s', image_path) os.unlink(image_path) return cluster.id
def execute_day1_flow(cluster_name): client = None cluster = {} if args.managed_dns_domains: args.base_dns_domain = args.managed_dns_domains.split(":")[0] if not args.vm_network_cidr: net_cidr = IPNetwork('192.168.126.0/24') net_cidr += args.ns_index args.vm_network_cidr = str(net_cidr) if not args.vm_network_cidr6: net_cidr = IPNetwork('1001:db8::/120') net_cidr += args.ns_index args.vm_network_cidr6 = str(net_cidr) if not args.network_bridge: args.network_bridge = f'tt{args.ns_index}' set_tf_config(cluster_name) image_path = None image_url = None image_type = args.iso_image_type kube_client = None cluster_deployment = None machine_net = MachineNetwork(args.ipv4, args.ipv6, args.vm_network_cidr, args.vm_network_cidr6, args.ns_index) if not args.image: utils.recreate_folder(consts.IMAGE_FOLDER, force_recreate=False) client = assisted_service_api.create_client( url=utils.get_assisted_service_url_by_args(args=args)) if args.cluster_id: cluster = client.cluster_get(cluster_id=args.cluster_id) elif args.kube_api: kube_client = create_kube_api_client( str(pathlib.Path("~/.kube/config").expanduser())) cluster_deployment = ClusterDeployment(kube_api_client=kube_client, name=cluster_name, namespace=args.namespace) secret = Secret( kube_api_client=kube_client, name=cluster_name, namespace=args.namespace, ) with contextlib.suppress(ApiException): secret.delete() secret.create(pull_secret=args.pull_secret) ipv4 = args.ipv4 and args.ipv4.lower() in MachineNetwork.YES_VALUES ipv6 = args.ipv6 and args.ipv6.lower() in MachineNetwork.YES_VALUES api_vip, ingress_vip = "", "" with contextlib.suppress(ApiException): cluster_deployment.delete() cluster_deployment.create( platform=Platform( api_vip=api_vip, ingress_vip=ingress_vip, ), install_strategy=InstallStrategy( host_prefix=args.host_prefix if ipv4 else args.host_prefix6, machine_cidr=machine_net.machine_cidr_addresses[0], cluster_cidr=args.cluster_network if ipv4 else args.cluster_network6, service_cidr=args.service_network if ipv4 else args.service_network6, ssh_public_key=args.ssh_key, control_plane_agents=args.master_count, worker_agents=args.number_of_workers, ), secret=secret, base_domain=args.base_dns_domain, ) cluster_deployment.wait_for_state("insufficient") http_proxy, https_proxy, no_proxy = _get_http_proxy_params( ipv4=ipv4, ipv6=ipv6) install_env = InstallEnv(kube_api_client=kube_client, name=f"{cluster_name}-install-env", namespace=args.namespace) with contextlib.suppress(ApiException): install_env.delete() install_env.create(cluster_deployment=cluster_deployment, secret=secret, proxy=Proxy(http_proxy=http_proxy, https_proxy=https_proxy, no_proxy=no_proxy)) install_env.status() image_url = install_env.get_iso_download_url() cluster = client.cluster_get( cluster_id=install_env.get_cluster_id()) else: cluster = client.create_cluster(cluster_name, ssh_public_key=args.ssh_key, **_cluster_create_params()) image_path = os.path.join(consts.IMAGE_FOLDER, f'{args.namespace}-installer-image.iso') if args.with_static_network_config: tf_folder = utils.get_tf_folder(cluster_name, args.namespace) static_network_config = static_network.generate_static_network_data_from_tf( tf_folder) else: static_network_config = None if image_url is not None: utils.download_iso(image_url, image_path) else: client.generate_and_download_image( cluster_id=cluster.id, image_path=image_path, image_type=image_type, ssh_key=args.ssh_key, static_network_config=static_network_config, ) # Iso only, cluster will be up and iso downloaded but vm will not be created if not args.iso_only: try: nodes_flow(client, cluster_name, cluster, machine_net, kube_client, cluster_deployment) finally: if not image_path or args.keep_iso: return log.info('deleting iso: %s', image_path) os.unlink(image_path) return cluster.id