diff --git a/lago/plugins/vm.py b/lago/plugins/vm.py index f2b32b97..686ca458 100644 --- a/lago/plugins/vm.py +++ b/lago/plugins/vm.py @@ -532,7 +532,7 @@ def ssh_reachable(self, tries=None, propagate_fail=True): return False try: - ssh.get_ssh_client( + self._ssh_client = ssh.get_ssh_client( ip_addr=self.ip(), host_name=self.name(), ssh_tries=tries, @@ -660,19 +660,23 @@ def _normalize_spec(cls, spec): @contextlib.contextmanager def _scp(self, propagate_fail=True): - client = ssh.get_ssh_client( - propagate_fail=propagate_fail, - ip_addr=self.ip(), - host_name=self.name(), - ssh_key=self.virt_env.prefix.paths.ssh_id_rsa(), - username=self._spec.get('ssh-user'), - password=self._spec.get('ssh-password'), - ) + if self._ssh_client is not None: + client = self._ssh_client + else: + client = ssh.get_ssh_client( + propagate_fail=propagate_fail, + ip_addr=self.ip(), + host_name=self.name(), + ssh_key=self.virt_env.prefix.paths.ssh_id_rsa(), + username=self._spec.get('ssh-user'), + password=self._spec.get('ssh-password'), + ) scp = SCPClient(client.get_transport()) try: yield scp finally: client.close() + self._ssh_client = None def _detect_service_provider(self): LOGGER.debug('Detecting service provider for %s', self.name())