def print_windows_instructions(instance_name):
    tail_start = gcloud_utils.tail_serial_console(
        instance_name, zone=LOCATION, until="Finished running startup scripts")

    pw = json.loads(
        gcloud.reset_windows_password(instance_name,
                                      format="json",
                                      zone=LOCATION).stdout)
    rdp_file = tempfile.mkstemp(suffix=".rdp")[1]
    with open(rdp_file, "w") as f:
        f.write("full address:s:" + pw["ip_address"] + "\n")
        f.write("username:s:" + pw["username"] + "\n")
    subprocess.run(["open", rdp_file])
    write_to_clipboard(pw["password"])
    with gcloud.PRINT_LOCK:
        print("Use this password to connect to the Windows VM: " +
              pw["password"])
        print(
            "Please run the setup script C:\\setup.ps1 once you're logged in.")

    # Wait until the VM reboots once, then open RDP again.
    tail_start = gcloud_utils.tail_serial_console(
        instance_name,
        zone=LOCATION,
        start=tail_start,
        until="Finished running startup scripts")
    print("Connecting via RDP a second time to finish the setup...")
    write_to_clipboard(pw["password"])
    run(["open", rdp_file])
    return tail_start
Exemplo n.º 2
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)
Exemplo n.º 3
0
def print_windows_instructions(instance_name):
    tail_start = gcloud_utils.tail_serial_console(
        instance_name, zone=LOCATION, until='Finished running startup scripts')

    pw = json.loads(
        gcloud.reset_windows_password(instance_name,
                                      format='json',
                                      zone=LOCATION).stdout)
    rdp_file = tempfile.mkstemp(suffix='.rdp')[1]
    with open(rdp_file, 'w') as f:
        f.write('full address:s:' + pw['ip_address'] + '\n')
        f.write('username:s:' + pw['username'] + '\n')
    subprocess.run(['open', rdp_file])
    write_to_clipboard(pw['password'])
    with gcloud.PRINT_LOCK:
        print('Use this password to connect to the Windows VM: ' +
              pw['password'])
        print(
            'Please run the setup script C:\\setup.ps1 once you\'re logged in.'
        )

    # Wait until the VM reboots once, then open RDP again.
    tail_start = gcloud_utils.tail_serial_console(
        instance_name,
        zone=LOCATION,
        start=tail_start,
        until='Finished running startup scripts')
    print('Connecting via RDP a second time to finish the setup...')
    write_to_clipboard(pw['password'])
    run(['open', rdp_file])
    return tail_start
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.º 6
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)