ape.parts.connections.sshconnection.SSHConnection

class ape.parts.connections.sshconnection.SSHConnection(hostname, username, prefix=None, password=None, port=22, compress=False, key_filename=None, timeout=None)

SSHConnection constructor

Param:
  • hostname: the IP address or resolvable host-name
  • username: the login username
  • password: the password for the device (optional if public-keys set)
  • prefix: string to add as a prefix to the commands
  • port: the port for the service
  • compress: if True, gzip the connection
  • key_filename: file-name or list of file-names for public-keys
  • timeout: seconds to wait for login before raising a socket.timeout
__init__(hostname, username, prefix=None, password=None, port=22, compress=False, key_filename=None, timeout=None)

SSHConnection constructor

Param:
  • hostname: the IP address or resolvable host-name
  • username: the login username
  • password: the password for the device (optional if public-keys set)
  • prefix: string to add as a prefix to the commands
  • port: the port for the service
  • compress: if True, gzip the connection
  • key_filename: file-name or list of file-names for public-keys
  • timeout: seconds to wait for login before raising a socket.timeout

Methods

__init__(hostname, username[, prefix, ...]) SSHConnection constructor
log_error(error[, message]) Logs the error in bold red
sudo(command, password[, timeout]) A convenience method to hide what’s needed to run as root

Attributes

client an SSHClient instance
logger
return:A logging object.
close()

Closes the connection and sets SSHClient to None

exec_command(command, bufsize=-1, timeout=None, get_pty=False)

a secondary interface to allow more arbitrary input

Param:
  • command: string with command to send over the ssh-connection
  • bufsize: bytes to set for the buffer
  • timeout: seconds for channel timeout
  • get_pty: needed for interactive things (like sending the sudo password)
log_error(error, message='')

Logs the error in bold red

Param:
  • error: error type (prefix in red and bold)
  • message: descriptive message (red but not bold)
sudo(command, password, timeout=None)

A convenience method to hide what’s needed to run as root

Param:
  • command: command to run (without the ‘sudo’ keyword)
  • password: the sudoer’s password
  • timeout: Amount of time to wait for the connection to respond
Returns:

InOutError named tuple

client

an SSHClient instance

Raise:ApeError for paramiko and socket exceptions
Return type:SSHClient
Returns:SSH Client with the constructor’s parameters
lock

A re-entrant lock that threaded users of the connection can use

logger
Returns:A logging object.

Navigation