mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-29 11:40:22 -07:00
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
This commit is contained in:
parent
890394aeed
commit
d40f0313e2
2 changed files with 12 additions and 0 deletions
|
@ -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 time
|
||||||
|
import datetime
|
||||||
import traceback
|
import traceback
|
||||||
from ast import literal_eval
|
from ast import literal_eval
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
|
@ -1191,6 +1192,15 @@ def create_instances(module, ec2, vpc, override_count=None):
|
||||||
count=count_remaining,
|
count=count_remaining,
|
||||||
type=spot_type,
|
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)
|
res = ec2.request_spot_instances(spot_price, **params)
|
||||||
|
|
||||||
# Now we have to do the intermediate waiting
|
# Now we have to do the intermediate waiting
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue