sped up instance creation

This commit is contained in:
Ari Brown 2023-10-12 14:31:39 -04:00
parent bfb5dda6d9
commit c8a29cfcd3
2 changed files with 9 additions and 7 deletions

View file

@ -75,8 +75,6 @@ class Machine:
self.thread.join() self.thread.join()
def wait(self, n): def wait(self, n):
time.sleep(n) # give time for AWS to register that the instance has been created
i = 0 i = 0
# Time for the server to show as "running" # Time for the server to show as "running"
# and time for the server to finish getting daemons running # and time for the server to finish getting daemons running
@ -88,6 +86,9 @@ class Machine:
reason = f"{self.info['InstanceId']} took too long to start ({i} attempts)" reason = f"{self.info['InstanceId']} took too long to start ({i} attempts)"
raise Exception(reason) raise Exception(reason)
# Final wait, now that the server is up and running -- need
# some time for daemons to start
time.sleep(25)
self.ready = True self.ready = True
# alternatively, could maybe implement this with SSM so that we can access # alternatively, could maybe implement this with SSM so that we can access
@ -96,15 +97,16 @@ class Machine:
if self.ssh: if self.ssh:
return True return True
if not self.public:
raise Exception("Can only log into server that has a public IP")
# Machine must be running first, so we need to wait for the countdown to finish # Machine must be running first, so we need to wait for the countdown to finish
self.join() self.join()
# Final wait, now that the server is up and running -- need some time for daemons to start
time.sleep(25)
resp = self.pier.ec2.describe_instances(InstanceIds=[self.info['InstanceId']]) resp = self.pier.ec2.describe_instances(InstanceIds=[self.info['InstanceId']])
self.description = resp['Reservations'][0]['Instances'][0] self.description = resp['Reservations'][0]['Instances'][0]
self.public_ip = self.description['PublicIpAddress'] self.public_ip = self.description['PublicIpAddress']
print(f"\t{self.name} ({self.info['InstanceId']}) => {self.public_ip} ({self.private_ip})") print(f"\t{self.name} ({self.info['InstanceId']}) => {self.public_ip} ({self.private_ip})")
self.ssh = Connection(self.public_ip, self.ssh = Connection(self.public_ip,

View file

@ -30,8 +30,8 @@ class Pier:
self.make_key_pair() self.make_key_pair()
def make_key_pair(self): def make_key_pair(self):
print("making keypair")
self.key_pair_name = f"Minerva-{random.random()}" self.key_pair_name = f"Minerva-{random.random()}"
print(f"making keypair ({self.key_pair_name})")
self.key = self.ec2.create_key_pair(KeyName=self.key_pair_name) self.key = self.ec2.create_key_pair(KeyName=self.key_pair_name)
self.key_path = "/tmp/key" self.key_path = "/tmp/key"