Package starcluster :: Module ssh :: Class SSHClient
[hide private]
[frames] | no frames]

Class SSHClient

source code


Establishes an SSH connection to a remote host using either password or private key authentication. Once established, this object allows executing commands, copying files to/from the remote host, various file querying similar to os.path.*, and much more.

Instance Methods [hide private]
 
__init__(self, host, username=None, password=None, private_key=None, private_key_pass=None, port=22, timeout=30)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
load_private_key(self, private_key, private_key_pass=None) source code
 
connect(self, host=None, username=None, password=None, private_key=None, private_key_pass=None, port=22, timeout=30) source code
 
get_server_public_key(self) source code
 
is_active(self) source code
 
_get_socket(self, hostname, port) source code
 
_load_rsa_key(self, private_key, private_key_pass=None) source code
 
_load_dsa_key(self, private_key, private_key_pass=None) source code
 
generate_rsa_key(self) source code
 
get_public_key(self, key) source code
 
load_remote_rsa_key(self, remote_filename)
Returns paramiko.RSAKey object for an RSA key located on the remote machine
source code
 
makedirs(self, path, mode=493)
Same as os.makedirs - makes a new directory and automatically creates all parent directories if they do not exist.
source code
 
mkdir(self, path, mode=493, ignore_failure=False)
Make a new directory on the remote machine
source code
 
get_remote_file_lines(self, remote_file, regex=None, matching=True)
Returns list of lines in a remote_file
source code
 
remove_lines_from_file(self, remote_file, regex)
Removes lines matching regex from remote_file
source code
 
unlink(self, remote_file) source code
 
remote_file(self, file, mode='w')
Returns a remote file descriptor
source code
 
path_exists(self, path)
Test whether a remote path exists.
source code
 
lpath_exists(self, path)
Test whether a remote path exists.
source code
 
chown(self, uid, gid, remote_file)
Apply permissions (mode) to remote_file
source code
 
chmod(self, mode, remote_file)
Apply permissions (mode) to remote_file
source code
 
ls(self, path)
Return a list containing the names of the entries in the remote path.
source code
 
glob(self, pattern) source code
 
isdir(self, path)
Return true if the remote path refers to an existing directory.
source code
 
isfile(self, path)
Return true if the remote path refers to an existing file.
source code
 
stat(self, path)
Perform a stat system call on the given remote path.
source code
 
lstat(self, path)
Same as stat but doesn't follow symlinks
source code
 
_file_transfer_progress(self, filename, size, sent) source code
 
_make_list(self, obj) source code
 
get(self, remotepaths, localpath='')
Copies one or more files from the remote host to the local host.
source code
 
put(self, localpaths, remotepath='.')
Copies one or more files from the local host to the remote host.
source code
 
execute_async(self, command, source_profile=False)
Executes a remote command so that it continues running even after this SSH connection closes.
source code
 
get_status(self, command, source_profile=False)
Execute a remote command and return the exit status
source code
 
_get_output(self, channel, silent=True, only_printable=False)
Returns the stdout/stderr output from a paramiko channel as a list of strings (non-interactive only)
source code
 
execute(self, command, silent=True, only_printable=False, ignore_exit_status=False, log_output=True, detach=False, source_profile=False)
Execute a remote command and return stdout/stderr
source code
 
has_required(self, progs)
Same as check_required but returns False if not all commands exist
source code
 
check_required(self, progs)
Checks that all commands in the progs list exist on the remote system.
source code
 
which(self, prog) source code
 
get_path(self)
Returns the PATH environment variable on the remote machine
source code
 
get_env(self)
Returns the remote machine's environment as a dictionary
source code
 
close(self)
Closes the connection and cleans up.
source code
 
_invoke_shell(self, term='screen', cols=80, lines=24) source code
 
interactive_shell(self, user='root') source code
 
_posix_shell(self, chan) source code
 
_windows_shell(self, chan) source code
 
__del__(self)
Attempt to clean up if not explicitly closed.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]
  transport
This property attempts to return an active SSH transport
  sftp
Establish the SFTP connection.
  scp
Initialize the SCP client.
  progress_bar

Inherited from object: __class__

Method Details [hide private]

__init__(self, host, username=None, password=None, private_key=None, private_key_pass=None, port=22, timeout=30)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

makedirs(self, path, mode=493)

source code 

Same as os.makedirs - makes a new directory and automatically creates all parent directories if they do not exist.

mode specifies unix permissions to apply to the new dir

mkdir(self, path, mode=493, ignore_failure=False)

source code 

Make a new directory on the remote machine

If parent is True, create all parent directories that do not exist

mode specifies unix permissions to apply to the new dir

get_remote_file_lines(self, remote_file, regex=None, matching=True)

source code 

Returns list of lines in a remote_file

If regex is passed only lines that contain a pattern that matches regex will be returned

If matching is set to False then only lines *not* containing a pattern that matches regex will be returned

path_exists(self, path)

source code 

Test whether a remote path exists. Returns False for broken symbolic links

lpath_exists(self, path)

source code 

Test whether a remote path exists. Returns True for broken symbolic links

execute_async(self, command, source_profile=False)

source code 

Executes a remote command so that it continues running even after this SSH connection closes. The remote process will be put into the background via nohup. Does not return output or check for non-zero exit status.

execute(self, command, silent=True, only_printable=False, ignore_exit_status=False, log_output=True, detach=False, source_profile=False)

source code 

Execute a remote command and return stdout/stderr

NOTE: this function blocks until the process finishes

kwargs:
silent - do not log output to console
only_printable - filter the command's output to allow only printable
                characters
ignore_exit_status - don't warn about non-zero exit status
log_output - log output to debug file
detach - detach the remote process so that it continues to run even
         after the SSH connection closes (does NOT return output or
         check for non-zero exit status if detach=True)
source_profile - if True prefix the command with "source /etc/profile"
returns List of output lines

check_required(self, progs)

source code 

Checks that all commands in the progs list exist on the remote system. Returns True if all commands exist and raises exception.CommandNotFound if not.


Property Details [hide private]

transport

This property attempts to return an active SSH transport

Get Method:
unreachable.transport(self) - This property attempts to return an active SSH transport

sftp

Establish the SFTP connection.

Get Method:
unreachable.sftp(self) - Establish the SFTP connection.

scp

Initialize the SCP client.

Get Method:
unreachable.scp(self) - Initialize the SCP client.

progress_bar

Get Method:
unreachable.progress_bar(self)