For backward compatibility, only specify look_for_keys and allow_agent option if "password" and "key" arguments are not provided.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/3a86c01e Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/3a86c01e Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/3a86c01e Branch: refs/heads/trunk Commit: 3a86c01e69ecb66b31fe48c709c06097c8102517 Parents: 3beba3a Author: Tomaz Muraus <[email protected]> Authored: Thu Jan 9 00:10:55 2014 +0100 Committer: Tomaz Muraus <[email protected]> Committed: Thu Jan 9 00:12:27 2014 +0100 ---------------------------------------------------------------------- libcloud/compute/ssh.py | 26 +++++++++++++++----------- libcloud/test/compute/test_ssh_client.py | 16 ++++++++-------- 2 files changed, 23 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/3a86c01e/libcloud/compute/ssh.py ---------------------------------------------------------------------- diff --git a/libcloud/compute/ssh.py b/libcloud/compute/ssh.py index 852b2f8..5cc877c 100644 --- a/libcloud/compute/ssh.py +++ b/libcloud/compute/ssh.py @@ -167,15 +167,15 @@ class ParamikoSSHClient(BaseSSHClient): def __init__(self, hostname, port=22, username='root', password=None, key=None, timeout=None): """ - Note #1: Authentication is always attempted in the following order: - - - The key passed in (if provided) - - Any key we can find through an SSH agent - - Any "id_rsa" or "id_dsa" key discoverable in ~/.ssh/ - - Plain username/password auth, if a password was given (if provided) - - Note #2: If a password protected key is used, `password` argument - represents a password which will be used to unlock the key file. + Authentication is always attempted in the following order: + + - The key passed in (if key is provided) + - Any key we can find through an SSH agent (only if no password and + key is provided) + - Any "id_rsa" or "id_dsa" key discoverable in ~/.ssh/ (only if no + password and key is provided) + - Plain username/password auth, if a password was given (if password is + provided) """ super(ParamikoSSHClient, self).__init__(hostname, port, username, password, key, timeout) @@ -187,8 +187,8 @@ class ParamikoSSHClient(BaseSSHClient): conninfo = {'hostname': self.hostname, 'port': self.port, 'username': self.username, - 'allow_agent': True, - 'look_for_keys': True} + 'allow_agent': False, + 'look_for_keys': False} if self.password: conninfo['password'] = self.password @@ -196,6 +196,10 @@ class ParamikoSSHClient(BaseSSHClient): if self.key: conninfo['key_filename'] = self.key + if not self.password and not self.key: + conninfo['allow_agent'] = True + conninfo['look_for_keys'] = True + if self.timeout: conninfo['timeout'] = self.timeout http://git-wip-us.apache.org/repos/asf/libcloud/blob/3a86c01e/libcloud/test/compute/test_ssh_client.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_ssh_client.py b/libcloud/test/compute/test_ssh_client.py index eb674f1..d996119 100644 --- a/libcloud/test/compute/test_ssh_client.py +++ b/libcloud/test/compute/test_ssh_client.py @@ -60,9 +60,9 @@ class ParamikoSSHClientTests(unittest.TestCase): expected_conn = {'username': 'ubuntu', 'password': 'ubuntu', - 'allow_agent': True, + 'allow_agent': False, 'hostname': 'dummy.host.org', - 'look_for_keys': True, + 'look_for_keys': False, 'port': 22} mock.client.connect.assert_called_once_with(**expected_conn) self.assertLogMsg('Connecting to server') @@ -76,9 +76,9 @@ class ParamikoSSHClientTests(unittest.TestCase): mock.connect() expected_conn = {'username': 'ubuntu', - 'allow_agent': True, + 'allow_agent': False, 'hostname': 'dummy.host.org', - 'look_for_keys': True, + 'look_for_keys': False, 'key_filename': 'id_rsa', 'port': 22} mock.client.connect.assert_called_once_with(**expected_conn) @@ -95,9 +95,9 @@ class ParamikoSSHClientTests(unittest.TestCase): expected_conn = {'username': 'ubuntu', 'password': 'ubuntu', - 'allow_agent': True, + 'allow_agent': False, 'hostname': 'dummy.host.org', - 'look_for_keys': True, + 'look_for_keys': False, 'key_filename': 'id_rsa', 'port': 22} mock.client.connect.assert_called_once_with(**expected_conn) @@ -136,9 +136,9 @@ class ParamikoSSHClientTests(unittest.TestCase): mock_cli = mock.client # The actual mocked object: SSHClient expected_conn = {'username': 'ubuntu', 'key_filename': '~/.ssh/ubuntu_ssh', - 'allow_agent': True, + 'allow_agent': False, 'hostname': 'dummy.host.org', - 'look_for_keys': True, + 'look_for_keys': False, 'timeout': '600', 'port': 8822} mock_cli.connect.assert_called_once_with(**expected_conn)
