diff --git a/minerva/machine.py b/minerva/machine.py index 9647dd0..9df3f2d 100644 --- a/minerva/machine.py +++ b/minerva/machine.py @@ -75,8 +75,6 @@ class Machine: self.thread.join() def wait(self, n): - time.sleep(n) # give time for AWS to register that the instance has been created - i = 0 # Time for the server to show as "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)" 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 # alternatively, could maybe implement this with SSM so that we can access @@ -96,15 +97,16 @@ class Machine: if self.ssh: 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 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']]) 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})") self.ssh = Connection(self.public_ip, diff --git a/minerva/pier.py b/minerva/pier.py index ef67672..2df1425 100644 --- a/minerva/pier.py +++ b/minerva/pier.py @@ -30,8 +30,8 @@ class Pier: self.make_key_pair() def make_key_pair(self): - print("making keypair") 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_path = "/tmp/key"