potiuk commented on a change in pull request #4167: [AIRFLOW-3220] Implement
Instance Group Manager Operators for GCE
URL: https://github.com/apache/incubator-airflow/pull/4167#discussion_r232554414
##########
File path: airflow/contrib/hooks/gcp_compute_hook.py
##########
@@ -106,49 +106,158 @@ def stop_instance(self, project_id, zone, resource_id):
instance=resource_id
).execute(num_retries=NUM_RETRIES)
operation_name = response["name"]
- return self._wait_for_operation_to_complete(project_id, zone,
operation_name)
+ return self._wait_for_operation_to_complete(project_id,
operation_name, zone)
def set_machine_type(self, project_id, zone, resource_id, body):
"""
Sets machine type of an instance defined by project_id, zone and
resource_id.
- :param project_id: Google Cloud Platform project where the Compute
Engine
- instance exists.
+ :param project_id: Google Cloud Platform project ID where the Compute
Engine
+ instance exists
:type project_id: str
:param zone: Google Cloud Platform zone where the instance exists.
:type zone: str
- :param resource_id: Name of the Compute Engine instance resource.
+ :param resource_id: Name of the Compute Engine instance resource
:type resource_id: str
:param body: Body required by the Compute Engine setMachineType API,
- as described in
-
https://cloud.google.com/compute/docs/reference/rest/v1/instances/setMachineType
+ as described in
+
https://cloud.google.com/compute/docs/reference/rest/v1/instances/setMachineType
:type body: dict
- :return: True if the operation succeeded, raises an error otherwise
+ :return: True if the operation succeeded, raises an error otherwise.
:rtype: bool
"""
response = self._execute_set_machine_type(project_id, zone,
resource_id, body)
operation_name = response["name"]
- return self._wait_for_operation_to_complete(project_id, zone,
operation_name)
+ return self._wait_for_operation_to_complete(project_id,
operation_name, zone)
def _execute_set_machine_type(self, project_id, zone, resource_id, body):
return self.get_conn().instances().setMachineType(
project=project_id, zone=zone, instance=resource_id, body=body)\
.execute(num_retries=NUM_RETRIES)
- def _wait_for_operation_to_complete(self, project_id, zone,
operation_name):
+ def get_instance_template(self, project_id, resource_id):
+ """
+ Retrieves instance template by project_id and resource_id.
+
+ :param project_id: Google Cloud Platform project ID where the Compute
Engine
+ instance template exists
+ :type project_id: str
+ :param resource_id: Name of the instance template
+ :type resource_id: str
+ :return: Instance template representation as object according to
+
https://cloud.google.com/compute/docs/reference/rest/v1/instanceTemplates
+ :rtype: dict
+ """
+ response = self.get_conn().instanceTemplates().get(
+ project=project_id,
+ instanceTemplate=resource_id
+ ).execute(num_retries=NUM_RETRIES)
+ return response
+
+ def insert_instance_template(self, project_id, body, request_id=None):
+ """
+ Inserts instance template using body specified
+
+ :param project_id: Google Cloud Platform project ID where the Compute
Engine
+ instance exists
+ :type project_id: str
+ :param body: Instance template representation as object according to
+
https://cloud.google.com/compute/docs/reference/rest/v1/instanceTemplates
+ :type body: dict
+ :param request_id: 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
+ :type request_id: str
+ :return: True if the operation succeeded
+ :rtype: bool
+ """
+ response = self.get_conn().instanceTemplates().insert(
+ project=project_id,
+ body=body,
+ requestId=request_id
+ ).execute(num_retries=NUM_RETRIES)
+ operation_name = response["name"]
+ return self._wait_for_operation_to_complete(project_id, operation_name)
+
+ def get_instance_group_manager(self, project_id, zone, resource_id):
+ """
+ Retrieves Instance Group Manager by project_id, zone and resource_id.
+
+ :param project_id: Google Cloud Platform project ID where the Compute
Engine
+ Instance Group Manager exists
Review comment:
Fixed.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services