BaseParallelSSHClient

API documentation for common parallel client functionality.

Abstract parallel SSH client package

class pssh.clients.base_pssh.BaseParallelSSHClient(hosts, user=None, password=None, port=None, pkey=None, allow_agent=True, num_retries=3, timeout=120, pool_size=10, host_config=None, retry_delay=5)

Parallel client base class.

copy_file(local_file, remote_file, recurse=False, copy_args=None)

Copy local file to remote file in parallel

This function returns a list of greenlets which can be join-ed on to wait for completion.

gevent.joinall() function may be used to join on all greenlets and will also raise exceptions from them if called with raise_error=True - default is False.

Alternatively call .get on each greenlet to raise any exceptions from it.

Exceptions listed here are raised when either gevent.joinall(<greenlets>, raise_error=True) is called or .get is called on each greenlet, not this function itself.

Parameters:
  • local_file (str) – Local filepath to copy to remote host
  • remote_file (str) – Remote filepath on remote host to copy file to
  • recurse (bool) – Whether or not to descend into directories recursively.
  • copy_args (tuple or list) – (Optional) format local_file and remote_file strings with per-host arguments in copy_args. copy_args length must equal length of host list - pssh.exceptions.HostArgumentException is raised otherwise
Return type:

List(gevent.Greenlet) of greenlets for remote copy commands

Raises:

ValueError when a directory is supplied to local_file and recurse is not set

Raises:

pssh.exceptions.HostArgumentException on number of per-host copy arguments not equal to number of hosts

Raises:

IOError on I/O errors writing files

Raises:

OSError on OS errors like permission denied

Note

Remote directories in remote_file that do not exist will be created as long as permissions allow.

copy_remote_file(remote_file, local_file, recurse=False, suffix_separator='_', copy_args=None, **kwargs)

Copy remote file(s) in parallel as <local_file><suffix_separator><host>

With a local_file value of myfile and default separator _ the resulting filename will be myfile_myhost for the file from host myhost.

This function, like ParallelSSHClient.copy_file(), returns a list of greenlets which can be join-ed on to wait for completion.

gevent.joinall() function may be used to join on all greenlets and will also raise exceptions if called with raise_error=True - default is False.

Alternatively call .get on each greenlet to raise any exceptions from it.

Exceptions listed here are raised when either gevent.joinall(<greenlets>, raise_error=True) is called or .get is called on each greenlet, not this function itself.

Parameters:
  • remote_file (str) – remote filepath to copy to local host
  • local_file (str) – local filepath on local host to copy file to
  • recurse (bool) – whether or not to recurse
  • suffix_separator (str) – (Optional) Separator string between filename and host, defaults to _. For example, for a local_file value of myfile and default separator the resulting filename will be myfile_myhost for the file from host myhost. suffix_separator has no meaning if copy_args is provided
  • copy_args (tuple or list) – (Optional) Format remote_file and local_file strings with per-host arguments in copy_args. copy_args length must equal length of host list - pssh.exceptions.HostArgumentException is raised otherwise
Return type:

list(gevent.Greenlet) of greenlets for remote copy commands

Raises:

ValueError when a directory is supplied to local_file and recurse is not set

Raises:

pssh.exceptions.HostArgumentException on number of per-host copy arguments not equal to number of hosts

Raises:

IOError on I/O errors writing files

Raises:

OSError on OS errors like permission denied

Note

Local directories in local_file that do not exist will be created as long as permissions allow.

Note

File names will be de-duplicated by appending the hostname to the filepath separated by suffix_separator.

finished(output)

Check if commands have finished without blocking

Parameters:output – As returned by pssh.pssh_client.ParallelSSHClient.get_output()
Return type:bool
get_exit_code(host_output)

Get exit code from host output if available.

Parameters:host_output – Per host output as returned by pssh.pssh_client.ParallelSSHClient.get_output()
Return type:int or None if exit code not ready
get_exit_codes(output)

Get exit code for all hosts in output if available. Output parameter is modified in-place.

Parameters:output – As returned by pssh.pssh_client.ParallelSSHClient.get_output()
Return type:None
get_last_output(cmds=None)

Get output for last commands executed by run_command

Parameters:cmds (list(gevent.Greenlet)) – Commands to get output for. Defaults to client.cmds
Return type:dict
get_output(cmd, output, timeout=None)

Get output from command.

Parameters:
Return type:

None