Host¶
This module contains the immediate wrappers around the remote hosts and their
terminals. It’s possible to run commands on a host directly by using these
classes. As an end-user of this library however, you will call the methods of
SSHHost and LocalHost
through HostsContainer, the
host proxy of a Node.
Base classes¶
-
class
deployer.host.base.Host(pty=None, logger=None)¶ Abstract base class for SSHHost and LocalHost.
Parameters: - pty (
deployer.pseudo_terminal.Pty) – The pseudo terminal wrapper which handles the stdin/stdout. - logger (LoggerInterface) – The logger interface.
class MyHost(SSHHost): ... my_host = MyHost() my_host.run('pwd', interactive=False)
-
copy(pty=None)¶ Create a deep copy of this Host class. (the pty-parameter allows to bind it to anothor pty)
-
exists(filename, use_sudo=True, **kw)¶ Returns
Truewhen a file namedfilenameexists on this hosts.
-
get_file(remote_path, local_path, use_sudo=False, sandbox=False)¶ Download this remote_file.
-
get_ip_address(interface='eth0')¶ Return internal IP address of this interface.
-
get_start_path()¶ The path in which commands at the server will be executed. by default. (if no cd-statements are used.) Usually, this is the home directory. It should always return an absolute path, starting with ‘/’
-
getcwd()¶ Return current working directory as absolute path.
-
open(remote_path, mode='rb', use_sudo=False, sandbox=False)¶ Open file handler to remote file. Can be used both as:
with host.open('/path/to/somefile', 'wb') as f: f.write('some content')
or:
host.open('/path/to/somefile', 'wb').write('some content')
-
password= ''¶ Password for connecting to the host. (for sudo)
-
put_file(local_path, remote_path, use_sudo=False, sandbox=False)¶ Upload this local_file to the remote location.
-
run(command, use_sudo=False, sandbox=False, interactive=True, user=None, ignore_exit_status=False, initial_input=None, silent=False)¶ Execute this shell command on the host.
Parameters: - command (basestring) – The shell command.
- use_sudo (bool) – Run as superuser.
- sandbox (bool) – Validate syntax instead of really executing. (Wrap the command in
bash -n.) - interactive (bool) – Start an interactive event loop which allows interaction with the remote command. Otherwise, just return the output.
- initial_input – When
interactive, send this input first to the host.
-
slug= ''¶ The slug should be a unique identifier for the host.
-
start_interactive_shell(command=None, initial_input=None)¶ Start an interactive bash shell.
-
sudo(command, use_sudo=False, sandbox=False, interactive=True, user=None, ignore_exit_status=False, initial_input=None, silent=False)¶ Wrapper around
run()which usessudo.
-
username= ''¶ Username for connecting to the Host
- pty (
-
class
deployer.host.base.HostContext¶ A push/pop stack which keeps track of the context on which commands at a host are executed.
(This is mainly used internally by the library.)
-
cd(path, expand=False)¶ Execute commands in this directory. Nesting of cd-statements is allowed.
with host.cd('directory'): host.run('ls')
Parameters: expand (bool) – Expand tildes.
-
copy()¶ Create a deep copy.
-
env(variable, value, escape=True)¶ Set this environment variable
with host.cd('VAR', 'my-value'): host.run('echo $VAR')
-
prefix(command)¶ Prefix all commands with given command plus
&&.with host.prefix('workon environment'): host.run('./manage.py migrate')
-
Localhost¶
SSH Host¶
-
class
deployer.host.ssh.SSHHost(*a, **kw)¶ SSH Host.
For the authentication, it’s required to provide either a
password, akey_filenameorrsa_key. e.g.class WebServer(SSHHost): slug = 'webserver' password = '...' address = 'example.com' username = 'jonathan'
-
address= 'example.com'¶ SSH Address
-
config_filename= '~/.ssh/config'¶ SSH config file (optional)
-
get_start_path()¶ The path in which commands at the server will be executed. by default. (if no cd-statements are used.) Usually, this is the home directory. It should always return an absolute path, starting with ‘/’
-
keepalive_interval= 30¶ SSH keep alive in seconds
-
key_filename= None¶ RSA key filename (optional)
-
port= 22¶ SSH Port
-
rsa_key= None¶ RSA key. (optional)
-
rsa_key_password= None¶ RSA key password. (optional)
-
start_interactive_shell(command=None, initial_input=None, sandbox=False)¶ Start /bin/bash and redirect all SSH I/O from stdin and to stdout.
-
timeout= 10¶ Connection timeout in seconds.
-
username= ''¶ SSH Username
-