Skip to content

Commit

Permalink
better authentication failure handling
Browse files Browse the repository at this point in the history
  • Loading branch information
caplan committed Oct 6, 2016
1 parent 92540a8 commit 3374024
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions soloutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ def _connect(ip, await=True, silent=False):
socket.setdefaulttimeout(5)
message = silent
start = time.time()
tryCount = 0
while True:

if (tryCount >= 5):
print 'error: unable to connect after {} attempts, giving up.'.format(tryCount)
sys.exit(1)

tryCount = tryCount + 1

try:
client.connect(ip, username='root', password='TjSDBkAu', timeout=5)
except paramiko.BadHostKeyException:
Expand All @@ -39,15 +47,18 @@ def _connect(ip, await=True, silent=False):
print ''
print 'and try again'
sys.exit(1)
except paramiko.AuthenticationException as e:
print 'ssh authentication error'
raise e
except Exception as e:
if not await:
raise e
if not message and time.time() - start > 5:
if not message and time.time() - start > 2:
message = True
print '(note: ensure you are connected to Solo\'s wifi network.)'
client.close()
time.sleep(1)
continue
time.sleep(1)
break
socket.setdefaulttimeout(None)

Expand Down

0 comments on commit 3374024

Please sign in to comment.