pycloudlib.gce.cloud module

GCE Cloud type.

This is an initial implementation of the GCE class. It enables authentication into the cloud, finding an image, and launching an instance. It however, does not allow any further actions from occurring.

class pycloudlib.gce.cloud.GCE(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, credentials_path: str | None = None, project: str | None = None, region: str | None = None, zone: str | None = None, service_account_email: str | None = None)[source]

Bases: BaseCloud

GCE Cloud Class.

__init__(tag: str, timestamp_suffix: bool = True, config_file: Path | StringIO | None = None, *, credentials_path: str | None = None, project: str | None = None, region: str | None = None, zone: str | None = None, service_account_email: str | None = None)[source]

Initialize the connection to GCE.

Parameters:
  • tag – string used to name and tag resources with

  • timestamp_suffix – bool set True to append a timestamp suffix to the tag

  • config_file – path to pycloudlib configuration file

  • credentials_path – path to credentials file for GCE

  • project – GCE project

  • region – GCE region

  • zone – GCE zone

  • service_account_email – service account to bind launched instances to

daily_image(release: str, *, arch: str = 'x86_64', image_type: ImageType = ImageType.GENERIC, **kwargs)[source]

Find the id of the latest image for a particular release.

Parameters:

release – string, Ubuntu release to look for

Returns:

string, path to latest daily image

delete_image(image_id, **kwargs)[source]

Delete an image.

Parameters:

image_id – string, id of the image to delete

get_instance(instance_id, name=None, *, username: str | None = None, **kwargs)[source]

Get an instance by id.

Parameters:
  • instance_id – The instance ID returned upon creation

  • username – username to use when connecting via SSH

Returns:

An instance object to use to manipulate the instance further.

image_serial(image_id)[source]

Find the image serial of the latest daily image for a particular release.

Parameters:

image_id – string, Ubuntu image id

Returns:

string, serial of latest image

launch(image_id, instance_type='n1-standard-1', user_data=None, *, username: str | None = None, **kwargs)[source]

Launch instance on GCE and print the IP address.

Parameters:
  • image_id – string, image ID for instance to use

  • instance_type – string, instance type to launch

  • user_data – string, user-data to pass to instance

  • username – username to use when connecting via SSH

  • kwargs – other named arguments to add to instance JSON

Raises: ValueError on invalid image_id

released_image(release, *, image_type: ImageType = ImageType.GENERIC, **kwargs)[source]

ID of the latest released image for a particular release.

Parameters:

release – The release to look for

Returns:

A single string with the latest released image ID for the specified release.

snapshot(instance: GceInstance, clean=True, **kwargs)[source]

Snapshot an instance and generate an image from it.

Parameters:
  • instance – Instance to snapshot

  • clean – run instance clean method before taking snapshot

Returns:

An image id