Skip to content

Commit 7ebfda9

Browse files
committed
Minor cleanup, separate username and password from host list argument to ParallelSSHClient as it makes usage complicated.
1 parent 58ac301 commit 7ebfda9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pssh.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(self, host,
7474
def _connect(self):
7575
"""Connect to host, throw UnknownHost exception on DNS errors"""
7676
try:
77-
if self.password is not None:
77+
if self.password:
7878
self.client.connect(self.host, username=self.user, password=self.password)
7979
else:
8080
self.client.connect(self.host, username=self.user)
@@ -103,6 +103,7 @@ class ParallelSSHClient(object):
103103
"""Uses SSHClient, runs command on multiple hosts in parallel"""
104104

105105
def __init__(self, hosts,
106+
user = None, password = None,
106107
pool_size=10):
107108

108109
"""Connect to hosts
@@ -112,15 +113,17 @@ def __init__(self, hosts,
112113
:param pool_size: Pool size - how many commands to run in parallel
113114
:type str:
114115
:param user: (Optional) User to login as. Defaults to logged in user or user from ~/.ssh/config if set
116+
:type str:
117+
:param password: (Optional) Password to use for login
115118
:throws: paramiko.AuthenticationException on authentication error
116119
:throws: ssh_client.UnknownHostException on DNS resolution error
117120
:throws: ssh_client.ConnectionErrorException on error connecting"""
118121
self.pool = gevent.pool.Pool(size = pool_size)
119122
self.pool_size = pool_size
120123
self.hosts = hosts
121-
124+
122125
# Initialise connections to all hosts
123-
self.host_clients = dict((host[0], SSHClient(host[0], user=host[1], password=host[2])) for host in hosts)
126+
self.host_clients = dict((host, SSHClient(host, user = user, password = password)) for host in hosts)
124127

125128
def exec_command(self, *args, **kwargs):
126129
"""Run command on all hosts in parallel, honoring self.pool_size"""

0 commit comments

Comments
 (0)