airflow.providers.google.cloud.hooks.compute
¶
This module contains a Google Compute Engine Hook.
Module Contents¶
Classes¶
Class with GCE operations statuses. |
|
Hook for Google Compute Engine APIs. |
Attributes¶
- class airflow.providers.google.cloud.hooks.compute.GceOperationStatus[source]¶
Class with GCE operations statuses.
- class airflow.providers.google.cloud.hooks.compute.ComputeEngineHook(api_version='v1', gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]¶
Bases:
airflow.providers.google.common.hooks.base_google.GoogleBaseHook
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.
- get_conn()[source]¶
Retrieves connection to Google Compute Engine.
- Returns
Google Compute Engine services object
- Return type
- get_compute_instance_group_managers_client()[source]¶
Returns Compute Engine Instance Group Managers Client.
- insert_instance_template(body, request_id=None, project_id=PROVIDE_PROJECT_ID, retry=None, timeout=None, metadata=())[source]¶
Creates Instance Template using body specified.
Must be called with keyword arguments rather than positional.
- Parameters
body (dict) – Instance Template representation as an object.
request_id (str | None) – 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) – Google Cloud project ID where the Compute Engine Instance Template exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
retry (google.api_core.retry.Retry | None) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- delete_instance_template(resource_id, request_id=None, project_id=PROVIDE_PROJECT_ID, retry=None, timeout=None, metadata=())[source]¶
Deletes Instance Template.
Deleting an Instance Template is permanent and cannot be undone. It is not possible to delete templates that are already in use by a managed instance group. Must be called with keyword arguments rather than positional.
- Parameters
resource_id (str) – Name of the Compute Engine Instance Template resource.
request_id (str | None) – 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) – Google Cloud project ID where the Compute Engine Instance Template exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
retry (google.api_core.retry.Retry | None) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- get_instance_template(resource_id, project_id=PROVIDE_PROJECT_ID, retry=None, timeout=None, metadata=())[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) – Google Cloud project ID where the Compute Engine Instance Template exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
retry (google.api_core.retry.Retry | None) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- Returns
Instance Template representation as object according to https://cloud.google.com/compute/docs/reference/rest/v1/instanceTemplates
- Return type
- insert_instance(body, zone, project_id=PROVIDE_PROJECT_ID, request_id=None, source_instance_template=None, retry=None, timeout=None, metadata=())[source]¶
Creates Instance using body specified.
Must be called with keyword arguments rather than positional.
- Parameters
body (dict) – Instance representation as an object. Should at least include ‘name’, ‘machine_type’, ‘disks’ and ‘network_interfaces’ fields but doesn’t include ‘zone’ field, as it will be specified in ‘zone’ parameter. Full or partial URL and can be represented as examples below: 1. “machine_type”: “projects/your-project-name/zones/your-zone/machineTypes/your-machine-type” 2. “source_image”: “projects/your-project-name/zones/your-zone/diskTypes/your-disk-type” 3. “subnetwork”: “projects/your-project-name/regions/your-region/subnetworks/your-subnetwork”
zone (str) – Google Cloud zone where the Instance exists
project_id (str) – Google Cloud project ID where the Compute Engine Instance Template exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
source_instance_template (str | None) – Existing Instance Template that will be used as a base while creating new Instance. When specified, only name of new Instance should be provided as input arguments in ‘body’ parameter when creating new Instance. All other parameters, will be passed to Instance as they are specified in the Instance Template. Full or partial URL and can be represented as examples below: 1. “https://www.googleapis.com/compute/v1/projects/your-project/global/instanceTemplates/temp” 2. “projects/your-project/global/instanceTemplates/temp” 3. “global/instanceTemplates/temp”
request_id (str | None) – 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
retry (google.api_core.retry.Retry | None) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- get_instance(resource_id, zone, project_id=PROVIDE_PROJECT_ID, retry=None, timeout=None, metadata=())[source]¶
Retrieves Instance by project_id and resource_id.
Must be called with keyword arguments rather than positional.
- Parameters
resource_id (str) – Name of the Instance
zone (str) – Google Cloud zone where the Instance exists
project_id (str) – Google Cloud project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
retry (google.api_core.retry.Retry | None) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- Returns
Instance representation as object according to https://cloud.google.com/compute/docs/reference/rest/v1/instances
- Return type
- delete_instance(resource_id, zone, project_id=PROVIDE_PROJECT_ID, request_id=None, retry=None, timeout=None, metadata=())[source]¶
Permanently and irrevocably deletes an Instance.
It is not possible to delete Instances that are already in use by a managed instance group. Must be called with keyword arguments rather than positional.
- Parameters
resource_id (str) – Name of the Compute Engine Instance Template resource.
request_id (str | None) – 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) – Google Cloud project ID where the Compute Engine Instance Template exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
zone (str) – Google Cloud zone where the Instance exists
retry (google.api_core.retry.Retry | None) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- start_instance(zone, resource_id, project_id)[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 zone where the instance exists
resource_id (str) – Name of the Compute Engine instance resource
project_id (str) – Optional, Google Cloud project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
- Returns
None
- Return type
None
- stop_instance(zone, resource_id, project_id)[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 zone where the instance exists
resource_id (str) – Name of the Compute Engine instance resource
project_id (str) – Optional, Google Cloud project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
- Returns
None
- Return type
None
- set_machine_type(zone, resource_id, body, project_id)[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 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 project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
- Returns
None
- Return type
None
- insert_instance_group_manager(body, zone, project_id=PROVIDE_PROJECT_ID, request_id=None, retry=None, timeout=None, metadata=())[source]¶
Creates an Instance Group Managers using the body specified.
After the group is created, instances in the group are created using the specified Instance Template. Must be called with keyword arguments rather than positional.
- Parameters
body (dict) – Instance Group Manager representation as an object.
request_id (str | None) – 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 Group Managers again) It should be in UUID format as defined in RFC 4122
project_id (str) – Google Cloud project ID where the Compute Engine Instance Group Managers exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
zone (str) – Google Cloud zone where the Instance exists
retry (google.api_core.retry.Retry | None) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- get_instance_group_manager(resource_id, zone, project_id=PROVIDE_PROJECT_ID, retry=None, timeout=None, metadata=())[source]¶
Retrieves Instance Group Manager by project_id, zone and resource_id.
Must be called with keyword arguments rather than positional.
- Parameters
resource_id (str) – The name of the Managed Instance Group
zone (str) – Google Cloud zone where the Instance Group Managers exists
project_id (str) – Google Cloud project ID where the Compute Engine Instance Group Managers exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
retry (google.api_core.retry.Retry | None) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- Returns
Instance Group Managers representation as object according to https://cloud.google.com/compute/docs/reference/rest/v1/instanceGroupManagers
- Return type
- delete_instance_group_manager(resource_id, zone, project_id=PROVIDE_PROJECT_ID, request_id=None, retry=None, timeout=None, metadata=())[source]¶
Permanently and irrevocably deletes Instance Group Managers.
Must be called with keyword arguments rather than positional.
- Parameters
resource_id (str) – Name of the Compute Engine Instance Group Managers resource.
request_id (str | None) – 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) – Google Cloud project ID where the Compute Engine Instance Group Managers exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
zone (str) – Google Cloud zone where the Instance Group Managers exists
retry (google.api_core.retry.Retry | None) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (float | None) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Sequence[tuple[str, str]]) – Additional metadata that is provided to the method.
- patch_instance_group_manager(zone, resource_id, body, project_id, request_id=None)[source]¶
Patches Instance Group Manager with the specified body.
Must be called with keyword arguments rather than positional.
- Parameters
zone (str) – Google Cloud 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 | None) – 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 project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
- Returns
None
- Return type
None
- get_instance_info(zone, resource_id, project_id)[source]¶
Gets instance information.
- Parameters
zone (str) – Google Cloud zone where the Instance Group Manager exists
resource_id (str) – Name of the Instance Group Manager
project_id (str) – Optional, Google Cloud project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
- get_instance_address(zone, resource_id, project_id=PROVIDE_PROJECT_ID, use_internal_ip=False)[source]¶
Return network address associated to instance.
- Parameters
zone (str) – Google Cloud zone where the Instance Group Manager exists
resource_id (str) – Name of the Instance Group Manager
project_id (str) – Optional, Google Cloud project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the Google Cloud connection is used.
use_internal_ip (bool) – If true, return private IP address.
- set_instance_metadata(zone, resource_id, metadata, project_id)[source]¶
Set instance metadata.
- Parameters
zone (str) – Google Cloud zone where the Instance Group Manager exists
resource_id (str) – Name of the Instance Group Manager
project_id (str) – Optional, Google Cloud project ID where the Compute Engine Instance exists. If set to None or missing, the default project_id from the Google Cloud connection is used.