airflow.gcp.hooks.compute

This module contains a Google Compute Engine Hook.

Module Contents

airflow.gcp.hooks.compute.TIME_TO_SLEEP_IN_SECONDS = 1[source]
class airflow.gcp.hooks.compute.GceOperationStatus[source]

Class with GCE operations statuses.

PENDING = PENDING[source]
RUNNING = RUNNING[source]
DONE = DONE[source]
class airflow.gcp.hooks.compute.GceHook(api_version:str='v1', gcp_conn_id:str='google_cloud_default', delegate_to:str=None)[source]

Bases: airflow.contrib.hooks.gcp_api_base_hook.GoogleCloudBaseHook

Hook for Google Compute Engine APIs.

All the methods in the hook where project_id is used must be called with keyword arguments rather than positional.

_conn :Optional[Any][source]
get_conn(self)[source]

Retrieves connection to Google Compute Engine.

Returns

Google Compute Engine services object

Return type

dict

start_instance(self, zone:str, resource_id:str, project_id:str=None)[source]

Starts an existing instance defined by project_id, zone and resource_id. Must be called with keyword arguments rather than positional.

Parameters
  • zone (str) – Google Cloud Platform zone where the instance exists

  • resource_id (str) – Name of the Compute Engine instance resource

  • project_id (str) – Optional, Google Cloud Platform project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the GCP connection is used.

Returns

None

stop_instance(self, zone:str, resource_id:str, project_id:str=None)[source]

Stops an instance defined by project_id, zone and resource_id Must be called with keyword arguments rather than positional.

Parameters
  • zone (str) – Google Cloud Platform zone where the instance exists

  • resource_id (str) – Name of the Compute Engine instance resource

  • project_id (str) – Optional, Google Cloud Platform project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the GCP connection is used.

Returns

None

set_machine_type(self, zone:str, resource_id:str, body:Dict, project_id:str=None)[source]

Sets machine type of an instance defined by project_id, zone and resource_id. Must be called with keyword arguments rather than positional.

Parameters
  • zone (str) – Google Cloud Platform zone where the instance exists.

  • resource_id (str) – Name of the Compute Engine instance resource

  • body (dict) – Body required by the Compute Engine setMachineType API, as described in https://cloud.google.com/compute/docs/reference/rest/v1/instances/setMachineType

  • project_id (str) – Optional, Google Cloud Platform project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the GCP connection is used.

Returns

None

_execute_set_machine_type(self, zone:str, resource_id:str, body:Dict, project_id:str)[source]
get_instance_template(self, resource_id:str, project_id:str=None)[source]

Retrieves instance template by project_id and resource_id. Must be called with keyword arguments rather than positional.

Parameters
  • resource_id (str) – Name of the instance template

  • project_id (str) – Optional, Google Cloud Platform project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the GCP connection is used.

Returns

Instance template representation as object according to https://cloud.google.com/compute/docs/reference/rest/v1/instanceTemplates

Return type

dict

insert_instance_template(self, body:Dict, request_id:str=None, project_id:str=None)[source]

Inserts instance template using body specified Must be called with keyword arguments rather than positional.

Parameters
  • body (dict) – Instance template representation as object according to https://cloud.google.com/compute/docs/reference/rest/v1/instanceTemplates

  • request_id (str) – Optional, unique request_id that you might add to achieve full idempotence (for example when client call times out repeating the request with the same request id will not create a new instance template again) It should be in UUID format as defined in RFC 4122

  • project_id (str) – Optional, Google Cloud Platform project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the GCP connection is used.

Returns

None

get_instance_group_manager(self, zone:str, resource_id:str, project_id:str=None)[source]

Retrieves Instance Group Manager by project_id, zone and resource_id. Must be called with keyword arguments rather than positional.

Parameters
  • zone (str) – Google Cloud Platform zone where the Instance Group Manager exists

  • resource_id (str) – Name of the Instance Group Manager

  • project_id (str) – Optional, Google Cloud Platform project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the GCP connection is used.

Returns

Instance group manager representation as object according to https://cloud.google.com/compute/docs/reference/rest/beta/instanceGroupManagers

Return type

dict

patch_instance_group_manager(self, zone:str, resource_id:str, body:Dict, request_id:str=None, project_id:str=None)[source]

Patches Instance Group Manager with the specified body. Must be called with keyword arguments rather than positional.

Parameters
  • zone (str) – Google Cloud Platform zone where the Instance Group Manager exists

  • resource_id (str) – Name of the Instance Group Manager

  • body (dict) – Instance Group Manager representation as json-merge-patch object according to https://cloud.google.com/compute/docs/reference/rest/beta/instanceTemplates/patch

  • request_id (str) – Optional, unique request_id that you might add to achieve full idempotence (for example when client call times out repeating the request with the same request id will not create a new instance template again). It should be in UUID format as defined in RFC 4122

  • project_id (str) – Optional, Google Cloud Platform project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the GCP connection is used.

Returns

None

_wait_for_operation_to_complete(self, project_id:str, operation_name:str, zone:str=None)[source]

Waits for the named operation to complete - checks status of the async call.

Parameters
  • operation_name (str) – name of the operation

  • zone (str) – optional region of the request (might be None for global operations)

Returns

None

static _check_zone_operation_status(service:Any, operation_name:str, project_id:str, zone:str, num_retries:int)[source]
static _check_global_operation_status(service:Any, operation_name:str, project_id:str, num_retries:int)[source]