Skip to content

Commit

Permalink
Merge pull request #114 from spotty-cloud/dev
Browse files Browse the repository at this point in the history
AWS: use a private IP address when an instance doesn't have a public one
  • Loading branch information
apls777 committed May 19, 2022
2 parents 3ac3498 + 995d58f commit d50f10a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion spotty/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.2'
__version__ = '1.3.3'
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,11 @@ def ssh_host(self):
if not instance or not instance.is_running:
raise InstanceNotRunningError(self.instance_config.name)

public_ip_address = instance.public_ip_address
if not public_ip_address:
raise ValueError('The running instance doesn\'t have a public IP address.\n'
'Use the "localSshPort" parameter if you want to create a tunnel to the instance.')
instance_ip_address = instance.public_ip_address if instance.public_ip_address else instance.private_ip_address
if not instance_ip_address:
raise ValueError('Instance IP address not found')

return public_ip_address
return instance_ip_address

@property
def ssh_port(self) -> int:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class AbstractInstance(ABC):
def public_ip_address(self):
raise NotImplementedError

@property
def private_ip_address(self):
raise NotImplementedError

@property
def is_running(self):
"""Returns true if the instance is running."""
Expand Down
2 changes: 2 additions & 0 deletions spotty/providers/aws/instance_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def get_status_text(self):

if instance.public_ip_address:
table.append(('Public IP Address', instance.public_ip_address))
elif instance.private_ip_address:
table.append(('Private IP Address', instance.private_ip_address))

if instance.lifecycle == 'spot':
spot_price = instance.get_spot_price()
Expand Down
4 changes: 4 additions & 0 deletions spotty/providers/aws/resources/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def instance_id(self):
def public_ip_address(self) -> str:
return self._data.get('PublicIpAddress', None)

@property
def private_ip_address(self) -> str:
return self._data.get('PrivateIpAddress', None)

@property
def state(self) -> str:
return self._data['State']['Name']
Expand Down

0 comments on commit d50f10a

Please sign in to comment.