-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the
SshAutoTransport
transport plugin
This is an alternative to the `SshFabricTransport` that does not depend on the `fabric` library but instead simply modifies the `SshTransport` plugin to not require specifying any connection arguments, but that are instead automatically parsed from the SSH config. The `fabric` plugin anyway uses `paramiko` under the hood to perform the actual connections, just as the `SshTransport` plugin, and the logic to automatically determine connection parameters is not that complicated for default input arguments to the `fabric.Connection` class. It does do some clever stuff with proxy commands and jumps, but that is also already implemented by `SshTransport`. So there is little reason to add another dependency.
- Loading branch information
Showing
5 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
"""Plugin for transport over SSH (and SFTP for file transfer).""" | ||
|
||
import pathlib | ||
|
||
import paramiko | ||
|
||
from .ssh import SshTransport | ||
|
||
__all__ = ('SshAutoTransport',) | ||
|
||
|
||
class SshAutoTransport(SshTransport): | ||
"""Support connection, command execution and data transfer to remote computers via SSH+SFTP.""" | ||
|
||
_valid_connect_params = [] | ||
_valid_auth_options = [] | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs, key_policy='AutoAddPolicy') | ||
|
||
config_ssh = paramiko.SSHConfig() | ||
|
||
with (pathlib.Path('~').expanduser() / '.ssh' / 'config').open() as handle: | ||
config_ssh.parse(handle) | ||
|
||
if self._machine not in config_ssh.get_hostnames(): | ||
self.logger.warning( | ||
f'The host `{self._machine}` is not defined in SSH config, connection will most likely fail to open.' | ||
) | ||
|
||
config_host = config_ssh.lookup(self._machine) | ||
|
||
self._connect_args = { | ||
'port': config_host.get('port', 22), | ||
'username': config_host.get('user'), | ||
'key_filename': config_host.get('identityfile', []), | ||
'timeout': config_host.get('connecttimeout', 60), | ||
'proxy_command': config_host.get('proxycommand', None), | ||
'proxy_jump': config_host.get('proxyjump', None), | ||
} | ||
|
||
self._machine = config_host['hostname'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters