mirror of
https://github.com/certbot/certbot.git
synced 2026-06-04 22:33:00 -04:00
Merge remote-tracking branch 'origin/fix-race-condition' into test-letstest-all-changes
This commit is contained in:
commit
c92ef367a4
1 changed files with 7 additions and 19 deletions
|
|
@ -150,9 +150,11 @@ def make_instance(ec2_client,
|
|||
subnet_id,
|
||||
machine_type='t2.micro',
|
||||
userdata=""): #userdata contains bash or cloud-init script
|
||||
|
||||
new_instance = ec2_client.create_instances(
|
||||
BlockDeviceMappings=_get_block_device_mappings(ec2_client, ami_id),
|
||||
block_device_mappings = _get_block_device_mappings(ec2_client, ami_id)
|
||||
tags = [{'Key': 'Name', 'Value': instance_name}]
|
||||
tag_spec = [{'ResourceType': 'instance', 'Tags': tags}]
|
||||
return ec2_client.create_instances(
|
||||
BlockDeviceMappings=block_device_mappings,
|
||||
ImageId=ami_id,
|
||||
SecurityGroupIds=[security_group_id],
|
||||
SubnetId=subnet_id,
|
||||
|
|
@ -160,22 +162,8 @@ def make_instance(ec2_client,
|
|||
MinCount=1,
|
||||
MaxCount=1,
|
||||
UserData=userdata,
|
||||
InstanceType=machine_type)[0]
|
||||
|
||||
# brief pause to prevent rare error on EC2 delay, should block until ready instead
|
||||
time.sleep(1.0)
|
||||
|
||||
# give instance a name
|
||||
try:
|
||||
new_instance.create_tags(Tags=[{'Key': 'Name', 'Value': instance_name}])
|
||||
except ClientError as e:
|
||||
if "InvalidInstanceID.NotFound" in str(e):
|
||||
# This seems to be ephemeral... retry
|
||||
time.sleep(1)
|
||||
new_instance.create_tags(Tags=[{'Key': 'Name', 'Value': instance_name}])
|
||||
else:
|
||||
raise
|
||||
return new_instance
|
||||
InstanceType=machine_type,
|
||||
TagSpecifications=tag_spec)[0]
|
||||
|
||||
def _get_block_device_mappings(ec2_client, ami_id):
|
||||
"""Returns the list of block device mappings to ensure cleanup.
|
||||
|
|
|
|||
Loading…
Reference in a new issue