elasticluster.providers.gce¶
Cloud provider for the Google Compute Engine.
See <https://code.google.com/p/google-cloud-platform-samples/source/browse/python-client-library-example/gce.py?repo=compute> for reference.
-
elasticluster.providers.gce.
GCE_SCOPE
= 'https://www.googleapis.com/auth/compute'¶ the OAuth scope for the GCE web API
-
class
elasticluster.providers.gce.
GoogleCloudProvider
(gce_client_id, gce_client_secret, gce_project_id, zone='us-central1-a', network='default', email='default', storage_path=None)[source]¶ Cloud provider for the Google Compute Engine.
Parameters: - gce_client_id (str) – Client ID to use in OAuth authentication.
- gce_client_secret (str) – Client secret (password) to use in OAuth authentication.
- gce_project_id (str) – Project name to log in to GCE.
- zone (str) – gce zone, default is us-central1-a
- network (str) – network to use, default is default
- email (str) – service email to use, default is default
- storage_path (str) – path to store authentication data (oauth.dat file). If no path is specified, the login data has to be entered after every request.
-
get_ips
(instance_id)[source]¶ Retrieves the ip addresses (private and public) from the cloud provider by the given instance id.
Parameters: instance_id (str) – id of the instance Returns: list (ips) Raises: InstanceError if the ip could not be retrieved.
-
is_instance_running
(instance_id)[source]¶ Check whether the instance is up and running.
Parameters: instance_id (str) – instance identifier Reutrn: True if instance is running, False otherwise
-
list_instances
(filter=None)[source]¶ List instances on GCE, optionally filtering the results.
Parameters: filter (str) – Filter specification; see https://developers.google.com/compute/docs/reference/latest/instances/list for details. Returns: list of instances
-
start_instance
(key_name, public_key_path, private_key_path, security_group, flavor, image_id, image_userdata, username=None, instance_name=None, **kwargs)[source]¶ Starts a new instance with the given properties and returns the instance id.
Parameters: - key_name (str) – name of the ssh key to connect
- public_key_path (str) – path to ssh public key
- private_key_path (str) – path to ssh private key
- security_group (str) – firewall rule definition to apply on the instance
- flavor (str) – machine type to use for the instance
- image_id (str) – image type (os) to use for the instance
- image_userdata (str) – command to execute after startup
- username (str) – username for the given ssh key, default None
- instance_name (str) – name of the instance
Returns: str - instance id of the started instance