-
Notifications
You must be signed in to change notification settings - Fork 343
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
Add initial work on new spot instance module #407
Conversation
There was a problem hiding this 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!
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
choices: [ "one-time", "persistent" ] | ||
type: str | ||
valid_from: | ||
description: |
There was a problem hiding this comment.
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.
plugins/modules/ec2_spot_instance.py
Outdated
default: [] | ||
type: list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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()), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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()), |
There was a problem hiding this comment.
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
|
||
if state == 'absent': | ||
response = cancel_spot_instance_requests(module, connection) | ||
changed = True |
There was a problem hiding this comment.
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
|
||
if state == 'present': | ||
response = request_spot_instances(module, connection) | ||
changed = True |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Outdated
- > | ||
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. |
There was a problem hiding this comment.
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.
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
b94e34c
to
eb2df32
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks for all your hard work on this @srirachanaachyuthuni, it's merging into the collection and will be released soon! |
* 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
SUMMARY
Working on a new EC2 spot instance module
ISSUE TYPE
COMPONENT NAME
ec2_spot_instance
ADDITIONAL INFORMATION