WIP: enable EC2 Spot usage in AWS
Change-Id: I9868d014991d78e7b2421439403ae1371b33524c
This commit is contained in:
parent
f399292401
commit
62bdc0bbe4
|
@ -66,6 +66,7 @@ Selecting the ``aws`` driver adds the following options to the
|
|||
cloud-image: debian9
|
||||
instance-type: t3.large
|
||||
key-name: zuul
|
||||
use-spot: True
|
||||
tags:
|
||||
key1: value1
|
||||
key2: value2
|
||||
|
@ -717,3 +718,10 @@ Selecting the ``aws`` driver adds the following options to the
|
|||
.. _`VM Import/Export service role`: https://docs.aws.amazon.com/vm-import/latest/userguide/vmie_prereqs.html#vmimport-role
|
||||
.. _`instance quotas`: https://us-west-1.console.aws.amazon.com/servicequotas/home/services/ec2/quotas
|
||||
.. _`AWS RegisterImage API documentation`: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RegisterImage.html
|
||||
|
||||
.. attr:: use-spot
|
||||
:type: bool
|
||||
:default: False
|
||||
|
||||
When set to True, nodepool will try to launch an EC2 Spot
|
||||
instance, instead of an On-Demand instance.
|
|
@ -834,6 +834,16 @@ class AwsAdapter(statemachine.Adapter):
|
|||
del mapping['Ebs']['Encrypted']
|
||||
args['BlockDeviceMappings'] = [mapping]
|
||||
|
||||
# enable EC2 Spot
|
||||
if label.use_spot:
|
||||
args['InstanceMarketOptions'] = {
|
||||
'MarketType': 'spot',
|
||||
'SpotOptions': {
|
||||
'SpotInstanceType': 'one-time',
|
||||
'InstanceInterruptionBehavior': 'terminate'
|
||||
}
|
||||
}
|
||||
|
||||
with self.rate_limiter(log.debug, "Created instance"):
|
||||
log.debug(f"Creating VM {hostname}")
|
||||
instances = self.ec2.create_instances(**args)
|
||||
|
|
|
@ -177,6 +177,7 @@ class AwsLabel(ConfigValue):
|
|||
self.tags = label.get('tags', {})
|
||||
self.dynamic_tags = label.get('dynamic-tags', {})
|
||||
self.host_key_checking = self.pool.host_key_checking
|
||||
self.use_spot = bool(label.get('use-spot', False))
|
||||
|
||||
@staticmethod
|
||||
def getSchema():
|
||||
|
@ -198,6 +199,7 @@ class AwsLabel(ConfigValue):
|
|||
},
|
||||
'tags': dict,
|
||||
'dynamic-tags': dict,
|
||||
'use-spot': bool
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue