def ssh(self, host=None, user=None, port=None): msg = ("Establishing ssh connection with '{}' " "through port '{}' as user '{}'") logger.debug(msg.format(host, port, user)) ssh = paramiko.SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) if self.ask_password and self.password is None: msg = ("Enter a private key passphrase or a password for " "host '{}' port '{}' user '{}'").format(host, port, user) self.password = prompt.password(msg) ssh.connect( host, username=user, port=port, key_filename=self.keyfile, timeout=self.timeout, password=self.password, ) return ssh
def ask_password(host, user, port): return prompt.password( "Enter a private key passphrase or a password for " "host '{host}' port '{port}' user '{user}'".format( host=host, port=port, user=user ) )
def ssh(self, path_info): host, user, port = path_info.host, path_info.user, path_info.port # NOTE: we use the same password regardless of the server :( if self.ask_password and self.password is None: with saved_passwords_lock: server_key = (host, user, port) password = saved_passwords.get(server_key) if password is None: saved_passwords[server_key] = password = prompt.password( "Enter a private key passphrase or a password for " "host '{host}' port '{port}' user '{user}'".format( host=host, port=port, user=user)) self.password = password return get_connection( SSHConnection, host, username=user, port=port, key_filename=self.keyfile, timeout=self.timeout, password=self.password, )
def ssh(self, path_info): host, user, port = path_info.host, path_info.user, path_info.port logger.debug( "Establishing ssh connection with '{host}' " "through port '{port}' as user '{user}'".format( host=host, user=user, port=port ) ) if self.ask_password and not self.password: self.password = prompt.password( "Enter a private key passphrase or a password for " "host '{host}' port '{port}' user '{user}'".format( host=host, port=port, user=user ) ) return SSHConnection( host, username=user, port=port, key_filename=self.keyfile, timeout=self.timeout, password=self.password, )
def ensure_credentials(self, path_info=None): if path_info is None: path_info = self.path_info host, user, port = path_info.host, path_info.user, path_info.port # NOTE: we use the same password regardless of the server :( if self.ask_password and self.password is None: with saved_passwords_lock: server_key = (host, user, port) password = saved_passwords.get(server_key) if password is None: saved_passwords[server_key] = password = prompt.password( "Enter a private key passphrase or a password for " "host '{host}' port '{port}' user '{user}'".format( host=host, port=port, user=user)) self.password = password
def ssh(self, path_info): host, user, port = path_info.host, path_info.user, path_info.port # NOTE: we use the same password regardless of the server :( if self.ask_password and not self.password: self.password = prompt.password( "Enter a private key passphrase or a password for " "host '{host}' port '{port}' user '{user}'".format(host=host, port=port, user=user)) return ssh_connection( host, username=user, port=port, key_filename=self.keyfile, timeout=self.timeout, password=self.password, )
def ask_password(host, user): return prompt.password("Enter a password for " "host '{host}' user '{user}'".format(host=host, user=user))