示例#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)
示例#2
0
def workflow(name, params):
    # Get the name from the current image in the source family.
    source_image = gcloud.describe_image_family(
        params["source_image_family"], project=params["source_image_project"])

    # Promote the testing image to the production image.
    gcloud.create_image(
        source_image["name"].replace("-testing", ""),
        project=params["project"],
        family=name,
        guest_os_features=params.get("guest_os_features", []),
        licenses=params.get("licenses", []),
        source_image_family=params["source_image_family"],
        source_image_project=params["source_image_project"],
    )
示例#3
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)