feluelle commented on a change in pull request #9011:
URL: https://github.com/apache/airflow/pull/9011#discussion_r551178117



##########
File path: airflow/providers/amazon/aws/hooks/ec2.py
##########
@@ -33,21 +33,90 @@ class EC2Hook(AwsBaseHook):
         :class:`~airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook`
     """
 
+    # Describe response
+    RESERVATIONS = 'Reservations'
+    INSTANCES = 'Instances'
+    STATE = 'State'
+    NAME = 'Name'
+    INSTANCE_ID = 'InstanceId'
+
     def __init__(self,
                  *args,
                  **kwargs):
-        super().__init__(resource_type="ec2", *args, **kwargs)
+        super().__init__(client_type="ec2", *args, **kwargs)
 
-    def get_instance(self, instance_id: str):
+    def stop_instances(self, instance_ids):
         """
-        Get EC2 instance by id and return it.
+        Stop instances with given ids
 
-        :param instance_id: id of the AWS EC2 instance
-        :type instance_id: str
-        :return: Instance object
-        :rtype: ec2.Instance
+        :param instance_ids: List of instance ids to stop
+        :return: Dict with key `StoppingInstances` and value as list of 
instances being stopped
+        """
+        self.log.info("Stopping instances: %s", instance_ids)
+
+        return self.conn.stop_instances(InstanceIds=instance_ids)
+
+    def start_instances(self, instance_ids):
+        """
+        Start instances with given ids
+
+        :param instance_ids: List of instance ids to start
+        :return: Dict with key `StartingInstances` and value as list of 
instances being started
+        """
+        self.log.info("Starting instances: %s", instance_ids)
+
+        return self.conn.start_instances(InstanceIds=instance_ids)
+
+    def terminate_instances(self, instance_ids):
+        """
+        Terminate instances with given ids
+
+        :param instance_ids: List of instance ids to terminate
+        :return: Dict with key `TerminatingInstances` and value as list of 
instances being terminated
+        """
+        self.log.info("Terminating instances: %s", instance_ids)
+
+        return self.conn.terminate_instances(InstanceIds=instance_ids)
+
+    def describe_instances(self, filters=None, instance_ids=None):
+        """
+        Describe EC2 instances, optionally applying filters and selective 
instance ids
+
+        :param filters: List of filters to specify instances to describe
+        :param instance_ids: List of instance IDs to describe
+        :return: Response from EC2 describe_instances API
+        """
+        filters = [] if filters is None else filters
+        instance_ids = [] if instance_ids is None else instance_ids

Review comment:
       @VijayantSoni can you fix this, please? :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to