Skip to content

Conversation

@dashton90
Copy link
Contributor

Adds two new operators to Amazon provider package: EC2HibernateInstanceOperator, and EC2RebootInstanceOperator

closes: #35703

@dashton90 dashton90 force-pushed the add-ec2-reboot-and-hibernate-operators branch from cf52c49 to f8e294e Compare November 21, 2023 04:49

:param instance_id: id of the AWS EC2 instance
:param aws_conn_id: aws connection to use
:param region_name: (optional) aws region name associated with the client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bother marking just this one as optional but not the arg above and below? I'd either do it for all optional args or don't bother. Same for Hibernate operator below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I naively copied the EC2StartInstanceOperator setup. Switched to use the pattern established by more recent operators so there are no more optional args.

self.log.info("Rebooting EC2 instance %s", self.instance_id)
instance = ec2_hook.get_instance(instance_id=self.instance_id)
instance.reboot()
ec2_hook.wait_for_state(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually wrap waits like this with a wait_for_completion arg for folks who prefer to just fire and forget. Do you mind adding that here? If you grep for that arg name you'll see lots of examples. Also same for the Hibernate operator below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think I was using an outdated pattern (copied the set-up of EC2StartInstanceOperator). Updated the operators to accept a wait_for_completion parameter, and to use waiters

@dashton90 dashton90 closed this Nov 22, 2023
@dashton90 dashton90 deleted the add-ec2-reboot-and-hibernate-operators branch November 22, 2023 03:07
@dashton90 dashton90 restored the add-ec2-reboot-and-hibernate-operators branch November 22, 2023 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add EC2RebootInstanceOperator and EC2HibernateInstanceOperator to Amazon Provider

3 participants