pycloudlib.gce.cloud module

GCE Cloud type.

This is an initial implimentation 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 occuring.

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

Bases: pycloudlib.cloud.BaseCloud

GCE Cloud Class.

__init__(tag, timestamp_suffix=True, config_file: Union[pathlib.Path, _io.StringIO] = None, *, credentials_path=None, project=None, region=None, zone=None, service_account_email=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
create_key_pair()

Create and set a ssh key pair for a cloud instance.

Returns:A tuple containing the public and private key created
daily_image(release, arch='amd64')[source]

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

Parameters:
  • release – string, Ubuntu release to look for
  • arch – string, architecture to use
Returns:

string, path to latest daily image

delete_image(image_id)[source]

Delete an image.

Parameters:image_id – string, id of the image to delete
get_instance(instance_id, name=None)[source]

Get an instance by id.

Parameters:instance_id – The instance ID returned upon creation
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, wait=True, **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
  • wait – boolean, wait for instance to come up
  • kwargs – other named arguments to add to instance JSON
list_keys()

List ssh key names present on the cloud for accessing instances.

Returns:A list of strings of key pair names accessible to the cloud.
released_image(release, arch='amd64')[source]

ID of the latest released image for a particular release.

Parameters:
  • release – The release to look for
  • arch – string, architecture to use
Returns:

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

snapshot(instance: pycloudlib.gce.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

use_key(public_key_path, private_key_path=None, name=None)

Use an existing key.

Parameters:
  • public_key_path – path to the public key to upload
  • private_key_path – path to the private key
  • name – name to reference key by