Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial work on new spot instance module #407

Merged

Conversation

srirachanaachyuthuni
Copy link
Contributor

SUMMARY

Working on a new EC2 spot instance module

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

ec2_spot_instance

ADDITIONAL INFORMATION

@ansibullbot
Copy link

Copy link
Collaborator

@jillr jillr left a comment

Choose a reason for hiding this comment

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

The module currently has a number of options specified as parameters that need to be subkeys of LaunchSpecification. We could list them all out individually and then build a LaunchSpecification from the params, but if we do that we shouldn't also have a separate launch_specification option.

Please make sure your API calls are wrapped in try/except blocks and that both botocore.exceptions.BotoCoreError and botocore.exceptions.ClientError are handled in the except. Please also return information about the created spot request (and document the return data). Good work so far!

plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Jul 20, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Jul 20, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Jul 20, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Jul 20, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Jul 20, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Jul 20, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Jul 20, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Jul 20, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Jul 21, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
choices: [ "one-time", "persistent" ]
type: str
valid_from:
description:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ansible doesn't support datetime parameters so the best thing we can probably do is describe what the data needs to look like, take it as a string, and convert it. I don't love this option though. :( I can try to find an example of a module that does something similar but I don't know of one offhand.

Comment on lines 159 to 160
default: []
type: list
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
default: []
type: list
default: {}
type: dict

Tags should be a dictionary, there's a module util for doing most of the work. https://github.com/ansible-collections/amazon.aws/blob/main/plugins/module_utils/ec2.py#L908

plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
count=dict(type='int', default=1),
interruption=dict(type='str', default="terminate"),
launch_group=dict(type='str', default=' '),
launch_specification=dict(type='dict', default=dict()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

When you document this key, it can be helpful for readability to put the suboptions in a separate var like this https://github.com/ansible-collections/amazon.aws/blob/main/plugins/modules/ec2_ami.py#L703

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please make sure the suboptions of these arguments:
launch_specification
block_device_mappings
network_interfaces
placement
monitoring

Are properly defined as such. You need an options key in the arg spec for each parameter that contains the spec for the suboptions.
https://docs.ansible.com/ansible/devel/dev_guide/developing_program_flow_modules.html#argument-spec

plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
count=dict(type='int', default=1),
interruption=dict(type='str', default="terminate"),
launch_group=dict(type='str', default=' '),
launch_specification=dict(type='dict', default=dict()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please make sure the suboptions of these arguments:
launch_specification
block_device_mappings
network_interfaces
placement
monitoring

Are properly defined as such. You need an options key in the arg spec for each parameter that contains the spec for the suboptions.
https://docs.ansible.com/ansible/devel/dev_guide/developing_program_flow_modules.html#argument-spec


if state == 'absent':
response = cancel_spot_instance_requests(module, connection)
changed = True
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will report True even if the spot instance is already cancelled or does not exist. Please describe_spot_instance_requests() first to determine if there is work to do before setting changed status/running the cancellation.

plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved

if state == 'present':
response = request_spot_instances(module, connection)
changed = True
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does the API do if a request that matches all the parameters already exists? Does it recreate it or is there no change?

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 have been running the same playbook for testing. It creates a new request each time since even if the parameters are the same, Boto3 considers it as a new request for a spot instance with the same configuration.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In this case we should handle idempotency inside the module by checking for existing requests and comparing them to the specification then. Let's get the current functionality sorted out and then we can work on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

plugins/modules/ec2_spot_instance.py Show resolved Hide resolved
Comment on lines 14 to 16
- >
Note: This module uses the boto3 Python module to interact with the EC2 API.
M(amazon.aws.ec2) will still support the older boto Python module to interact with spot instances.
Copy link
Contributor

@tremble tremble Jul 30, 2021

Choose a reason for hiding this comment

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

We can lose this note. The old boto SDK is no longer supported upstream and by adding the document fragment we automatically add a note about which Python modules we require.

alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Aug 23, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Aug 23, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Aug 23, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Aug 23, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Aug 23, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
@jillr jillr changed the title (WIP) Add initial work on new spot instance module Add initial work on new spot instance module Aug 24, 2021
@jillr jillr requested a review from tremble August 24, 2021 23:34
alinabuzachis pushed a commit that referenced this pull request Aug 25, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit that referenced this pull request Aug 25, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit that referenced this pull request Aug 26, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit that referenced this pull request Aug 26, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
alinabuzachis pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Aug 26, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_spot_instance.py Outdated Show resolved Hide resolved
jillr pushed a commit to alinabuzachis/amazon.aws that referenced this pull request Aug 27, 2021
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@701153a
@jillr jillr requested review from alinabuzachis and goneri August 30, 2021 16:54
@jillr jillr force-pushed the ec2_spot_instance branch from b94e34c to eb2df32 Compare August 31, 2021 00:35
Copy link
Collaborator

@alinabuzachis alinabuzachis left a comment

Choose a reason for hiding this comment

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

LGTM!

@jillr jillr dismissed tremble’s stale review August 31, 2021 16:40

zuul doesn't like -1 reviews

@jillr jillr added the gate label Aug 31, 2021
Copy link
Contributor

@ansible-zuul ansible-zuul bot left a comment

Choose a reason for hiding this comment

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

LGTM!

@jillr
Copy link
Collaborator

jillr commented Aug 31, 2021

Thanks for all your hard work on this @srirachanaachyuthuni, it's merging into the collection and will be released soon!

@jillr jillr added gate and removed gate labels Aug 31, 2021
@ansible-zuul ansible-zuul bot merged commit 62e1387 into ansible-collections:main Aug 31, 2021
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Oct 24, 2023
* Remove ec2_vpc_nat_gateway unit tests
* update comments in ec2_vpc_nat_gateway integration tests - they're not based on the hard coded check_mode results any more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community_review integration tests/integration module module new_module New module new_plugin New plugin plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants