Merge pull request #597 from jbbarth/bug/fix-ec2-spot-provisionning/423
EC2: move logic about terminated instances up (#423)
This commit is contained in:
commit
095f8681db
1 changed files with 12 additions and 9 deletions
21
cloud/amazon/ec2.py
Normal file → Executable file
21
cloud/amazon/ec2.py
Normal file → Executable file
|
@ -915,6 +915,18 @@ def create_instances(module, ec2, override_count=None):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg = str(e))
|
module.fail_json(msg = str(e))
|
||||||
|
|
||||||
|
# The instances returned through ec2.run_instances above can be in
|
||||||
|
# terminated state due to idempotency. See commit 7f11c3d for a complete
|
||||||
|
# explanation.
|
||||||
|
terminated_instances = [
|
||||||
|
str(instance.id) for instance in res.instances if instance.state == 'terminated'
|
||||||
|
]
|
||||||
|
if terminated_instances:
|
||||||
|
module.fail_json(msg = "Instances with id(s) %s " % terminated_instances +
|
||||||
|
"were created previously but have since been terminated - " +
|
||||||
|
"use a (possibly different) 'instanceid' parameter")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if private_ip:
|
if private_ip:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
|
@ -952,15 +964,6 @@ def create_instances(module, ec2, override_count=None):
|
||||||
except boto.exception.BotoServerError, e:
|
except boto.exception.BotoServerError, e:
|
||||||
module.fail_json(msg = "Instance creation failed => %s: %s" % (e.error_code, e.error_message))
|
module.fail_json(msg = "Instance creation failed => %s: %s" % (e.error_code, e.error_message))
|
||||||
|
|
||||||
# The instances returned through run_instances can be in
|
|
||||||
# terminated state due to idempotency.
|
|
||||||
terminated_instances = [ str(instance.id) for instance in res.instances
|
|
||||||
if instance.state == 'terminated' ]
|
|
||||||
if terminated_instances:
|
|
||||||
module.fail_json(msg = "Instances with id(s) %s " % terminated_instances +
|
|
||||||
"were created previously but have since been terminated - " +
|
|
||||||
"use a (possibly different) 'instanceid' parameter")
|
|
||||||
|
|
||||||
# wait here until the instances are up
|
# wait here until the instances are up
|
||||||
num_running = 0
|
num_running = 0
|
||||||
wait_timeout = time.time() + wait_timeout
|
wait_timeout = time.time() + wait_timeout
|
||||||
|
|
Loading…
Reference in a new issue