spot instance request stay opened when module exit with timeout (#51535)

Fixes: #51534

* set valid_until equal to current time + spot_wait_timeout
* add setting ValidUntil to  value
* add changelog fragment
* fix shebang issue
pull/51856/head
Viktor Utkin 6 years ago committed by Abhijeet Kasurde
parent 890394aeed
commit d40f0313e2

@ -0,0 +1,2 @@
bugfixes:
- ec2 - Correctly sets the end date of the Spot Instance request. Sets `ValidUntil` value in proper way so it will be auto-canceled through `spot_wait_timeout` interval.

@ -540,6 +540,7 @@ EXAMPLES = '''
'''
import time
import datetime
import traceback
from ast import literal_eval
from distutils.version import LooseVersion
@ -1191,6 +1192,15 @@ def create_instances(module, ec2, vpc, override_count=None):
count=count_remaining,
type=spot_type,
))
# Set spot ValidUntil
# ValidUntil -> (timestamp). The end date of the request, in
# UTC format (for example, YYYY -MM -DD T*HH* :MM :SS Z).
utc_valid_until = (
datetime.datetime.utcnow()
+ datetime.timedelta(seconds=spot_wait_timeout))
params['valid_until'] = utc_valid_until.strftime('%Y-%m-%dT%H:%M:%S.000Z')
res = ec2.request_spot_instances(spot_price, **params)
# Now we have to do the intermediate waiting

Loading…
Cancel
Save