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
|
cloud-image: debian9
|
||||||
instance-type: t3.large
|
instance-type: t3.large
|
||||||
key-name: zuul
|
key-name: zuul
|
||||||
|
use-spot: True
|
||||||
tags:
|
tags:
|
||||||
key1: value1
|
key1: value1
|
||||||
key2: value2
|
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
|
.. _`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
|
.. _`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
|
.. _`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']
|
del mapping['Ebs']['Encrypted']
|
||||||
args['BlockDeviceMappings'] = [mapping]
|
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"):
|
with self.rate_limiter(log.debug, "Created instance"):
|
||||||
log.debug(f"Creating VM {hostname}")
|
log.debug(f"Creating VM {hostname}")
|
||||||
instances = self.ec2.create_instances(**args)
|
instances = self.ec2.create_instances(**args)
|
||||||
|
|
|
@ -177,6 +177,7 @@ class AwsLabel(ConfigValue):
|
||||||
self.tags = label.get('tags', {})
|
self.tags = label.get('tags', {})
|
||||||
self.dynamic_tags = label.get('dynamic-tags', {})
|
self.dynamic_tags = label.get('dynamic-tags', {})
|
||||||
self.host_key_checking = self.pool.host_key_checking
|
self.host_key_checking = self.pool.host_key_checking
|
||||||
|
self.use_spot = bool(label.get('use-spot', False))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getSchema():
|
def getSchema():
|
||||||
|
@ -198,6 +199,7 @@ class AwsLabel(ConfigValue):
|
||||||
},
|
},
|
||||||
'tags': dict,
|
'tags': dict,
|
||||||
'dynamic-tags': dict,
|
'dynamic-tags': dict,
|
||||||
|
'use-spot': bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue