diff options
author | Viktor Utkin <vutkin@users.noreply.github.com> | 2019-02-07 19:08:19 +0300 |
---|---|---|
committer | Abhijeet Kasurde <akasurde@redhat.com> | 2019-02-07 21:38:19 +0530 |
commit | d40f0313e2b1c6cf91ada4cb35e19a24ef404675 (patch) | |
tree | 5e487ec0f6bbab29d8e7e88cf7913bbbc339f0e5 /lib/ansible/modules/cloud | |
parent | 890394aeed4b9a999be4ba35c9e57cfc94d00af2 (diff) | |
download | ansible-d40f0313e2b1c6cf91ada4cb35e19a24ef404675.tar.gz |
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
Diffstat (limited to 'lib/ansible/modules/cloud')
-rw-r--r-- | lib/ansible/modules/cloud/amazon/ec2.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/ansible/modules/cloud/amazon/ec2.py b/lib/ansible/modules/cloud/amazon/ec2.py index 1de6ccea4f..f7130b723c 100644 --- a/lib/ansible/modules/cloud/amazon/ec2.py +++ b/lib/ansible/modules/cloud/amazon/ec2.py @@ -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 |