Base Single Client
API documentation for common single host client functionality.
This class is abstract and contains functions that need to be implemented for each underlying SSH library.
- class pssh.clients.base.single.BaseSSHClient(host, user=None, password=None, port=None, pkey=None, alias=None, num_retries=3, retry_delay=5, allow_agent=True, timeout=None, proxy_host=None, proxy_port=None, _auth_thread_pool=True, identity_auth=True, ipv6_only=False, compress=False, keyboard_interactive=False)
- auth()
- close_channel(channel)
- copy_file(local_file, remote_file, recurse=False, sftp=None)
- copy_remote_file(remote_file, local_file, recurse=False, sftp=None, encoding='utf-8')
- disconnect()
Deprecated and a no-op. Disconnections handled by client de-allocation.
- execute(cmd, use_pty=False, channel=None)
Deprecated - use
run_commandinstead which returns aHostOutputobject.
- get_exit_status(channel)
- mkdir(sftp, directory)
- open_session()
- open_shell(encoding='utf-8', read_timeout=None)
Open interactive shell on new channel.
Can be used as context manager -
with open_shell() as shell.
- read_output(stdout_buffer, timeout=None)
Read standard output buffer. Returns a generator of line by line output.
- Parameters:
stdout_buffer (
pssh.clients.reader.ConcurrentRWBuffer) – Buffer to read from.timeout (int or float) – Timeout in seconds - defaults to no timeout.
- Return type:
generator
- read_output_buffer(output_buffer, prefix=None, callback=None, callback_args=None, encoding='utf-8')
Read from output buffers and log to
host_logger.
- read_stderr(stderr_buffer, timeout=None)
Read standard error buffer. Returns a generator of line by line output.
- Parameters:
stderr_buffer (
pssh.clients.reader.ConcurrentRWBuffer) – Buffer to read from.timeout (int or float) – Timeout in seconds - defaults to no timeout.
- Return type:
generator
- run_command(command, sudo=False, user=None, use_pty=False, shell=None, encoding='utf-8', timeout=None, read_timeout=None)
Run remote command.
- Parameters:
command (str) – Command to run.
sudo (bool) – Run command via sudo as super-user.
user (str) – Run command as user via sudo
use_pty (bool) – Whether or not to obtain a PTY on the channel.
shell (str) – (Optional) Override shell to use to run command with. Defaults to login user’s defined shell. Use the shell’s command syntax, eg shell=’bash -c’ or shell=’zsh -c’.
encoding (str) – Encoding to use for output. Must be valid Python codec
read_timeout (float) – (Optional) Timeout in seconds for reading output.
timeout – Deprecated - use read_timeout.
- Return type:
- scp_recv(remote_file, local_file, recurse=False, sftp=None, encoding='utf-8')
- scp_send(local_file, remote_file, recurse=False, sftp=None)
- sftp_get(sftp, remote_file, local_file)
- sftp_put(sftp, local_file, remote_file)
- wait_finished(host_output, timeout=None)
- IDENTITIES = ('/home/docs/.ssh/id_rsa', '/home/docs/.ssh/id_dsa', '/home/docs/.ssh/identity', '/home/docs/.ssh/id_ecdsa', '/home/docs/.ssh/id_ed25519')
- sock
- class pssh.clients.base.single.InteractiveShell(channel, client, encoding='utf-8', read_timeout=None)
Run commands on an interactive shell.
Use as context manager to wait for commands to finish on exit.
Read from .stdout and stderr once context manager has exited.
InteractiveShell.outputis apssh.output.HostOutputobject.- Parameters:
channel (
ssh2.channel.Channelor similar.) – The channel to open shell on.client (
BaseSSHClient) – The SSHClient that opened the channel.encoding (str) – Encoding to use for command string when calling
runand shell output.
- close()
Wait for shell to finish executing and close channel.
- run(cmd)
Run command on interactive shell.
- Parameters:
cmd (str) – The command string to run. Note that
\nis appended to every string.
- property exit_code
self.output.exit_code
- output
- property stderr
self.output.stderr
- property stdin
self.output.stdin
- property stdout
self.output.stdout
- class pssh.clients.base.single.PollMixIn(sock=None)
MixIn for co-operative socket polling functionality.
- eagain(func, *args, **kwargs)
- eagain_write(write_func, data)
- poll(timeout=None)
- sock
- class pssh.clients.base.single.Stdin(channel, client)
Stdin stream for a channel.
Handles EAGAIN.
Provides
writeandflushonly.- Parameters:
channel (IO object) – The channel the stdin stream is from.
client (
BaseSSHClient) – The SSH client the channel is from.
- flush()
Flush pending data written to stdin.