1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

waiting enhancements

This commit is contained in:
milan 2013-03-07 18:01:55 +01:00
parent 78d1e2483a
commit d32d899161

View file

@ -71,6 +71,11 @@ options:
required: false required: false
default: false default: false
aliases: [] aliases: []
wait_timeout:
descritption:
- How long before wait gives up. In seconds.
- default: 300
aliases: []
ec2_url: ec2_url:
description: description:
- url to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints) - url to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints)
@ -152,6 +157,7 @@ def main():
monitoring = dict(choices=BOOLEANS, default=False), monitoring = dict(choices=BOOLEANS, default=False),
ramdisk = dict(), ramdisk = dict(),
wait = dict(choices=BOOLEANS, default=False), wait = dict(choices=BOOLEANS, default=False),
wait_timeout = dict(default=300),
ec2_url = dict(aliases=['EC2_URL']), ec2_url = dict(aliases=['EC2_URL']),
ec2_secret_key = dict(aliases=['EC2_SECRET_KEY'], no_log=True), ec2_secret_key = dict(aliases=['EC2_SECRET_KEY'], no_log=True),
ec2_access_key = dict(aliases=['EC2_ACCESS_KEY']), ec2_access_key = dict(aliases=['EC2_ACCESS_KEY']),
@ -171,6 +177,7 @@ def main():
kernel = module.params.get('kernel') kernel = module.params.get('kernel')
ramdisk = module.params.get('ramdisk') ramdisk = module.params.get('ramdisk')
wait = module.params.get('wait') wait = module.params.get('wait')
wait_timeout = int(module.params.get('wait_timeout'))
ec2_url = module.params.get('ec2_url') ec2_url = module.params.get('ec2_url')
ec2_secret_key = module.params.get('ec2_secret_key') ec2_secret_key = module.params.get('ec2_secret_key')
ec2_access_key = module.params.get('ec2_access_key') ec2_access_key = module.params.get('ec2_access_key')
@ -221,6 +228,16 @@ def main():
module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message)) module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message))
instids = [ i.id for i in res.instances ] instids = [ i.id for i in res.instances ]
while True:
try:
res.connection.get_all_instances(instids)
break
except boto.exception.EC2ResponseError as e:
if "<Code>InvalidInstanceID.NotFound</Code>" in str(e):
# there's a race between start and get an instance
continue
else:
module.fail_json(msg = str(e))
if instance_tags: if instance_tags:
try: try:
@ -228,20 +245,19 @@ def main():
except boto.exception.EC2ResponseError as e: except boto.exception.EC2ResponseError as e:
module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message)) module.fail_json(msg = "%s: %s" % (e.error_code, e.error_message))
# wait here until the instances are up
res_list = res.connection.get_all_instances(instids) res_list = res.connection.get_all_instances(instids)
this_res = res_list[0] this_res = res_list[0]
if wait: num_running = 0
# there's a race between start and get an instance state wait_timeout = time.time() + wait_timeout
import time while wait and wait_timeout > time.time() and num_running < len(instids):
res_list = res.connection.get_all_instances(instids)
this_res = res_list[0]
num_running = len([ i for i in this_res.instances if i.state=='running' ])
time.sleep(5) time.sleep(5)
# wait here until the instances are up if wait and wait_timeout <= time.time():
num_running = 0 # waiting took too long
while num_running != len(instids): module.fail_json(msg = "wait for instances running timeout on %s" % time.asctime())
res_list = res.connection.get_all_instances(instids)
this_res = res_list[0]
num_running = len([ i for i in this_res.instances if i.state=='running' ])
time.sleep(5)
instances = [] instances = []
for inst in this_res.instances: for inst in this_res.instances:
d = { d = {