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 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)
    copy_tree(consts.TF_TEMPLATE, tf_folder)
    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")

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

        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()