Exemplo n.º 1
0
def workflow(name, params, git_commit):
    instance_name = "%s-image-%s" % (name, int(datetime.now().timestamp()))
    try:
        # Create the VM.
        create_instance(instance_name, params, git_commit)

        # Wait for the VM to become ready.
        gcloud_utils.wait_for_instance(instance_name,
                                       zone=LOCATION,
                                       status='RUNNING')

        if 'windows' in instance_name:
            # Wait for VM to be ready, then print setup instructions.
            tail_start = print_windows_instructions(instance_name)
            # Continue printing the serial console until the VM shuts down.
            gcloud_utils.tail_serial_console(instance_name,
                                             zone=LOCATION,
                                             start=tail_start)
        else:
            # Continuously print the serial console.
            gcloud_utils.tail_serial_console(instance_name, zone=LOCATION)

        # Wait for the VM to completely shutdown.
        gcloud_utils.wait_for_instance(instance_name,
                                       zone=LOCATION,
                                       status='TERMINATED')

        # Create a new image from our VM.
        gcloud.create_image(instance_name,
                            family=name,
                            source_disk=instance_name,
                            source_disk_zone=LOCATION,
                            licenses=params.get('licenses', []))
    finally:
        gcloud.delete_instance(instance_name, zone=LOCATION)
def workflow(zone, cpu_platform, machine_type, image, local_ssd,
             boot_disk_size):
    instance_name = "benchmark-ubuntu-" + str(uuid4())
    try:
        # Create the VM.
        create_instance(instance_name, zone, cpu_platform, machine_type, image,
                        local_ssd, boot_disk_size)

        # Wait for the VM to become ready.
        gcloud_utils.wait_for_instance(instance_name,
                                       zone=zone,
                                       status="RUNNING")

        # Wait for benchmark to complete.
        gcloud_utils.tail_serial_console(instance_name,
                                         zone=zone,
                                         until="=== BENCHMARK COMPLETE ===")

        log = fetch_benchmark_log(instance_name, zone)
        results = parse_benchmark_log(instance_name, zone, log)
        results["requested_cpu_platform"] = cpu_platform
        results["machine_type"] = machine_type
        results["image"] = image
        results["local_ssd"] = local_ssd
        results["boot_disk_size"] = boot_disk_size

        with open(os.path.join("results", instance_name + ".json"), "w") as f:
            json.dump(results, f)

        with open(os.path.join("results", "combined.csv"), "a",
                  newline="") as f:
            results_writer = csv.writer(f)
            results_writer.writerow([
                results["timestamp"],
                results["instance_name"],
                results["zone"],
                results["cpu_count"],
                results["ram_gb"],
                results["requested_cpu_platform"],
                results["cpu_platform"],
                results["machine_type"],
                results["image"],
                results["local_ssd"],
                results["boot_disk_size"],
                "{0:.4f}".format(results["bazel_info_duration_secs"]),
                "{0:.4f}".format(results["bazel_fetch_duration_secs"]),
                "{0:.4f}".format(results["bazel_build_duration_secs"]),
                "{0:.4f}".format(results["bazel_test_duration_secs"]),
                "{0:.4f}".format(results["bazel_clean_duration_secs"]),
            ])
    finally:
        try:
            gcloud.delete_instance(instance_name)
        except Exception:
            pass
def workflow(zone, cpu_platform, machine_type, image, local_ssd,
             boot_disk_size):
    instance_name = "benchmark-ubuntu-" + str(uuid4())
    try:
        # Create the VM.
        create_instance(instance_name, zone, cpu_platform, machine_type, image,
                        local_ssd, boot_disk_size)

        # Wait for the VM to become ready.
        gcloud_utils.wait_for_instance(instance_name,
                                       zone=zone,
                                       status='RUNNING')

        # Wait for benchmark to complete.
        gcloud_utils.tail_serial_console(instance_name,
                                         zone=zone,
                                         until='=== BENCHMARK COMPLETE ===')

        log = fetch_benchmark_log(instance_name, zone)
        results = parse_benchmark_log(instance_name, zone, log)
        results['requested_cpu_platform'] = cpu_platform
        results['machine_type'] = machine_type
        results['image'] = image
        results['local_ssd'] = local_ssd
        results['boot_disk_size'] = boot_disk_size

        with open(os.path.join('results', instance_name + '.json'), 'w') as f:
            json.dump(results, f)

        with open(os.path.join('results', 'combined.csv'), 'a',
                  newline='') as f:
            results_writer = csv.writer(f, )
            results_writer.writerow([
                results['timestamp'], results['instance_name'],
                results['zone'], results['cpu_count'], results['ram_gb'],
                results['requested_cpu_platform'], results['cpu_platform'],
                results['machine_type'], results['image'],
                results['local_ssd'], results['boot_disk_size'],
                "{0:.4f}".format(results['bazel_info_duration_secs']),
                "{0:.4f}".format(results['bazel_fetch_duration_secs']),
                "{0:.4f}".format(results['bazel_build_duration_secs']),
                "{0:.4f}".format(results['bazel_test_duration_secs']),
                "{0:.4f}".format(results['bazel_clean_duration_secs'])
            ])
    finally:
        try:
            gcloud.delete_instance(instance_name)
        except Exception:
            pass
Exemplo n.º 4
0
def workflow(name, params):
    instance_name = "%s-image-%s" % (name, int(datetime.now().timestamp()))
    project = params["project"]
    zone = params["zone"]
    try:
        # Create the VM.
        create_instance(instance_name, params)

        # Wait for the VM to become ready.
        gcloud_utils.wait_for_instance(instance_name,
                                       project=project,
                                       zone=zone,
                                       status="RUNNING")

        if "windows" in instance_name:
            # Wait for VM to be ready, then print setup instructions.
            tail_start = print_windows_instructions(project, zone,
                                                    instance_name)
            # Continue printing the serial console until the VM shuts down.
            gcloud_utils.tail_serial_console(instance_name,
                                             project=project,
                                             zone=zone,
                                             start=tail_start)
        else:
            # Continuously print the serial console.
            gcloud_utils.tail_serial_console(instance_name,
                                             project=project,
                                             zone=zone)

        # Wait for the VM to completely shutdown.
        gcloud_utils.wait_for_instance(instance_name,
                                       project=project,
                                       zone=zone,
                                       status="TERMINATED")

        # Create a new image from our VM.
        gcloud.create_image(
            instance_name,
            project=project,
            family=name,
            source_disk=instance_name,
            source_disk_zone=zone,
            licenses=params.get("licenses", []),
            guest_os_features=params.get("guest_os_features", []),
        )
    finally:
        gcloud.delete_instance(instance_name, project=project, zone=zone)
def single_instance_task(instance_name, zone, **kwargs):
    if gcloud.delete_instance(instance_name, zone=zone).returncode == 0:
        print('Deleted existing instance: {}'.format(instance_name))

    gcloud.create_instance(instance_name, zone=zone, **kwargs)