Commit bc6caae7 authored by Simon Redman's avatar Simon Redman

Fix boo-boo when failing over to password-based SSH login

parent 97aac97f
......@@ -28,16 +28,19 @@ def login_password_failover(session, hostname, username, password=""):
:param hostname: remote to connect to
:param username: login username
:param password: login password -- Will be prompted for if needed and not passed
:return: password if key-based login failed, otherwise None
:return: password if key-based login failed, otherwise empty string
# First, try in-memory authentication tools, including the password if it is defined
session.login(hostname, username, password)
return None
return ""
except pxssh.ExceptionPxssh:
session.close() # Unlikely to be necessary, but make sure the pxssh file descriptor, etc. get cleaned up
# That didn't work. Try a password.
# Make a new session because you can only use each once
original_force_password = session.force_password
session = pxssh.pxssh(options=session.options)
session.force_password = True # Probably never necessary -- we already tried key-based login
password = getpass.getpass("Password for {user}@{host}: ".format(user=username, host=hostname))
session.login(hostname, username, password)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment