Beispiel #1
0
    def _process_exec_jobs(self, execjobs, die, timeout, fanout):
        jobs = []
        for job in execjobs:
            state = STATE_UNKNOWN
            try:
                job.wait(timeout)
                state = job.state
            except acclient.ResultTimeout:
                if die:
                    raise
                state = STATE_TIMEDOUT

            stdout, stderr = job.streams
            error = stderr or job.data
            if state != STATE_SUCCESS and die:
                raise acclient.AgentException(
                    'Job on agent {job.gid}.{job.nid} failed with status: "{job.state}" and message: "{error}"'
                    .format(job=job, error=error))

            jobs.append((job.gid, job.nid, state, stdout, error))

        if fanout:
            # potential multiple results.
            return self._build_result(jobs)
        else:
            # single job
            _, _, state, stdout, stderr = jobs.pop()
            return ResultTuple(state, stdout, stderr)
Beispiel #2
0
    def tunnel_create(self, gid, nid, local, remote_gid, remote_nid, ip,
                      remote):
        """
        Opens a tunnel that accepts connection at the agent's local port `local`
        and forwards the received connections to remote agent `gateway` which will
        forward the tunnel connection to `ip:remote`

        Note: The agent will proxy the connection over the agent-controller it recieved this open command from.

        :param gid: Grid id
        :param nid: Node id
        :param local: Agent's local listening port for the tunnel. 0 for dynamic allocation
        :param remote_gid: Grid id of remote node
        :param remote_nid: Node id of remote node
        :param ip: The endpoint ip address on the remote agent network. Note that IP must be a real ip not a host name
                 dns names lookup is not supported.
        :param remote: The endpoint port on the remote agent network
        """

        agents = self.getAgents()
        found = False
        for agent in agents:
            if agent.nid == remote_nid and agent.gid == remote_gid:
                found = True
                break

        if not found:
            raise acclient.AgentException('Remote end %s:%s is not alive!' %
                                          (remote_gid, remote_nid))

        gateway = '%s.%s' % (remote_gid, remote_nid)
        return self._client.tunnel_open(gid, nid, local, gateway, ip, remote)