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

ec2_asg: add support for Spot allocation #418

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions plugins/modules/ec2_asg.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@
- A list of instance_types.
type: list
elements: str
ondemand_base:
description:
- the minimum amount of capacity that must be fulfilled by On-Demand instances
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- the minimum amount of capacity that must be fulfilled by On-Demand instances
- "A baseline of the ASG's capacity which will be fulfilled using only on-demand instances."

type: int
ondemand_percentage_above_base:
description:
- percentages of on-demand instances beyond OnDemandBaseCapacity
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- percentages of on-demand instances beyond OnDemandBaseCapacity
- Defines the percentage of Instances above I(ondemand_base) which will be provisioned using on-demand Instances.
- The first I(ondemand_base) instances will be provisioned using on-demand instances.
- Capacity above I(ondemand_base) will be split between on-demand- and spot- instances based upon I(ondemand_percentage_above_base).

type: int
type: dict
placement_group:
description:
Expand Down Expand Up @@ -743,6 +751,10 @@ def get_properties(autoscaling_group):
raw_mixed_instance_object = autoscaling_group.get('MixedInstancesPolicy')
if raw_mixed_instance_object:
properties['mixed_instances_policy'] = [x['InstanceType'] for x in raw_mixed_instance_object.get('LaunchTemplate').get('Overrides')]
if 'OnDemandPercentageAboveBaseCapacity' in raw_mixed_instance_object.get('InstancesDistribution', []):
properties['ondemand_percentage_above_base'] = raw_mixed_instance_object.get('InstancesDistribution').get('OnDemandPercentageAboveBaseCapacity')
if 'OnDemandBaseCapacity' in raw_mixed_instance_object.get('InstancesDistribution', []):
properties['ondemand_base'] = raw_mixed_instance_object.get('InstancesDistribution').get('OnDemandBaseCapacity')

metrics = autoscaling_group.get('EnabledMetrics')
if metrics:
Expand Down Expand Up @@ -802,6 +814,10 @@ def get_launch_object(connection, ec2_connection):
for instance_type in instance_types:
instance_type_dict = {'InstanceType': instance_type}
policy['LaunchTemplate']['Overrides'].append(instance_type_dict)
policy['InstancesDistribution'] = {
'OnDemandPercentageAboveBaseCapacity': mixed_instances_policy.get('ondemand_percentage_above_base'),
'OnDemandBaseCapacity': mixed_instances_policy.get('ondemand_base')
}
launch_object['MixedInstancesPolicy'] = policy
return launch_object

Expand Down Expand Up @@ -1661,6 +1677,8 @@ def main():
type='list',
elements='str'
),
ondemand_percentage_above_base=dict(type='int'),
ondemand_base=dict(type='int')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ondemand_base=dict(type='int')
ondemand_base=dict(type='int'),

By leaving the comma at the end it simplifies patches for future features (they don't need to change this line, they just add the next one). Which then helps if you ever need to use git blame

)
),
placement_group=dict(type='str'),
Expand Down