host_container

Access to hosts from within a Node class happens through a HostsContainer proxy. This container object has also methods for reducing the amount of hosts on which commands are executed, by filtering according to conditions.

The hosts property of Env wrapper around a node instance returns such a HostsContainer object.

class MyNode(Node):
    class Hosts:
        web_servers = { Host1, Host2 }
        caching_servers = Host3

    def do_something(self):
        # ``self.hosts`` here is a HostsContainer instance.
        self.hosts.filter('caching_servers').run('echo hello')

Reference

class deployer.host_container.HostsContainer(hosts, pty=None, logger=None, is_sandbox=False)

Proxy to a group of Host instances.

For instance, if you have a role, name ‘www’ inside the container, you could do:

host_container.run(...)
host_container[0].run(...)
host_container.filter('www')[0].run(...)

Typically, you get a HostsContainer class by accessing the hosts property of an Env (Node wrapper.)

cd(path, expand=False)

Execute commands in this directory. Nesting of cd-statements is allowed.

Call cd() on the HostContext of every host.

with host_container.cd('directory'):
    host_container.run('ls')
env(variable, value, escape=True)

Sets an environment variable.

This calls env() on the HostContext of every host.

with host_container.cd('VAR', 'my-value'):
    host_container.run('echo $VAR')
exists(filename, use_sudo=True)

Returns an array of boolean values that represent whether this a file with this name exist for each host.

filter(*roles)

Returns a new HostsContainer instance, containing only the hosts matching this filter. The hosts are passed by reference, so if you’d call cd() on the returned container, it will also effect the hosts in this object.

Examples:

hosts.filter('role1', 'role2')
classmethod from_definition(hosts_class, **kw)

Create a HostsContainer from a Hosts class.

get_hosts()

Return a set of deployer.host.Host classes that appear in this container. Each deployer.host.Host class will abviously appear only once in the set, even when it appears in several roles.

get_hosts_as_dict()

Return a dictionary which maps all the roles to the set of deployer.host.Host classes for each role.

getcwd()

Calls getcwd() for every host and return the result as an array.

has_command(command, use_sudo=False)

Test whether this command can be found in the bash shell, by executing a ‘which’

prefix(command)

Call prefix() on the HostContext of every host.

with host.prefix('workon environment'):
    host.run('./manage.py migrate')
run(command, sandbox=False, interactive=True, user=None, ignore_exit_status=False, initial_input=None)

Call run() with this parameters on every Host in this container. It can be executed in parallel when we have multiple hosts.

Returns:An array of all the results.
sudo(command, sandbox=False, interactive=True, user=None, ignore_exit_status=False, initial_input=None)

Call sudo() with this parameters on every Host in this container. It can be executed in parallel when we have multiple hosts.

Returns:An array of all the results.
class deployer.host_container.HostContainer(hosts, pty=None, logger=None, is_sandbox=False)

Similar to HostsContainer, but wraps only around exactly one Host.

exists(filename, use_sudo=True)

Returns True when this file exists on the hosts.

get_file(*args, **kwargs)

Download this remote_file.

getcwd()

Calls getcwd() for every host and return the result as an array.

has_command(command, use_sudo=False)

Test whether this command can be found in the bash shell, by executing a which Returns True when the command exists.

open(*args, **kwargs)

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')
put_file(*args, **kwargs)

Upload this local_file to the remote location.

run(command, sandbox=False, interactive=True, user=None, ignore_exit_status=False, initial_input=None)

Call run() with this parameters on every Host in this container. It can be executed in parallel when we have multiple hosts.

Returns:An array of all the results.
sudo(command, sandbox=False, interactive=True, user=None, ignore_exit_status=False, initial_input=None)

Call sudo() with this parameters on every Host in this container. It can be executed in parallel when we have multiple hosts.

Returns:An array of all the results.