From 1f5cd1bfb6fa8932b0696f574218c49542ef1870 Mon Sep 17 00:00:00 2001 From: Roger Caplan Date: Fri, 30 Sep 2016 16:12:35 -0400 Subject: [PATCH] better authentication failure handling --- soloutils/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/soloutils/__init__.py b/soloutils/__init__.py index 89c655d..793eb9e 100644 --- a/soloutils/__init__.py +++ b/soloutils/__init__.py @@ -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: @@ -39,6 +47,9 @@ 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