The sshutil.cache Module

class sshutil.cache.SSHConnectionCache(desc=u'', close_timeout=1, max_channels=8)

Bases: sshutil.cache._SSHConnectionCache

An ssh connection cache.

Authenticated connections to a given host are cached for a specified amount of time before being closed. This allows for connection reuse as well as avoiding re-authentication.

Parameters:
  • close_timeout – Amount of time to wait before closing an opened unused ssh socket.
  • max_channels – Maximum number of channels to open on a given ssh socket.
flush(debug=False)

Flush (close) any un-referenced open entries currently waiting for timeout.

get_ssh_socket(host, port, username, password, debug, proxycmd=None)

Returns a socket to the given host using the given credentials.

If a socket has already been opened with the supplied arguments, then it will be reference counted and returned. Otherwise a new socket will be opened. If usernamee is None getpass will be used to obtain the current user name.

Parameters:
  • host – The hostname to connect to.
  • port – The TCP port number to connect to.
  • username – The username to use for authentication or None. If None then getpass.get_user() will be used.
  • password – The password/key for authentication or None.
  • debug – Boolean indicating if debug messages should be enabled.
  • proxycmd – A proxy command to use when making the ssh connection.
Raises:

ssh.AuthenticationException

release_ssh_socket(ssh_socket, debug)

Release a refrence on an open socket.

release_ssh_socket must be paired with each call to get_ssh_socket.

class sshutil.cache.SSHNoConnectionCache(desc=u'')

Bases: sshutil.cache._SSHConnectionCache

Simple non-caching cache class

flush(debug=False)
get_ssh_socket(host, port, username, password, debug, proxycmd=None)
release_ssh_socket(ssh_socket, debug=False)