예제 #1
0
def execute_day2_flow(cluster_id, args, day2_type_flag):
    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))
    cluster = client.cluster_get(cluster_id=cluster_id)
    cluster_name = cluster.name
    openshift_version = cluster.openshift_version
    api_vip_dnsname = "api." + cluster_name + "." + cluster.base_dns_domain
    api_vip_ip = cluster.api_vip
    terraform_cluster_dir_prefix = cluster_name
    if day2_type_flag == "ocp":
        terraform_cluster_dir_prefix = "test-infra-cluster-assisted-installer"
    else:
        cluster_id = str(uuid.uuid4())
        cluster = client.create_day2_cluster(
            cluster_name + "-day2", cluster_id,
            **_day2_cluster_create_params(openshift_version, api_vip_dnsname))
        set_cluster_pull_secret(client, cluster_id, args.pull_secret)

    config_etc_hosts(api_vip_ip, api_vip_dnsname)
    image_path = os.path.join(consts.IMAGE_FOLDER,
                              f'{args.namespace}-installer-image.iso')
    client.generate_and_download_image(
        cluster_id=cluster.id,
        image_path=image_path,
        ssh_key=args.ssh_key,
    )

    day2_nodes_flow(client, terraform_cluster_dir_prefix, cluster, image_path,
                    args.number_of_day2_workers, api_vip_ip, api_vip_dnsname,
                    args.namespace, args.install_cluster, day2_type_flag)
예제 #2
0
def execute_day2_flow(ocp_cluster_id, args):
    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))
    ocp_cluster = client.cluster_get(cluster_id=ocp_cluster_id)
    ocp_cluster_name = ocp_cluster.name
    ocp_openshift_version = ocp_cluster.openshift_version
    ocp_api_vip_dnsname = "api." + ocp_cluster_name + "." + ocp_cluster.base_dns_domain
    ocp_api_vip_ip = ocp_cluster.api_vip
    cluster_id = str(uuid.uuid4())
    cluster = client.create_day2_cluster(
        ocp_cluster_name + "-day2", cluster_id,
        **_day2_cluster_create_params(ocp_openshift_version,
                                      ocp_api_vip_dnsname))

    set_cluster_pull_secret(client, cluster_id, args.pull_secret)

    image_path = os.path.join(consts.IMAGE_FOLDER,
                              f'{args.namespace}-installer-image.iso')
    client.generate_and_download_image(
        cluster_id=cluster.id,
        image_path=image_path,
        ssh_key=args.ssh_key,
    )

    day2_nodes_flow(client, ocp_cluster_name, cluster, image_path,
                    args.number_of_day2_workers, ocp_api_vip_ip,
                    ocp_api_vip_dnsname, args.namespace, args.install_cluster)
예제 #3
0
def get_ocp_cluster(args):
    if not args.cluster_id:
        cluster_name = f'{args.cluster_name or consts.CLUSTER_PREFIX}-{args.namespace}'
        tf_folder = utils.get_tf_folder(cluster_name, args.namespace)
        args.cluster_id = utils.get_tfvars(tf_folder)['cluster_inventory_id']
    client = assisted_service_api.create_client(
        url=utils.get_assisted_service_url_by_args(args=args))
    return client.cluster_get(cluster_id=args.cluster_id)
예제 #4
0
def main():
    client = None
    cluster = {}

    internal_cluster_name = f'{args.cluster_name or consts.CLUSTER_PREFIX}-{args.namespace}'
    log.info('Cluster name: %s', internal_cluster_name)

    image_folder = os.path.join(consts.BASE_IMAGE_FOLDER,
                                internal_cluster_name)
    log.info('Image folder: %s', image_folder)

    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.network_bridge:
        args.network_bridge = f'tt{args.ns_index}'

    image_path = None

    # If image is passed, there is no need to create cluster and download image, need only to spawn vms with is image
    if not args.image:
        utils.recreate_folder(image_folder)
        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:
            random_postfix = str(uuid.uuid4())[:8]
            ui_cluster_name = internal_cluster_name + f'-{random_postfix}'
            log.info('Cluster name on UI: %s', ui_cluster_name)

            cluster = client.create_cluster(ui_cluster_name,
                                            ssh_public_key=args.ssh_key,
                                            **_cluster_create_params())

        image_path = os.path.join(image_folder, consts.IMAGE_NAME)
        client.generate_and_download_image(
            cluster_id=cluster.id,
            image_path=image_path,
            ssh_key=args.ssh_key,
        )

    # Iso only, cluster will be up and iso downloaded but vm will not be created
    if not args.iso_only:
        try:
            nodes_flow(client, internal_cluster_name, cluster, args.image
                       or image_path)
        finally:
            if not image_path or args.keep_iso:
                return
            log.info('deleting iso: %s', image_path)
            os.unlink(image_path)
예제 #5
0
def try_to_delete_cluster(namespace, tfvars):
    """ Try to delete cluster if assisted-service is up and such cluster
        exists.
    """
    cluster_id = tfvars.get('cluster_inventory_id')
    if not cluster_id:
        return

    args.namespace = namespace
    client = assisted_service_api.create_client(
        url=utils.get_assisted_service_url_by_args(args=args, wait=False))
    client.delete_cluster(cluster_id=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.network_bridge:
        args.network_bridge = f'tt{args.ns_index}'

    image_path = None

    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'
        )
        client.generate_and_download_image(
            cluster_id=cluster.id,
            image_path=image_path,
            ssh_key=args.ssh_key,
        )

    # 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, args.image or image_path)
        finally:
            if not image_path or args.keep_iso:
                return
            log.info('deleting iso: %s', image_path)
            os.unlink(image_path)
def main():
    _verify_kube_download_folder(args.kubeconfig_path)
    log.info("Creating assisted service client")
    # if not cluster id is given, reads it from latest run
    if not args.cluster_id:
        cluster_name = f'{args.cluster_name or consts.CLUSTER_PREFIX}-{args.namespace}'
        tf_folder = utils.get_tf_folder(cluster_name, args.namespace)
        args.cluster_id = utils.get_tfvars(tf_folder)['cluster_inventory_id']

    client = assisted_service_api.create_client(
        url=utils.get_assisted_service_url_by_args(args=args, wait=False))
    run_install_flow(
        client=client,
        cluster_id=args.cluster_id,
        kubeconfig_path=args.kubeconfig_path,
        pull_secret=args.pull_secret,
    )
예제 #8
0
def execute_day2_flow(cluster_name, args):
    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))
    cluster_id = str(uuid.uuid4())
    cluster = client.create_day2_cluster(cluster_name, cluster_id,
                                         **_day2_cluster_create_params(args))

    set_cluster_pull_secret(client, cluster_id, args.pull_secret)

    image_path = os.path.join(consts.IMAGE_FOLDER,
                              f'{args.namespace}-installer-image.iso')
    client.generate_and_download_image(
        cluster_id=cluster.id,
        image_path=image_path,
        ssh_key=args.ssh_key,
    )

    day2_nodes_flow(client, cluster_name, cluster, image_path,
                    args.number_of_workers, args.api_vip_ip,
                    args.api_vip_dnsname, args.namespace, args.install_cluster)
예제 #9
0
def main():
    args = handle_arguments()
    client = create_client(url=args.inventory_url)

    if args.cluster_id:
        cluster = client.cluster_get(args.cluster_id)
        download_logs(
            client,
            json.loads(
                json.dumps(cluster.to_dict(), sort_keys=True, default=str)),
            args.dest)
    else:
        clusters = client.clusters_list()

        if not clusters:
            log.info('No clusters were found')
            return

        for cluster in clusters:
            if args.download_all or should_download_logs(cluster):
                download_logs(client, cluster, args.dest)

        print(Counter(map(lambda cluster: cluster['status'], clusters)))
예제 #10
0
 def api_client(self):
     client = assisted_service_api.create_client(
         env_variables['REMOTE_SERVICE_URL'])
     self.delete_cluster_if_exists(
         api_client=client, cluster_name=env_variables['CLUSTER_NAME'])
     return client