Google Compute Engine Driver Documentation

Google Cloud Platform Compute Engine gives users the ability to run large-scale workloads on virtual machines hosted on Google’s infrastructure. It is a part of Google Cloud Platform.

../../_images/gcp.png

Google Compute Engine features:

  • High-performance virtual machines
  • Minute-level billing (10-minute minimum)
  • Fast VM provisioning
  • Native Load Balancing

Connecting to Google Compute Engine

Libcloud supports two different methods for authenticating to Compute Engine: Service Account and Installed Application

Which one should I use?

  • Service Accounts are generally better suited for automated systems, cron jobs, etc. They should be used when access to the application/script is limited and needs to be able to run with limited intervention.
  • Installed Application authentication is often the better choice when creating an application that may be used by third-parties interactively. For example, a desktop application for managing VMs that would be used by many different people with different Google accounts.

Once you have set up the authentication as described below, you pass the authentication information to the driver as described in Examples

Service Account

To set up Service Account authentication:

  1. Follow the instructions at https://developers.google.com/console/help/new/#serviceaccounts to create and download a PKCS-12 private key.
  2. Convert the PKCS-12 private key to a .pem file using the following: openssl pkcs12 -in YOURPRIVKEY.p12 -nodes -nocerts | openssl rsa -out PRIV.pem
  3. Move the .pem file to a safe location
  4. You will need the Service Account’s “Email Address” and the path to the .pem file for authentication.
  5. You will also need your “Project ID” which can be found by clicking on the “Overview” link on the left sidebar.

Installed Application

To set up Installed Account authentication:

  1. Go to the Google Developers Console
  2. Select your project
  3. In the left sidebar, go to “APIs & auth”
  4. Click on “Credentials” then “Create New Client ID”
  5. Select “Installed application” and “Other” then click “Create Client ID”
  6. For authentication, you will need the “Client ID” and the “Client Secret”
  7. You will also need your “Project ID” which can be found by clicking on the “Overview” link on the left sidebar.

Examples

Additional example code can be found in the “demos” directory of Libcloud here: https://github.com/apache/libcloud/blob/trunk/demos/gce_demo.py

1. Getting Driver with Service Account authentication

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

ComputeEngine = get_driver(Provider.GCE)
driver = ComputeEngine('your_service_account_email', 'path_to_pem_file',
                       project='your_project_id')

2. Getting Driver with Installed Application authentication

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

ComputeEngine = get_driver(Provider.GCE)
driver = ComputeEngine('your_client_id', 'your_client_secret',
                       project='your_project_id')

3. Getting Driver using a default Datacenter (Zone)

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

ComputeEngine = get_driver(Provider.GCE)
# Datacenter is set to 'us-central1-a' as an example, but can be set to any
# zone, like 'us-central1-b' or 'europe-west1-a'
driver = ComputeEngine('your_service_account_email', 'path_to_pem_file',
                       datacenter='us-central1-a',
                       project='your_project_id')

API Docs

class libcloud.compute.drivers.gce.GCENodeDriver(user_id, key, datacenter=None, project=None, auth_type=None, scopes=None, **kwargs)[source]

GCE Node Driver class.

This is the primary driver for interacting with Google Compute Engine. It contains all of the standard libcloud methods, plus additional ex_* methods for more features.

Note that many methods allow either objects or strings (or lists of objects/strings). In most cases, passing strings instead of objects will result in additional GCE API calls.

Parameters:
  • user_id (str) – The email address (for service accounts) or Client ID (for installed apps) to be used for authentication.
  • key (str) – The RSA Key (for service accounts) or file path containing key or Client Secret (for installed apps) to be used for authentication.
  • datacenter (str) – The name of the datacenter (zone) used for operations.
  • project (str) – Your GCE project name. (required)
  • auth_type (str) – Accepted values are “SA” or “IA” (“Service Account” or “Installed Application”). If not supplied, auth_type will be guessed based on value of user_id.
  • scopes (list) – List of authorization URLs. Default is empty and grants read/write to Compute, Storage, DNS.
attach_volume(node, volume, device=None, ex_mode=None, ex_boot=False)[source]

Attach a volume to a node.

If volume is None, a scratch disk will be created and attached.

Parameters:
  • node (Node) – The node to attach the volume to
  • volume (StorageVolume or None) – The volume to attach. If none, a scratch disk will be attached.
  • device (str) – The device name to attach the volume as. Defaults to volume name.
  • ex_mode (str) – Either ‘READ_WRITE’ or ‘READ_ONLY’
  • ex_boot (bool) – If true, disk will be attached as a boot disk
Returns:

True if successful

Return type:

bool

connectionCls

alias of GCEConnection

copy_image(source_region, node_image, name, description=None)

Copies an image from a source region to the current region.

Parameters:
  • source_region (str) – Region to copy the node from.
  • node_image – NodeImage to copy.
  • name (str) – name for new image.
  • description – description for new image.
Return type:

NodeImage:

Returns:

NodeImage instance on success.

create_image(node, name, description=None)

Creates an image from a node object.

Parameters:
  • node (Node) – Node to run the task on.
  • name (description) – name for new image.
  • description – description for new image.
Return type:

NodeImage:

Returns:

NodeImage instance on success.

create_key_pair(name)

Create a new key pair object.

Parameters:name (str) – Key pair name.
create_node(name, size, image, location=None, ex_network='default', ex_tags=None, ex_metadata=None, ex_boot_disk=None, use_existing_disk=True, external_ip='ephemeral')[source]

Create a new node and return a node object for the node.

Parameters:
  • name (str) – The name of the node to create.
  • size (str or GCENodeSize) – The machine type to use.
  • image (str or GCENodeImage) – The image to use to create the node (or, if attaching a persistent disk, the image used to create the disk)
  • location (str or NodeLocation or GCEZone or None) – The location (zone) to create the node in.
  • ex_network (str or GCENetwork) – The network to associate with the node.
  • ex_tags (list of str or None) – A list of tags to associate with the node.
  • ex_metadata (dict or None) – Metadata dictionary for instance.
  • ex_boot_disk (StorageVolume or str) – The boot disk to attach to the instance.
  • use_existing_disk (bool) – If True and if an existing disk with the same name/location is found, use that disk instead of creating a new one.
  • external_ip (GCEAddress or str or None) – The external IP address to use. If ‘ephemeral’ (default), a new non-static address will be used. If ‘None’, then no external address will be used. To use an existing static IP address, a GCEAddress object should be passed in.
Returns:

A Node object for the new node.

Return type:

Node

create_volume(size, name, location=None, snapshot=None, image=None, use_existing=True)[source]

Create a volume (disk).

Parameters:
  • size (int or str or None) – Size of volume to create (in GB). Can be None if image or snapshot is supplied.
  • name (str) – Name of volume to create
  • location (str or GCEZone or NodeLocation or None) – Location (zone) to create the volume in
  • snapshot (GCESnapshot or str or None) – Snapshot to create image from
  • image (GCENodeImage or str or None) – Image to create disk from.
  • use_existing (bool) – If True and a disk with the given name already exists, return an object for that disk instead of attempting to create a new disk.
Returns:

Storage Volume object

Return type:

StorageVolume

create_volume_snapshot(volume, name)[source]

Create a snapshot of the provided Volume.

Parameters:volume (StorageVolume) – A StorageVolume object
Returns:A GCE Snapshot object
Return type:GCESnapshot
delete_image(node_image)

Deletes a node image from a provider.

Parameters:node_image (NodeImage) – Node image object.
Returns:True if delete_image was successful, False otherwise.
Return type:bool
delete_key_pair(key_pair)

Delete an existing key pair.

Parameters:key_pair (:class`.KeyPair`) – Key pair object.
deploy_node(name, size, image, script, location=None, ex_network='default', ex_tags=None)[source]

Create a new node and run a script on start-up.

Parameters:
  • name (str) – The name of the node to create.
  • size (str or GCENodeSize) – The machine type to use.
  • image (str or GCENodeImage) – The image to use to create the node.
  • script (str) – File path to start-up script
  • location (str or NodeLocation or GCEZone or None) – The location (zone) to create the node in.
  • ex_network (str or GCENetwork) – The network to associate with the node.
  • ex_tags (list of str or None) – A list of tags to associate with the node.
Returns:

A Node object for the new node.

Return type:

Node

destroy_node(node, destroy_boot_disk=False)[source]

Destroy a node.

Parameters:
  • node (Node) – Node object to destroy
  • destroy_boot_disk (bool) – If true, also destroy the node’s boot disk. (Note that this keyword is not accessible from the node’s .destroy() method.)
Returns:

True if successful

Return type:

bool

destroy_volume(volume)[source]

Destroy a volume.

Parameters:volume (StorageVolume) – Volume object to destroy
Returns:True if successful
Return type:bool
destroy_volume_snapshot(snapshot)[source]

Destroy a snapshot.

Parameters:snapshot (GCESnapshot) – Snapshot object to destroy
Returns:True if successful
Return type:bool
detach_volume(volume, ex_node=None)[source]

Detach a volume from a node.

Parameters:
  • volume (StorageVolume) – Volume object to detach
  • ex_node (Node) – Node object to detach volume from (required)
Returns:

True if successful

Return type:

bool

ex_copy_image(name, url, description=None)[source]

Copy an image to your image collection.

Parameters:
  • name (str) – The name of the image
  • url – The URL to the image. The URL can start with gs://
  • urlstr
  • description (str) – The description of the image
Returns:

NodeImage object based on provided information or None if an image with that name is not found.

Return type:

NodeImage or None

ex_create_address(name, region=None)[source]

Create a static address in a region.

Parameters:
  • name (str) – Name of static address
  • region (str or GCERegion) – Name of region for the address (e.g. ‘us-central1’)
Returns:

Static Address object

Return type:

GCEAddress

ex_create_firewall(name, allowed, network='default', source_ranges=None, source_tags=None, target_tags=None)[source]

Create a firewall on a network.

Firewall rules should be supplied in the “allowed” field. This is a list of dictionaries formated like so (“ports” is optional):

[{"IPProtocol": "<protocol string or number>",
  "ports": "<port_numbers or ranges>"}]

For example, to allow tcp on port 8080 and udp on all ports, ‘allowed’ would be:

[{"IPProtocol": "tcp",
  "ports": ["8080"]},
 {"IPProtocol": "udp"}]

See Firewall Reference for more information.

Parameters:
  • name (str) – Name of the firewall to be created
  • allowed (list of dict) – List of dictionaries with rules
  • network (str or GCENetwork) – The network that the firewall applies to.
  • source_ranges (list of str) – A list of IP ranges in CIDR format that the firewall should apply to. Defaults to [‘0.0.0.0/0’]
  • source_tags (list of str) – A list of source instance tags the rules apply to.
  • target_tags (list of str) – A list of target instance tags the rules apply to.
Returns:

Firewall object

Return type:

GCEFirewall

ex_create_forwarding_rule(name, targetpool, region=None, protocol='tcp', port_range=None, address=None)[source]

Create a forwarding rule.

Parameters:
  • name (str) – Name of forwarding rule to be created
  • targetpool – Target pool to apply the rule to
  • targetpoolstr or GCETargetPool
  • region (str or GCERegion) – Region to create the forwarding rule in. Defaults to self.region
  • protocol (str) – Should be ‘tcp’ or ‘udp’
  • port_range (str) – Optional single port number or range separated by a dash. Examples: ‘80’, ‘5000-5999’.
  • address (str or GCEAddress) – Optional static address for forwarding rule. Must be in same region.
Returns:

Forwarding Rule object

Return type:

GCEForwardingRule

ex_create_healthcheck(name, host=None, path=None, port=None, interval=None, timeout=None, unhealthy_threshold=None, healthy_threshold=None)[source]

Create an Http Health Check.

Parameters:
  • name (str) – Name of health check
  • host (str) – Hostname of health check request. Defaults to empty and public IP is used instead.
  • path (str) – The request path for the check. Defaults to /.
  • port (int) – The TCP port number for the check. Defaults to 80.
  • interval (int) – How often (in seconds) to check. Defaults to 5.
  • timeout (int) – How long to wait before failing. Defaults to 5.
  • unhealthy_threshold (int) – How many failures before marking unhealthy. Defaults to 2.
  • healthy_threshold (int) – How many successes before marking as healthy. Defaults to 2.
Returns:

Health Check object

Return type:

GCEHealthCheck

ex_create_multiple_nodes(base_name, size, image, number, location=None, ex_network='default', ex_tags=None, ex_metadata=None, ignore_errors=True, use_existing_disk=True, poll_interval=2, external_ip='ephemeral', timeout=180)[source]

Create multiple nodes and return a list of Node objects.

Nodes will be named with the base name and a number. For example, if the base name is ‘libcloud’ and you create 3 nodes, they will be named:

libcloud-000
libcloud-001
libcloud-002
Parameters:
  • base_name (str) – The base name of the nodes to create.
  • size (str or GCENodeSize) – The machine type to use.
  • image (str or GCENodeImage) – The image to use to create the nodes.
  • number (int) – The number of nodes to create.
  • location (str or NodeLocation or GCEZone or None) – The location (zone) to create the nodes in.
  • ex_network (str or GCENetwork) – The network to associate with the nodes.
  • ex_tags (list of str or None) – A list of tags to assiciate with the nodes.
  • ex_metadata (dict or None) – Metadata dictionary for instances.
  • ignore_errors (bool) – If True, don’t raise Exceptions if one or more nodes fails.
  • use_existing_disk (bool) – If True and if an existing disk with the same name/location is found, use that disk instead of creating a new one.
  • poll_interval (int) – Number of seconds between status checks.
  • external_ip (str or None) – The external IP address to use. If ‘ephemeral’ (default), a new non-static address will be used. If ‘None’, then no external address will be used. (Static addresses are not supported for multiple node creation.)
  • timeout (int) – The number of seconds to wait for all nodes to be created before timing out.
Returns:

A list of Node objects for the new nodes.

Return type:

list of Node

ex_create_network(name, cidr)[source]

Create a network.

Parameters:
  • name (str) – Name of network to be created
  • cidr (str) – Address range of network in CIDR format.
Returns:

Network object

Return type:

GCENetwork

ex_create_targetpool(name, region=None, healthchecks=None, nodes=None)[source]

Create a target pool.

Parameters:
  • name (str) – Name of target pool
  • region (str or GCERegion or None) – Region to create the target pool in. Defaults to self.region
  • healthchecks (list of str or GCEHealthCheck) – Optional list of health checks to attach
  • nodes (list of str or Node) – Optional list of nodes to attach to the pool
Returns:

Target Pool object

Return type:

GCETargetPool

ex_delete_image(image)[source]

Delete a specific image resource.

Parameters:image (str or GCENodeImage) – Image object to delete
Returns:True if successfull
Return type:bool
ex_deprecate_image(image, replacement, state=None)[source]

Deprecate a specific image resource.

Parameters:
  • image (str or :class: GCENodeImage) – Image object to deprecate
  • replacement (str or :class: GCENodeImage) – Image object to use as a replacement
  • state (str) – State of the image
Returns:

True if successfull

Return type:

bool

ex_destroy_address(address)[source]

Destroy a static address.

Parameters:address (GCEAddress) – Address object to destroy
Returns:True if successful
Return type:bool
ex_destroy_firewall(firewall)[source]

Destroy a firewall.

Parameters:firewall (GCEFirewall) – Firewall object to destroy
Returns:True if successful
Return type:bool
ex_destroy_forwarding_rule(forwarding_rule)[source]

Destroy a forwarding rule.

Parameters:forwarding_rule (GCEForwardingRule) – Forwarding Rule object to destroy
Returns:True if successful
Return type:bool
ex_destroy_healthcheck(healthcheck)[source]

Destroy a healthcheck.

Parameters:healthcheck (GCEHealthCheck) – Health check object to destroy
Returns:True if successful
Return type:bool
ex_destroy_multiple_nodes(node_list, ignore_errors=True, destroy_boot_disk=False, poll_interval=2, timeout=180)[source]

Destroy multiple nodes at once.

Parameters:
  • node_list (list of Node) – List of nodes to destroy
  • ignore_errors (bool) – If true, don’t raise an exception if one or more nodes fails to be destroyed.
  • destroy_boot_disk (bool) – If true, also destroy the nodes’ boot disks.
  • poll_interval (int) – Number of seconds between status checks.
  • timeout (int) – Number of seconds to wait for all nodes to be destroyed.
Returns:

A list of boolean values. One for each node. True means that the node was successfully destroyed.

Return type:

list of bool

ex_destroy_network(network)[source]

Destroy a network.

Parameters:network (GCENetwork) – Network object to destroy
Returns:True if successful
Return type:bool
ex_destroy_targetpool(targetpool)[source]

Destroy a target pool.

Parameters:targetpool (GCETargetPool) – TargetPool object to destroy
Returns:True if successful
Return type:bool
ex_get_address(name, region=None)[source]

Return an Address object based on an address name and optional region.

Parameters:
  • name (str) – The name of the address
  • region (str GCERegion or None) – The region to search for the address in (set to ‘all’ to search all regions)
Returns:

An Address object for the address

Return type:

GCEAddress

ex_get_firewall(name)[source]

Return a Firewall object based on the firewall name.

Parameters:name (str) – The name of the firewall
Returns:A GCEFirewall object
Return type:GCEFirewall
ex_get_forwarding_rule(name, region=None)[source]

Return a Forwarding Rule object based on the forwarding rule name.

Parameters:
  • name (str) – The name of the forwarding rule
  • region (str or None) – The region to search for the rule in (set to ‘all’ to search all regions).
Returns:

A GCEForwardingRule object

Return type:

GCEForwardingRule

ex_get_healthcheck(name)[source]

Return a HealthCheck object based on the healthcheck name.

Parameters:name (str) – The name of the healthcheck
Returns:A GCEHealthCheck object
Return type:GCEHealthCheck
ex_get_image(partial_name)[source]

Return an GCENodeImage object based on the name or link provided.

Parameters:partial_name (str) – The name, partial name, or full path of a GCE image.
Returns:GCENodeImage object based on provided information or None if an image with that name is not found.
Return type:GCENodeImage or None
ex_get_network(name)[source]

Return a Network object based on a network name.

Parameters:name (str) – The name of the network
Returns:A Network object for the network
Return type:GCENetwork
ex_get_node(name, zone=None)[source]

Return a Node object based on a node name and optional zone.

Parameters:
  • name (str) – The name of the node
  • zone (str or GCEZone or NodeLocation or None) – The zone to search for the node in. If set to ‘all’, search all zones for the instance.
Returns:

A Node object for the node

Return type:

Node

ex_get_project()[source]

Return a Project object with project-wide information.

Returns:A GCEProject object
Return type:GCEProject
ex_get_region(name)[source]

Return a Region object based on the region name.

Parameters:name (str) – The name of the region.
Returns:A GCERegion object for the region
Return type:GCERegion
ex_get_size(name, zone=None)[source]

Return a size object based on a machine type name and zone.

Parameters:
  • name (str) – The name of the node
  • zone (str or GCEZone or NodeLocation or None) – The zone to search for the machine type in
Returns:

A GCENodeSize object for the machine type

Return type:

GCENodeSize

ex_get_snapshot(name)[source]

Return a Snapshot object based on snapshot name.

Parameters:name (str) – The name of the snapshot
Returns:A GCESnapshot object for the snapshot
Return type:GCESnapshot
ex_get_targetpool(name, region=None)[source]

Return a TargetPool object based on a name and optional region.

Parameters:
  • name (str) – The name of the target pool
  • region (str or GCERegion or None) – The region to search for the target pool in (set to ‘all’ to search all regions).
Returns:

A TargetPool object for the pool

Return type:

GCETargetPool

ex_get_volume(name, zone=None)[source]

Return a Volume object based on a volume name and optional zone.

Parameters:
  • name (str) – The name of the volume
  • zone (str or GCEZone or NodeLocation or None) – The zone to search for the volume in (set to ‘all’ to search all zones)
Returns:

A StorageVolume object for the volume

Return type:

StorageVolume

ex_get_zone(name)[source]

Return a Zone object based on the zone name.

Parameters:name (str) – The name of the zone.
Returns:A GCEZone object for the zone or None if not found
Return type:GCEZone or None
ex_list_addresses(region=None)[source]

Return a list of static addresses for a region or all.

Parameters:region (str or None) – The region to return addresses from. For example: ‘us-central1’. If None, will return addresses from region of self.zone. If ‘all’, will return all addresses.
Returns:A list of static address objects.
Return type:list of GCEAddress
ex_list_firewalls()[source]

Return the list of firewalls.

Returns:A list of firewall objects.
Return type:list of GCEFirewall
ex_list_forwarding_rules(region=None)[source]

Return the list of forwarding rules for a region or all.

Parameters:region (str or GCERegion or None) – The region to return forwarding rules from. For example: ‘us-central1’. If None, will return forwarding rules from the region of self.region (which is based on self.zone). If ‘all’, will return all forwarding rules.
Returns:A list of forwarding rule objects.
Return type:list of GCEForwardingRule
ex_list_healthchecks()[source]

Return the list of health checks.

Returns:A list of health check objects.
Return type:list of GCEHealthCheck
ex_list_networks()[source]

Return the list of networks.

Returns:A list of network objects.
Return type:list of GCENetwork
ex_list_regions()[source]

Return the list of regions.

Returns:A list of region objects.
Return type:list of GCERegion
ex_list_snapshots()[source]

Return the list of disk snapshots in the project.

Returns:A list of snapshot objects
Return type:list of GCESnapshot
ex_list_targetpools(region=None)[source]

Return the list of target pools.

Returns:A list of target pool objects
Return type:list of GCETargetPool
ex_list_zones()[source]

Return the list of zones.

Returns:A list of zone objects.
Return type:list of GCEZone
ex_set_node_scheduling(node, on_host_maintenance=None, automatic_restart=None)[source]

Set the maintenance behavior for the node.

See Scheduling documentation for more info.

Parameters:
  • node (Node) – Node object
  • on_host_maintenance (str) – Defines whether node should be terminated or migrated when host machine goes down. Acceptable values are: ‘MIGRATE’ or ‘TERMINATE’ (If not supplied, value will be reset to GCE default value for the instance type.)
  • automatic_restart (bool) – Defines whether the instance should be automatically restarted when it is terminated by Compute Engine. (If not supplied, value will be set to the GCE default value for the instance type.)
Returns:

True if successful.

Return type:

bool

ex_set_node_tags(node, tags)[source]

Set the tags on a Node instance.

Note that this updates the node object directly.

Parameters:
  • node (Node) – Node object
  • tags (list of str) – List of tags to apply to the object
Returns:

True if successful

Return type:

bool

ex_set_volume_auto_delete(volume, node, auto_delete=True)[source]

Sets the auto-delete flag for a volume attached to a node.

Parameters:
  • volume (StorageVolume) – Volume object to auto-delete
  • ex_node (Node) – Node object to auto-delete volume from
  • auto_delete (bool (default True)) – Flag to set for the auto-delete value
Returns:

True if successfull

Return type:

bool

ex_targetpool_add_healthcheck(targetpool, healthcheck)[source]

Add a health check to a target pool.

Parameters:
  • targetpool (str or GCETargetPool) – The targetpool to add health check to
  • healthcheck (str or GCEHealthCheck) – The healthcheck to add
Returns:

True if successful

Return type:

bool

ex_targetpool_add_node(targetpool, node)[source]

Add a node to a target pool.

Parameters:
  • targetpool (str or GCETargetPool) – The targetpool to add node to
  • node (str or Node) – The node to add
Returns:

True if successful

Return type:

bool

ex_targetpool_remove_healthcheck(targetpool, healthcheck)[source]

Remove a health check from a target pool.

Parameters:
  • targetpool (str or GCETargetPool) – The targetpool to remove health check from
  • healthcheck (str or GCEHealthCheck) – The healthcheck to remove
Returns:

True if successful

Return type:

bool

ex_targetpool_remove_node(targetpool, node)[source]

Remove a node from a target pool.

Parameters:
  • targetpool (str or GCETargetPool) – The targetpool to remove node from
  • node (str or Node) – The node to remove
Returns:

True if successful

Return type:

bool

ex_update_firewall(firewall)[source]

Update a firewall with new values.

To update, change the attributes of the firewall object and pass the updated object to the method.

Parameters:firewall (GCEFirewall) – A firewall object with updated values.
Returns:An object representing the new state of the firewall.
Return type:GCEFirewall
ex_update_healthcheck(healthcheck)[source]

Update a health check with new values.

To update, change the attributes of the health check object and pass the updated object to the method.

Parameters:healthcheck (GCEHealthCheck) – A healthcheck object with updated values.
Returns:An object representing the new state of the health check.
Return type:GCEHealthCheck
get_image(image_id)

Returns a single node image from a provider.

Parameters:image_id (str) – Node to run the task on.

:rtype NodeImage: :return: NodeImage instance on success.

get_key_pair(name)

Retrieve a single key pair.

Parameters:name (str) – Name of the key pair to retrieve.
Return type:KeyPair
import_key_pair_from_file(name, key_file_path)

Import a new public key from string.

Parameters:
  • name (str) – Key pair name.
  • key_file_path (str) – Path to the public key file.
Return type:

KeyPair object

import_key_pair_from_string(name, key_material)

Import a new public key from string.

Parameters:
  • name (str) – Key pair name.
  • key_material (str) – Public key material.
Return type:

KeyPair object

list_images(ex_project=None)[source]

Return a list of image objects for a project.

Parameters:ex_project (str or None) – Optional alternate project name.
Returns:List of GCENodeImage objects
Return type:list of GCENodeImage
list_key_pairs()

List all the available key pair objects.

Return type:list of KeyPair objects
list_locations()[source]

Return a list of locations (zones).

The ex_list_zones method returns more comprehensive results, but this is here for compatibility.

Returns:List of NodeLocation objects
Return type:list of NodeLocation
list_nodes(ex_zone=None)[source]

Return a list of nodes in the current zone or all zones.

Parameters:ex_zone (str or GCEZone or NodeLocation or None) – Optional zone name or ‘all’
Returns:List of Node objects
Return type:list of Node
list_sizes(location=None)[source]

Return a list of sizes (machineTypes) in a zone.

Parameters:location (str or GCEZone or NodeLocation or None) – Location or Zone for sizes
Returns:List of GCENodeSize objects
Return type:list of GCENodeSize
list_volume_snapshots(volume)[source]

List snapshots created from the provided volume.

For GCE, snapshots are global, but while the volume they were created from still exists, the source disk for the snapshot is tracked.

Parameters:volume (StorageVolume) – A StorageVolume object
Returns:A list of Snapshot objects
Return type:list of GCESnapshot
list_volumes(ex_zone=None)[source]

Return a list of volumes for a zone or all.

Will return list from provided zone, or from the default zone unless given the value of ‘all’.

Parameters:ex_zone (str or GCEZone or NodeLocation or None) – The zone to return volumes from.
Returns:A list of volume objects.
Return type:list of StorageVolume
reboot_node(node)[source]

Reboot a node.

Parameters:node (Node) – Node to be rebooted
Returns:True if successful, False if not
Return type:bool
wait_until_running(nodes, wait_period=3, timeout=600, ssh_interface='public_ips', force_ipv4=True)

Block until the provided nodes are considered running.

Node is considered running when it’s state is “running” and when it has at least one IP address assigned.

Parameters:
  • nodes (list of Node) – List of nodes to wait for.
  • wait_period (int) – How many seconds to wait between each loop iteration. (default is 3)
  • timeout (int) – How many seconds to wait before giving up. (default is 600)
  • ssh_interface (str) – Which attribute on the node to use to obtain an IP address. Valid options: public_ips, private_ips. Default is public_ips.
  • force_ipv4 (bool) – Ignore IPv6 addresses (default is True).
Returns:

[(Node, ip_addresses)] list of tuple of Node instance and list of ip_address on success.

Return type:

list of tuple