mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 15:36:27 +00:00
ec2_launch: Store the instance object directly in the info dictionary
Instead of storing just its ID. This gives quick access to the recently created instance, which allows us to simplify the code that needs to fetch the instance object every time it was necessary.
This commit is contained in:
parent
b934808cce
commit
50d61c735d
1 changed files with 11 additions and 18 deletions
|
@ -26,14 +26,14 @@ class LaunchEC2Instance(Task):
|
||||||
r = conn.run_instances(info._ec2['image'],
|
r = conn.run_instances(info._ec2['image'],
|
||||||
security_group_ids=info.manifest.plugins['ec2_launch'].get('security_group_ids'),
|
security_group_ids=info.manifest.plugins['ec2_launch'].get('security_group_ids'),
|
||||||
instance_type=info.manifest.plugins['ec2_launch'].get('instance_type', 't2.micro'))
|
instance_type=info.manifest.plugins['ec2_launch'].get('instance_type', 't2.micro'))
|
||||||
info._ec2['instance_id'] = r.instances[0].id
|
info._ec2['instance'] = r.instances[0]
|
||||||
|
|
||||||
if 'tags' in info.manifest.plugins['ec2_launch']:
|
if 'tags' in info.manifest.plugins['ec2_launch']:
|
||||||
def apply_format(v):
|
def apply_format(v):
|
||||||
return v.format(**info.manifest_vars)
|
return v.format(**info.manifest_vars)
|
||||||
tags = info.manifest.plugins['ec2_launch']['tags']
|
tags = info.manifest.plugins['ec2_launch']['tags']
|
||||||
r = {k: apply_format(v) for k, v in tags.items()}
|
r = {k: apply_format(v) for k, v in tags.items()}
|
||||||
conn.create_tags([info._ec2['instance_id']], r)
|
conn.create_tags([info._ec2['instance'].id], r)
|
||||||
|
|
||||||
|
|
||||||
class PrintPublicIPAddress(Task):
|
class PrintPublicIPAddress(Task):
|
||||||
|
@ -50,22 +50,15 @@ class PrintPublicIPAddress(Task):
|
||||||
filename = '/dev/null'
|
filename = '/dev/null'
|
||||||
f = open(filename, 'w')
|
f = open(filename, 'w')
|
||||||
|
|
||||||
r = ec2['connection'].get_only_instances([ec2['instance_id']])
|
def instance_has_ip():
|
||||||
if not r and not r[0]:
|
ec2['instance'].update()
|
||||||
logger.error('Could not get instance metadata')
|
return ec2['instance'].ip_address
|
||||||
f.write('')
|
|
||||||
|
if waituntil(instance_has_ip, timeout=120, interval=5):
|
||||||
|
logger.info('******* EC2 IP ADDRESS: %s *******' % ec2['instance'].ip_address)
|
||||||
|
f.write(ec2['instance'].ip_address)
|
||||||
else:
|
else:
|
||||||
instance = r[0]
|
logger.error('Could not get IP address for the instance')
|
||||||
|
f.write('')
|
||||||
def instance_has_ip():
|
|
||||||
instance.update()
|
|
||||||
return instance.ip_address
|
|
||||||
|
|
||||||
if waituntil(instance_has_ip, timeout=120, interval=5):
|
|
||||||
logger.info('******* EC2 IP ADDRESS: %s *******' % instance.ip_address)
|
|
||||||
f.write(instance.ip_address)
|
|
||||||
else:
|
|
||||||
logger.error('Could not get IP address for the instance')
|
|
||||||
f.write('')
|
|
||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
Loading…
Add table
Reference in a new issue