Module for classes and utilities to define transports to other machines.
aiida.transports.
Transport
Bases: abc.ABC
abc.ABC
Abstract class for a generic transport (ssh, local, …) ontains the set of minimal methods.
_DEFAULT_SAFE_OPEN_INTERVAL
_MAGIC_CHECK
__abstractmethods__
__dict__
__enter__
For transports that require opening a connection, opens all required channels (used in ‘with’ statements).
This object can be used in nested with statements and the connection will only be opened once and closed when the final with scope finishes e.g.:
t = Transport() with t: # Connection is now open.. with t: # ..still open.. pass # ..still open.. # ...closed
__exit__
Closes connections, if needed (used in ‘with’ statements).
__init__
__init__ method of the Transport base class.
safe_interval – (optional, default self._DEFAULT_SAFE_OPEN_INTERVAL) Minimum time interval in seconds between opening new connections.
use_login_shell – (optional, default True) if False, do not use a login shell when executing command
__module__
__repr__
Return repr(self).
__str__
Return str(self).
__weakref__
list of weak references to the object (if defined)
_abc_impl
_common_auth_options
_exec_command_internal
Execute the command on the shell, similarly to os.system.
Enforce the execution to be run from the cwd (as given by self.getcwd), if this is not None.
If possible, use the higher-level exec_command_wait function.
command (str) – execute the command given as a string
stdin, stdout, stderr and the session, when this exists (can be None).
_get_safe_interval_suggestion_string
Return as a suggestion the default safe interval of this Transport class.
This is used to provide a default in verdi computer configure.
verdi computer configure
_get_use_login_shell_suggestion_string
Return a suggestion for the specific field.
_gotocomputer_string
command executed when goto computer.
_valid_auth_options
_valid_auth_params
auth_options
chdir
Change directory to ‘path’
path (str) – path to change working directory into.
IOError, if the requested path does not exist
str
chmod
Change permissions of a path.
path (str) – path to file
mode (int) – new permissions
chown
Change the owner (uid) and group (gid) of a file. As with python’s os.chown function, you must pass both arguments, so if you only want to change one, use stat first to retrieve the current owner and group.
path (str) – path to the file to change the owner and group of
uid (int) – new owner’s uid
gid (int) – new group id
close
Closes the local transport channel
copy
Copy a file or a directory from remote source to remote destination (On the same remote machine)
remotesource (str) – path of the remote source directory / file
remotedestination (str) – path of the remote destination directory / file
dereference (bool) – if True copy the contents of any symlinks found, otherwise copy the symlinks themselves
recursive (bool) – if True copy directories recursively, otherwise only copy the specified file(s)
IOError, if one of src or dst does not exist
copy_from_remote_to_remote
Copy files or folders from a remote computer to another remote computer.
transportdestination – transport to be used for the destination computer
remotesource (str) – path to the remote source directory / file
remotedestination (str) – path to the remote destination directory / file
kwargs – keyword parameters passed to the call to transportdestination.put, except for ‘dereference’ that is passed to self.get
Note
the keyword ‘dereference’ SHOULD be set to False for the final put (onto the destination), while it can be set to the value given in kwargs for the get from the source. In that way, a symbolic link would never be followed in the final copy to the remote destination. That way we could avoid getting unknown (potentially malicious) files into the destination computer. HOWEVER, since dereference=False is currently NOT supported by all plugins, we still force it to True for the final put.
the supported keys in kwargs are callback, dereference, overwrite and ignore_nonexisting.
copyfile
Copy a file from remote source to remote destination (On the same remote machine)
IOError – if one of src or dst does not exist
copytree
Copy a folder from remote source to remote destination (On the same remote machine)
exec_command_wait
Execute the command on the shell, waits for it to finish, and return the retcode, the stdout and the stderr.
Enforce the execution to be run from the pwd (as given by self.getcwd), if this is not None.
a list: the retcode (int), stdout (str) and stderr (str).
get
Retrieve a file or folder from remote source to local destination dst must be an absolute path (src not necessarily)
remotepath – (str) remote_folder_path
localpath – (str) local_folder_path
get_attribute
Return an object FixedFieldsAttributeDict for file in a given path, as defined in aiida.common.extendeddicts Each attribute object consists in a dictionary with the following keys:
st_size: size of files, in bytes
st_uid: user id of owner
st_gid: group id of owner
st_mode: protection bits
st_atime: time of most recent access
st_mtime: time of most recent modification
object FixedFieldsAttributeDict
get_mode
Return the portion of the file’s mode that can be set by chmod().
the portion of the file’s mode that can be set by chmod()
get_safe_open_interval
Get an interval (in seconds) that suggests how long the user should wait between consecutive calls to open the transport. This can be used as a way to get the user to not swamp a limited number of connections, etc. However it is just advisory.
If returns 0, it is taken that there are no reasons to limit the frequency of open calls.
In the main class, it returns a default value (>0 for safety), set in the _DEFAULT_SAFE_OPEN_INTERVAL attribute of the class. Plugins should override it.
The safe interval between calling open, in seconds
float
get_short_doc
Return the first non-empty line of the class docstring, if available
get_valid_auth_params
Return the internal list of valid auth_params
get_valid_transports
Return the list of registered transport entry points.
Deprecated since version 1.4.0: Will be removed in 2.0.0, use aiida.plugins.entry_point.get_entry_point_names instead
getcwd
Get working directory
a string identifying the current working directory
getfile
Retrieve a file from remote source to local destination dst must be an absolute path (src not necessarily)
remotepath (str) – remote_folder_path
localpath (str) – local_folder_path
gettree
Retrieve a folder recursively from remote source to local destination dst must be an absolute path (src not necessarily)
glob
Return a list of paths matching a pathname pattern.
The pattern may contain simple shell-style wildcards a la fnmatch.
glob0
Wrap basename i a list if it is empty or if dirname/basename is an existing path, else return empty list.
glob1
Match subpaths of dirname against pattern.
gotocomputer_command
Return a string to be run using os.system in order to connect via the transport to the remote directory.
Expected behaviors:
A new bash session is opened
A reasonable error message is produced if the folder does not exist
remotedir (str) – the full path of the remote directory
has_magic
iglob
Return an iterator which yields the paths matching a pathname pattern.
is_open
isdir
True if path is an existing directory.
path (str) – path to directory
boolean
isfile
Return True if path is an existing file.
listdir
Return a list of the names of the entries in the given path. The list is in arbitrary order. It does not include the special entries ‘.’ and ‘..’ even if they are present in the directory.
path (str) – path to list (default to ‘.’)
pattern (str) – if used, listdir returns a list of files matching filters in Unix style. Unix only.
a list of strings
listdir_withattributes
a list of dictionaries, one per entry. The schema of the dictionary is the following:
{ 'name': String, 'attributes': FileAttributeObject, 'isdir': Bool }
where ‘name’ is the file or folder directory, and any other information is metadata (if the file is a folder, a directory, …). ‘attributes’ behaves as the output of transport.get_attribute(); isdir is a boolean indicating if the object is a directory or not.
logger
Return the internal logger. If you have set extra parameters using set_logger_extra(), a suitable LoggerAdapter instance is created, bringing with itself also the extras.
makedirs
Super-mkdir; create a leaf directory and all intermediate ones. Works like mkdir, except that any intermediate path segment (not just the rightmost) will be created if it does not exist.
path (str) – directory to create
ignore_existing (bool) – if set to true, it doesn’t give any error if the leaf directory does already exist
OSError, if directory at path already exists
mkdir
Create a folder (directory) named path.
path (str) – name of the folder to create
ignore_existing (bool) – if True, does not give any error if the directory already exists
normalize
Return the normalized path (on the server) of a given path. This can be used to quickly resolve symbolic links or determine what the server is considering to be the “current folder”.
path (str) – path to be normalized
IOError – if the path can’t be resolved on the server
open
Opens a local transport channel
path_exists
Returns True if path exists, False otherwise.
put
Put a file or a directory from local src to remote dst. src must be an absolute path (dst not necessarily)) Redirects to putfile and puttree.
localpath (str) – absolute path to local source
remotepath (str) – path to remote destination
putfile
Put a file from local src to remote dst. src must be an absolute path (dst not necessarily))
localpath (str) – absolute path to local file
remotepath (str) – path to remote file
puttree
Put a folder recursively from local src to remote dst. src must be an absolute path (dst not necessarily))
localpath (str) – absolute path to local folder
remotepath (str) – path to remote folder
remove
Remove the file at the given path. This only works on files; for removing folders (directories), use rmdir.
path (str) – path to file to remove
IOError – if the path is a directory
rename
Rename a file or folder from oldpath to newpath.
oldpath (str) – existing name of the file or folder
newpath (str) – new name for the file or folder
IOError – if oldpath/newpath is not found
ValueError – if oldpath/newpath is not a valid string
rmdir
Remove the folder named path. This works only for empty folders. For recursive remove, use rmtree.
path (str) – absolute path to the folder to remove
rmtree
Remove recursively the content at path
path (str) – absolute path to remove
set_logger_extra
Pass the data that should be passed automatically to self.logger as ‘extra’ keyword. This is typically useful if you pass data obtained using get_dblogger_extra in aiida.backends.djsite.utils, to automatically log also to the DbLog table.
logger_extra – data that you want to pass as extra to the self.logger. To write to DbLog, it should be created by the aiida.backends.djsite.utils.get_dblogger_extra function. Pass None if you do not want to have extras passed.
symlink
Create a symbolic link between the remote source and the remote destination.
remotesource – remote source
remotedestination – remote destination
whoami
Get the remote username
list of username (str), retval (int), stderr (str)
Common cli utilities for transport plugins.
aiida.transports.cli.
common_params
Decorate a command function with common click parameters for all transport plugins.
configure_computer_main
Configure a computer via the CLI.
create_configure_cmd
Create verdi computer configure subcommand for a transport type.
create_option
Create a click option from a name and partial specs as used in transport auth_options.
interactive_default
Create a contextual_default value callback for an auth_param key.
key – the name of the option.
also_non_interactive – indicates whether this option should provide a default also in non-interactive mode. If False, the option will raise MissingParameter if no explicit value is specified when the command is called in non-interactive mode.
list_transport_options
match_comp_transport
Check the computer argument against the transport type.
transport_option_default
Determine the default value for an auth_param key.
transport_options
Decorate a command with all options for a computer configure subcommand for transport_type.
Transport interface.
aiida.transports.transport.
General utilities for Transport classes.
aiida.transports.util.
FileAttribute
Bases: aiida.common.extendeddicts.FixedFieldsAttributeDict
aiida.common.extendeddicts.FixedFieldsAttributeDict
A class, resembling a dictionary, to describe the attributes of a file, that is returned by get_attribute(). Possible keys: st_size, st_uid, st_gid, st_mode, st_atime, st_mtime
_valid_fields
_DetachedProxyCommand
Bases: paramiko.proxy.ProxyCommand
paramiko.proxy.ProxyCommand
Modifies paramiko’s ProxyCommand by launching the process in a separate process group.
Create a new CommandProxy instance. The instance created by this class can be passed as an argument to the .Transport class.
command_line (str) – the command that should be executed and used as the proxy.
transportsource – transport to be used for the source computer
kwargs – keyword parameters passed to the final put, except for ‘dereference’ that is passed to the initial get
it uses the method transportsource.copy_from_remote_to_remote