- logger.debug('Connect peer: {0}'.
- format(self._ssh.get_transport().getpeername()))
- logger.debug('Connections: {0}'.format(str(SSH.__existing_connections)))
+ logger.debug('Connect peer: {0}'.
+ format(self._ssh.get_transport().getpeername()))
+ logger.debug('Connections: {0}'.
+ format(str(SSH.__existing_connections)))
+ except:
+ if attempts > 0:
+ self._reconnect(attempts-1)
+ else:
+ raise
+
+ def disconnect(self, node):
+ """Close SSH connection to the node.
+
+ :param node: The node to disconnect from.
+ :type node: dict
+ """
+ node_hash = self._node_hash(node)
+ if node_hash in SSH.__existing_connections:
+ logger.debug('Disconnecting peer: {}, {}'.
+ format(node['host'], node['port']))
+ ssh = SSH.__existing_connections.pop(node_hash)
+ ssh.close()
+
+ def _reconnect(self, attempts=0):
+ """Close the SSH connection and open it again."""
+
+ node = self._node
+ self.disconnect(node)
+ self.connect(node, attempts)
+ logger.debug('Reconnecting peer done: {}'.
+ format(self._ssh.get_transport().getpeername()))