Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
pkittenis committed Aug 20, 2022
commit 5e2cb781bdaa2beaf6180fd6b17c6a0490be0536
24 changes: 19 additions & 5 deletions pssh/clients/base/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,26 @@ def hosts(self, _hosts):
self._host_clients.pop((i, host), None)
self._hosts = _hosts

def __del__(self):
self.disconnect()

def disconnect(self):
if not hasattr(self, '_host_clients'):
return
for s_client in self._host_clients.values():
try:
s_client.disconnect()
except Exception as ex:
logger.debug("Client disconnect failed with %s", ex)
pass
del s_client

def _check_host_config(self):
if self.host_config is None:
return
if not isinstance(self.host_config, list):
raise HostConfigError("Host configuration of type %s is invalid - valid types are List[HostConfig]",
type(self.host_config))
host_len = len(self.hosts)
if host_len != len(self.host_config):
raise ValueError(
Expand Down Expand Up @@ -257,7 +274,7 @@ def get_last_output(self, cmds=None):
return self._get_output_from_cmds(
cmds, raise_error=False)

def _get_host_config(self, host_i, host):
def _get_host_config(self, host_i):
if self.host_config is None:
config = HostConfig(
user=self.user, port=self.port, password=self.password, private_key=self.pkey,
Expand All @@ -276,9 +293,6 @@ def _get_host_config(self, host_i, host):
alias=None,
)
return config
elif not isinstance(self.host_config, list):
raise HostConfigError("Host configuration of type %s is invalid - valid types are list[HostConfig]",
type(self.host_config))
config = self.host_config[host_i]
return config

Expand Down Expand Up @@ -557,7 +571,7 @@ def _get_ssh_client(self, host_i, host):
_client = self._host_clients.get((host_i, host))
if _client is not None:
return _client
cfg = self._get_host_config(host_i, host)
cfg = self._get_host_config(host_i)
_pkey = self.pkey if cfg.private_key is None else cfg.private_key
_pkey_data = self._load_pkey_data(_pkey)
_client = self._make_ssh_client(host, cfg, _pkey_data)
Expand Down