Beispiel #1
0
    def __init__(self, node, pty=None, logger=None, is_sandbox=False):
        assert isinstance(node, Node)

        self._node = node
        self._pty = pty or DummyPty()
        self._logger = logger or DummyLoggerInterface()
        self._is_sandbox = is_sandbox

        # When the node is callable (when it has a default action),
        # make sure that this env becomes collable as well.
        if callable(self._node):
            # Per instance overriding
            def call(self, *a, **kw):
                return self.__getattr__('__call__')(*a, **kw)

            self.__class__ = type(self.__class__.__name__, (self.__class__, ),
                                  {'__call__': call})

        # Create a new HostsContainer object which is identical to the one of
        # the Node object, but add pty/logger/sandbox settings. (So, this
        # doesn't create new Host instances, only a new container.)
        # (do this in this constructor. Each call to Env.hosts should return
        # the same host container instance.)
        self._hosts = HostsContainer(self._node.hosts.get_hosts_as_dict(),
                                     pty=self._pty,
                                     logger=self._logger,
                                     is_sandbox=is_sandbox)

        # Lock Env
        self._lock_env = True
Beispiel #2
0
def Connect(self):
    """
    Open interactive SSH connection with this host.
    """
    from deployer.contrib.services import connect
    from deployer.host_container import HostsContainer
    c = connect.Connect(HostsContainer({ 'host': self.service.hosts._all }))

    # Run as any other action. (Nice exception handling, e.g. in case of NoInput on host selection.)
    Action(c.with_host, self.shell, False)()
Beispiel #3
0
    def __init__(self, parent=None):
        #: Reference to the parent :class:`~deployer.node.base.Node`.
        #: (This is always assigned in the constructor. You should never override it.)
        self.parent = parent

        if self._node_type in (NodeTypes.SIMPLE_ARRAY,
                               NodeTypes.SIMPLE_ONE) and not parent:
            raise Exception(
                'Cannot initialize a node of type %s without a parent' %
                self._node_type)

        # Create host container (from hosts definition, or mapping from parent hosts.)
        Hosts = self.Hosts or DefaultRoleMapping()

        if isinstance(Hosts, RoleMapping):
            self.hosts = Hosts.apply(parent) if parent else HostsContainer({})
        else:
            self.hosts = HostsContainer.from_definition(Hosts)
Beispiel #4
0
    def apply(self, parent_node_instance):
        """
        Map roles from the parent to the child node and create a new
        :class:`HostsContainer` instance by applying it.
        """
        parent_container = parent_node_instance.hosts

        def get(f):
            if f == ALL_HOSTS:
                return parent_container.get_hosts()
            else:
                assert isinstance(f, tuple), TypeError(
                    'Invalid value found in mapping: %r' % f)
                return parent_container.filter(*f).get_hosts()

        return HostsContainer(
            {role: get(f)
             for role, f in self._mappings.items()},
            pty=parent_container._pty,
            logger=parent_container._logger,
            is_sandbox=parent_container._sandbox)