vincbeck commented on code in PR #35790:
URL: https://github.com/apache/airflow/pull/35790#discussion_r1402331833


##########
airflow/providers/amazon/aws/operators/ec2.py:
##########
@@ -254,3 +255,128 @@ def execute(self, context: Context):
                         "MaxAttempts": self.max_attempts,
                     },
                 )
+
+
+class EC2RebootInstanceOperator(BaseOperator):
+    """
+    Reboot AWS EC2 instance using boto3.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:EC2RebootInstanceOperator`
+
+    :param instance_ids: ID of the instance to be terminated.
+    :param aws_conn_id: AWS connection to use
+    :param region_name: AWS region name associated with the client.
+    :param poll_interval: Number of seconds to wait before attempting to
+        check state of instance. Only used if wait_for_completion is True. 
Default is 20.
+    :param max_attempts: Maximum number of attempts when checking state of 
instance.
+        Only used if wait_for_completion is True. Default is 20.
+    :param wait_for_completion: If True, the operator will wait for the 
instance to be
+        in the `terminated` state before returning.

Review Comment:
   ```suggestion
           in the `running` state before returning.
   ```



##########
airflow/providers/amazon/aws/operators/ec2.py:
##########
@@ -254,3 +255,128 @@ def execute(self, context: Context):
                         "MaxAttempts": self.max_attempts,
                     },
                 )
+
+
+class EC2RebootInstanceOperator(BaseOperator):
+    """
+    Reboot AWS EC2 instance using boto3.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:EC2RebootInstanceOperator`
+
+    :param instance_ids: ID of the instance to be terminated.

Review Comment:
   ```suggestion
       :param instance_ids: ID of the instance(s) to be terminated.
   ```



##########
airflow/providers/amazon/aws/operators/ec2.py:
##########
@@ -254,3 +255,128 @@ def execute(self, context: Context):
                         "MaxAttempts": self.max_attempts,
                     },
                 )
+
+
+class EC2RebootInstanceOperator(BaseOperator):
+    """
+    Reboot AWS EC2 instance using boto3.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:EC2RebootInstanceOperator`
+
+    :param instance_ids: ID of the instance to be terminated.
+    :param aws_conn_id: AWS connection to use
+    :param region_name: AWS region name associated with the client.
+    :param poll_interval: Number of seconds to wait before attempting to
+        check state of instance. Only used if wait_for_completion is True. 
Default is 20.
+    :param max_attempts: Maximum number of attempts when checking state of 
instance.
+        Only used if wait_for_completion is True. Default is 20.
+    :param wait_for_completion: If True, the operator will wait for the 
instance to be
+        in the `terminated` state before returning.
+    """
+
+    template_fields: Sequence[str] = ("instance_id", "region_name")
+    ui_color = "#eeaa11"
+    ui_fgcolor = "#ffffff"
+
+    def __init__(
+        self,
+        *,
+        instance_ids: str | list[str],
+        aws_conn_id: str = "aws_default",
+        region_name: str | None = None,
+        poll_interval: int = 20,
+        max_attempts: int = 20,
+        wait_for_completion: bool = False,
+        **kwargs,
+    ):
+        super().__init__(**kwargs)
+        self.instance_ids = instance_ids
+        self.aws_conn_id = aws_conn_id
+        self.region_name = region_name
+        self.poll_interval = poll_interval
+        self.max_attempts = max_attempts
+        self.wait_for_completion = wait_for_completion
+
+    def execute(self, context: Context):
+        if isinstance(self.instance_ids, str):
+            self.instance_ids = [self.instance_ids]
+        ec2_hook = EC2Hook(aws_conn_id=self.aws_conn_id, 
region_name=self.region_name, api_type="client_type")
+        self.log.info("Rebooting EC2 instances %s", ", 
".join(self.instance_ids))
+        ec2_hook.conn.reboot_instances(InstanceIds=self.instance_ids)
+
+        if self.wait_for_completion:
+            ec2_hook.get_waiter("instance_running").wait(
+                InstanceIds=self.instance_ids,
+                WaiterConfig={
+                    "Delay": self.poll_interval,
+                    "MaxAttempts": self.max_attempts,
+                },
+            )
+
+
+class EC2HibernateInstanceOperator(BaseOperator):
+    """
+    Hibernate AWS EC2 instance using boto3.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:EC2HibernateInstanceOperator`
+
+    :param instance_ids: ID of the instance to be terminated.

Review Comment:
   ```suggestion
       :param instance_ids: ID of the instance(s) to be terminated.
   ```



##########
airflow/providers/amazon/aws/operators/ec2.py:
##########
@@ -254,3 +255,128 @@ def execute(self, context: Context):
                         "MaxAttempts": self.max_attempts,
                     },
                 )
+
+
+class EC2RebootInstanceOperator(BaseOperator):
+    """
+    Reboot AWS EC2 instance using boto3.

Review Comment:
   ```suggestion
       Reboot Amazon EC2 instance.
   ```



##########
airflow/providers/amazon/aws/operators/ec2.py:
##########
@@ -254,3 +255,128 @@ def execute(self, context: Context):
                         "MaxAttempts": self.max_attempts,
                     },
                 )
+
+
+class EC2RebootInstanceOperator(BaseOperator):
+    """
+    Reboot AWS EC2 instance using boto3.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:EC2RebootInstanceOperator`
+
+    :param instance_ids: ID of the instance to be terminated.
+    :param aws_conn_id: AWS connection to use
+    :param region_name: AWS region name associated with the client.
+    :param poll_interval: Number of seconds to wait before attempting to
+        check state of instance. Only used if wait_for_completion is True. 
Default is 20.
+    :param max_attempts: Maximum number of attempts when checking state of 
instance.
+        Only used if wait_for_completion is True. Default is 20.
+    :param wait_for_completion: If True, the operator will wait for the 
instance to be
+        in the `terminated` state before returning.
+    """
+
+    template_fields: Sequence[str] = ("instance_id", "region_name")
+    ui_color = "#eeaa11"
+    ui_fgcolor = "#ffffff"
+
+    def __init__(
+        self,
+        *,
+        instance_ids: str | list[str],
+        aws_conn_id: str = "aws_default",
+        region_name: str | None = None,
+        poll_interval: int = 20,
+        max_attempts: int = 20,
+        wait_for_completion: bool = False,
+        **kwargs,
+    ):
+        super().__init__(**kwargs)
+        self.instance_ids = instance_ids
+        self.aws_conn_id = aws_conn_id
+        self.region_name = region_name
+        self.poll_interval = poll_interval
+        self.max_attempts = max_attempts
+        self.wait_for_completion = wait_for_completion
+
+    def execute(self, context: Context):
+        if isinstance(self.instance_ids, str):
+            self.instance_ids = [self.instance_ids]
+        ec2_hook = EC2Hook(aws_conn_id=self.aws_conn_id, 
region_name=self.region_name, api_type="client_type")
+        self.log.info("Rebooting EC2 instances %s", ", 
".join(self.instance_ids))
+        ec2_hook.conn.reboot_instances(InstanceIds=self.instance_ids)
+
+        if self.wait_for_completion:
+            ec2_hook.get_waiter("instance_running").wait(
+                InstanceIds=self.instance_ids,
+                WaiterConfig={
+                    "Delay": self.poll_interval,
+                    "MaxAttempts": self.max_attempts,
+                },
+            )
+
+
+class EC2HibernateInstanceOperator(BaseOperator):
+    """
+    Hibernate AWS EC2 instance using boto3.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:EC2HibernateInstanceOperator`
+
+    :param instance_ids: ID of the instance to be terminated.
+    :param aws_conn_id: AWS connection to use
+    :param region_name: AWS region name associated with the client.
+    :param poll_interval: Number of seconds to wait before attempting to
+        check state of instance. Only used if wait_for_completion is True. 
Default is 20.
+    :param max_attempts: Maximum number of attempts when checking state of 
instance.
+        Only used if wait_for_completion is True. Default is 20.
+    :param wait_for_completion: If True, the operator will wait for the 
instance to be
+        in the `terminated` state before returning.

Review Comment:
   ```suggestion
           in the `stopped` state before returning.
   ```



##########
airflow/providers/amazon/aws/operators/ec2.py:
##########
@@ -254,3 +255,128 @@ def execute(self, context: Context):
                         "MaxAttempts": self.max_attempts,
                     },
                 )
+
+
+class EC2RebootInstanceOperator(BaseOperator):
+    """
+    Reboot AWS EC2 instance using boto3.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:EC2RebootInstanceOperator`
+
+    :param instance_ids: ID of the instance to be terminated.
+    :param aws_conn_id: AWS connection to use
+    :param region_name: AWS region name associated with the client.
+    :param poll_interval: Number of seconds to wait before attempting to
+        check state of instance. Only used if wait_for_completion is True. 
Default is 20.
+    :param max_attempts: Maximum number of attempts when checking state of 
instance.
+        Only used if wait_for_completion is True. Default is 20.
+    :param wait_for_completion: If True, the operator will wait for the 
instance to be
+        in the `terminated` state before returning.
+    """
+
+    template_fields: Sequence[str] = ("instance_id", "region_name")

Review Comment:
   ```suggestion
       template_fields: Sequence[str] = ("instance_ids", "region_name")
   ```



##########
airflow/providers/amazon/aws/operators/ec2.py:
##########
@@ -254,3 +255,128 @@ def execute(self, context: Context):
                         "MaxAttempts": self.max_attempts,
                     },
                 )
+
+
+class EC2RebootInstanceOperator(BaseOperator):
+    """
+    Reboot AWS EC2 instance using boto3.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:EC2RebootInstanceOperator`
+
+    :param instance_ids: ID of the instance to be terminated.
+    :param aws_conn_id: AWS connection to use
+    :param region_name: AWS region name associated with the client.
+    :param poll_interval: Number of seconds to wait before attempting to
+        check state of instance. Only used if wait_for_completion is True. 
Default is 20.
+    :param max_attempts: Maximum number of attempts when checking state of 
instance.
+        Only used if wait_for_completion is True. Default is 20.
+    :param wait_for_completion: If True, the operator will wait for the 
instance to be
+        in the `terminated` state before returning.
+    """
+
+    template_fields: Sequence[str] = ("instance_id", "region_name")
+    ui_color = "#eeaa11"
+    ui_fgcolor = "#ffffff"
+
+    def __init__(
+        self,
+        *,
+        instance_ids: str | list[str],
+        aws_conn_id: str = "aws_default",
+        region_name: str | None = None,
+        poll_interval: int = 20,
+        max_attempts: int = 20,
+        wait_for_completion: bool = False,
+        **kwargs,
+    ):
+        super().__init__(**kwargs)
+        self.instance_ids = instance_ids
+        self.aws_conn_id = aws_conn_id
+        self.region_name = region_name
+        self.poll_interval = poll_interval
+        self.max_attempts = max_attempts
+        self.wait_for_completion = wait_for_completion
+
+    def execute(self, context: Context):
+        if isinstance(self.instance_ids, str):
+            self.instance_ids = [self.instance_ids]
+        ec2_hook = EC2Hook(aws_conn_id=self.aws_conn_id, 
region_name=self.region_name, api_type="client_type")
+        self.log.info("Rebooting EC2 instances %s", ", 
".join(self.instance_ids))
+        ec2_hook.conn.reboot_instances(InstanceIds=self.instance_ids)
+
+        if self.wait_for_completion:
+            ec2_hook.get_waiter("instance_running").wait(
+                InstanceIds=self.instance_ids,
+                WaiterConfig={
+                    "Delay": self.poll_interval,
+                    "MaxAttempts": self.max_attempts,
+                },
+            )
+
+
+class EC2HibernateInstanceOperator(BaseOperator):
+    """
+    Hibernate AWS EC2 instance using boto3.

Review Comment:
   ```suggestion
       Hibernate Amazon EC2 instance.
   ```



##########
airflow/providers/amazon/aws/operators/ec2.py:
##########
@@ -254,3 +255,128 @@ def execute(self, context: Context):
                         "MaxAttempts": self.max_attempts,
                     },
                 )
+
+
+class EC2RebootInstanceOperator(BaseOperator):
+    """
+    Reboot AWS EC2 instance using boto3.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:EC2RebootInstanceOperator`
+
+    :param instance_ids: ID of the instance to be terminated.
+    :param aws_conn_id: AWS connection to use
+    :param region_name: AWS region name associated with the client.
+    :param poll_interval: Number of seconds to wait before attempting to
+        check state of instance. Only used if wait_for_completion is True. 
Default is 20.
+    :param max_attempts: Maximum number of attempts when checking state of 
instance.
+        Only used if wait_for_completion is True. Default is 20.
+    :param wait_for_completion: If True, the operator will wait for the 
instance to be
+        in the `terminated` state before returning.
+    """
+
+    template_fields: Sequence[str] = ("instance_id", "region_name")
+    ui_color = "#eeaa11"
+    ui_fgcolor = "#ffffff"
+
+    def __init__(
+        self,
+        *,
+        instance_ids: str | list[str],
+        aws_conn_id: str = "aws_default",
+        region_name: str | None = None,
+        poll_interval: int = 20,
+        max_attempts: int = 20,
+        wait_for_completion: bool = False,
+        **kwargs,
+    ):
+        super().__init__(**kwargs)
+        self.instance_ids = instance_ids
+        self.aws_conn_id = aws_conn_id
+        self.region_name = region_name
+        self.poll_interval = poll_interval
+        self.max_attempts = max_attempts
+        self.wait_for_completion = wait_for_completion
+
+    def execute(self, context: Context):
+        if isinstance(self.instance_ids, str):
+            self.instance_ids = [self.instance_ids]
+        ec2_hook = EC2Hook(aws_conn_id=self.aws_conn_id, 
region_name=self.region_name, api_type="client_type")
+        self.log.info("Rebooting EC2 instances %s", ", 
".join(self.instance_ids))
+        ec2_hook.conn.reboot_instances(InstanceIds=self.instance_ids)
+
+        if self.wait_for_completion:
+            ec2_hook.get_waiter("instance_running").wait(
+                InstanceIds=self.instance_ids,
+                WaiterConfig={
+                    "Delay": self.poll_interval,
+                    "MaxAttempts": self.max_attempts,
+                },
+            )
+
+
+class EC2HibernateInstanceOperator(BaseOperator):
+    """
+    Hibernate AWS EC2 instance using boto3.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:EC2HibernateInstanceOperator`
+
+    :param instance_ids: ID of the instance to be terminated.
+    :param aws_conn_id: AWS connection to use
+    :param region_name: AWS region name associated with the client.
+    :param poll_interval: Number of seconds to wait before attempting to
+        check state of instance. Only used if wait_for_completion is True. 
Default is 20.
+    :param max_attempts: Maximum number of attempts when checking state of 
instance.
+        Only used if wait_for_completion is True. Default is 20.
+    :param wait_for_completion: If True, the operator will wait for the 
instance to be
+        in the `terminated` state before returning.
+    """
+
+    template_fields: Sequence[str] = ("instance_id", "region_name")

Review Comment:
   ```suggestion
       template_fields: Sequence[str] = ("instance_ids", "region_name")
   ```



-- 
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.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to