def set_hosts_roles(client, cluster, nodes_details, machine_net, tf,
                    master_count, static_network_mode):
    networks_names = (nodes_details["libvirt_network_name"],
                      nodes_details["libvirt_secondary_network_name"])

    # don't set roles in bip role
    if machine_net.has_ip_v4:
        libvirt_nodes = utils.get_libvirt_nodes_mac_role_ip_and_name(
            networks_names[0])
        libvirt_nodes.update(
            utils.get_libvirt_nodes_mac_role_ip_and_name(networks_names[1]))
        if static_network_mode:
            log.info(
                "Setting hostnames when running in static network config mode")
            update_hostnames = True
        else:
            update_hostnames = False
    else:
        log.warning(
            "Work around libvirt for Terrafrom not setting hostnames of IPv6-only hosts"
        )
        libvirt_nodes = utils.get_libvirt_nodes_from_tf_state(
            networks_names, tf.get_state())
        update_hostnames = True

    utils.update_hosts(client,
                       cluster.id,
                       libvirt_nodes,
                       update_hostnames=update_hostnames,
                       update_roles=master_count > 1)
Пример #2
0
def set_hostnames_from_tf(client, cluster_id, tf_folder, network_name):
    tf = terraform_utils.TerraformUtils(working_dir=tf_folder)
    libvirt_nodes = utils.extract_nodes_from_tf_state(tf.get_state(),
                                                      network_name,
                                                      consts.NodeRoles.WORKER)
    utils.update_hosts(client,
                       cluster_id,
                       libvirt_nodes,
                       update_roles=False,
                       update_hostnames=True)
Пример #3
0
 def set_hostnames(self, cluster, nodes_count: int, is_ipv6: bool, is_static_ip: bool = False):
     if is_ipv6 or is_static_ip:
         # When using IPv6 with libvirt, hostnames are not set automatically by DHCP.  Therefore, we must find out
         # the hostnames using terraform's tfstate file. In case of static ip, the hostname is localhost and must be
         # set to valid hostname
         # TODO - NodeController has no `params` and `tf` attributes
         network_name = self.controller.params.libvirt_network_name
         libvirt_nodes = utils.get_libvirt_nodes_from_tf_state(network_name, self.controller.tf.get_state())
         utils.update_hosts(cluster.api_client, cluster.id, libvirt_nodes, update_hostnames=True,
                            update_roles=(nodes_count != 1))
Пример #4
0
 def set_hostnames(self, cluster):
     ipv6 = env_variables.get('ipv6')
     if ipv6:
         # When using IPv6 with libvirt, hostnames are not set automatically by DHCP.  Therefore, we must find out
         # the hostnames using terraform's tfstate file
         network_name = self.controller.params.libvirt_network_name
         libvirt_nodes = utils.get_libvirt_nodes_from_tf_state(
             network_name, self.controller.tf.get_state())
         utils.update_hosts(cluster.api_client,
                            cluster.id,
                            libvirt_nodes,
                            update_hostnames=True)
Пример #5
0
def set_nodes_hostnames_if_needed(client, tf_folder,
                                  with_static_network_config, has_ipv_6,
                                  network_name, cluster_id):
    if has_ipv_6 or with_static_network_config:
        tf = terraform_utils.TerraformUtils(working_dir=tf_folder)
        libvirt_nodes = utils.extract_nodes_from_tf_state(
            tf.get_state(), network_name, consts.NodeRoles.WORKER)
        log.info(
            "Set hostnames of day2 cluster %s in case of static network configuration or "
            "to work around libvirt for Terrafrom not setting hostnames of IPv6 hosts",
            cluster_id)
        utils.update_hosts(client,
                           cluster_id,
                           libvirt_nodes,
                           update_roles=False,
                           update_hostnames=True)
Пример #6
0
 def set_hostnames(self, cluster):
     ipv6 = env_variables.get('ipv6')
     static_ips_config = env_variables.get('static_ips_config')
     if ipv6 or static_ips_config:
         # When using IPv6 with libvirt, hostnames are not set automatically by DHCP.  Therefore, we must find out
         # the hostnames using terraform's tfstate file. In case of static ip, the hostname is localhost and must be set
         # to valid hostname
         network_name = self.controller.params.libvirt_network_name
         libvirt_nodes = utils.get_libvirt_nodes_from_tf_state(
             network_name, self.controller.tf.get_state())
         nodes_count = env_variables.get('num_nodes')
         utils.update_hosts(cluster.api_client,
                            cluster.id,
                            libvirt_nodes,
                            update_hostnames=True,
                            update_roles=(nodes_count != 1))
def nodes_flow(client, cluster_name, cluster, image_path):
    nodes_details = _create_node_details(cluster_name)
    if cluster:
        nodes_details["cluster_inventory_id"] = cluster.id

    tf_folder = utils.get_tf_folder(cluster_name, args.namespace)
    utils.recreate_folder(tf_folder)

    utils.copy_template_tree(tf_folder, is_none_platform_mode())

    tf = terraform_utils.TerraformUtils(working_dir=tf_folder)
    machine_net = MachineNetwork(args.ipv4, args.ipv6, args.vm_network_cidr,
                                 args.vm_network_cidr6, args.ns_index)

    create_nodes_and_wait_till_registered(cluster_name=cluster_name,
                                          inventory_client=client,
                                          cluster=cluster,
                                          image_path=image_path,
                                          storage_path=args.storage_path,
                                          master_count=args.master_count,
                                          nodes_details=nodes_details,
                                          tf=tf,
                                          machine_net=machine_net)

    if client:
        cluster_info = client.cluster_get(cluster.id)
        macs = utils.get_libvirt_nodes_macs(
            nodes_details["libvirt_network_name"])

        if not (cluster_info.api_vip and cluster_info.ingress_vip):
            utils.wait_till_hosts_with_macs_are_in_status(
                client=client,
                cluster_id=cluster.id,
                macs=macs,
                statuses=[
                    consts.NodesStatus.INSUFFICIENT,
                    consts.NodesStatus.PENDING_FOR_INPUT,
                ],
            )

            if args.vip_dhcp_allocation:
                set_cluster_machine_cidr(client, cluster.id, machine_net)
            else:
                set_cluster_vips(client, cluster.id, machine_net)
        else:
            log.info("VIPs already configured")

        networks_names = (nodes_details["libvirt_network_name"],
                          nodes_details["libvirt_secondary_network_name"])
        if machine_net.has_ip_v4:
            libvirt_nodes = utils.get_libvirt_nodes_mac_role_ip_and_name(
                networks_names[0])
            libvirt_nodes.update(
                utils.get_libvirt_nodes_mac_role_ip_and_name(
                    networks_names[1]))
            update_hostnames = False
        else:
            log.warning(
                "Work around libvirt for Terrafrom not setting hostnames of IPv6-only hosts"
            )
            libvirt_nodes = utils.get_libvirt_nodes_from_tf_state(
                networks_names, tf.get_state())
            update_hostnames = True

        utils.update_hosts(client, cluster.id, libvirt_nodes, update_hostnames)
        utils.wait_till_hosts_with_macs_are_in_status(
            client=client,
            cluster_id=cluster.id,
            macs=macs,
            statuses=[consts.NodesStatus.KNOWN],
        )

        if args.install_cluster:
            time.sleep(10)
            install_cluster.run_install_flow(
                client=client,
                cluster_id=cluster.id,
                kubeconfig_path=consts.DEFAULT_CLUSTER_KUBECONFIG_PATH,
                pull_secret=args.pull_secret,
                tf=tf)
            # Validate DNS domains resolvability
            validate_dns(client, cluster.id)
            if args.wait_for_cvo:
                cluster_info = client.cluster_get(cluster.id)
                log.info("Start waiting till CVO status is available")
                config_etc_hosts(cluster_info.name,
                                 cluster_info.base_dns_domain,
                                 cluster_info.api_vip)
                utils.wait_for_cvo_available()