airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] potiuk commented on a change in pull request #4167: [AIRFLOW-3220] Implement Instance Group Manager Operators for GCE
Date Mon, 12 Nov 2018 14:49:14 GMT
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_r232685471
 
 

 ##########
 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
+        :type project_id: str
+        :param zone: Google Cloud Platform zone where the Instance Group Manager exists
+        :type zone: str
+        :param resource_id: Name of the Instance Group Manager
+        :type resource_id: str
+        :return: Instance group manager representation as object according to
+          https://cloud.google.com/compute/docs/reference/rest/beta/instanceGroupManagers
+        :rtype: dict
+        """
+        response = self.get_conn().instanceGroupManagers().get(
+            project=project_id,
+            zone=zone,
+            instanceGroupManager=resource_id
+        ).execute(num_retries=NUM_RETRIES)
+        return response
+
+    def patch_instance_group_manager(self, project_id, zone, resource_id,
+                                     body, request_id=None):
+        """
+        Patches Instance Group Manager with the specified body.
+
+        :param project_id: Google Cloud Platform project ID where the Compute Engine
+            Instance Group Manager exists
+        :type project_id: str
+        :param zone: Google Cloud Platform zone where the Instance Group Manager exists
+        :type zone: str
+        :param resource_id: Name of the Instance Group Manager
+        :type resource_id: str
+        :param body: Instance Group Manager representation as json-merge-patch object
+         according to
+         https://cloud.google.com/compute/docs/reference/rest/beta/instanceTemplates/patch
+        :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().instanceGroupManagers().patch(
+            project=project_id,
+            zone=zone,
+            instanceGroupManager=resource_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, zone)
+
+    def _wait_for_operation_to_complete(self, project_id, operation_name, zone=None):
         """
         Waits for the named operation to complete - checks status of the
-        asynchronous call.
+          asynchronous call.
 
         :param operation_name: name of the operation
         :type operation_name: str
+        :param zone: optional region of the request (might be None for global operations)
+        :type zone: str
         :return: True if the operation succeeded, raises an error otherwise
         :rtype: bool
         """
         service = self.get_conn()
         while True:
-            operation_response = self._check_operation_status(
-                service, operation_name, project_id, zone)
+            if zone is None:
+                # noinspection PyTypeChecker
 
 Review comment:
   We need it here to remove some annoying complaints from the IDE. I try to keep 0 warnings
(i.e. green checkmark) while developing to catch stupid typos more easily. In this case discovery
API does a lot of meta-programming and a lot of python objects returned have some duck-typed
methods and silencing those warnings here helps to keep the green mark.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message