コード例 #1
0
    def _multiquery(self, method, *args, **kwargs):
        """Runs method once for each known MIB instance.

        The internal AgentProxy will be temporarily replaced with one
        representing the current MIB instance for each iteration.

        :param integrator: A function that can take a list of (description,
                           result) tuples. description is the object
                           associated with an instance, as supplied to the
                           class constructor; result is the actual result
                           value of the call to method.

                           If omitted, the default integrator function is
                           self._dictintegrator().

        :returns: A deferred whose result is the return value of the
                  integrator.

        """
        agents = self._make_agents()
        if 'integrator' in kwargs:
            integrator = kwargs['integrator']
            del kwargs['integrator']
        else:
            integrator = self._dictintegrator
        results = []

        for agent, descr in agents:
            self._logger.debug("now querying %r", descr)
            if agent is not self._base_agent:
                agent.open()
            self.agent_proxy = agent
            try:
                one_result = yield method(*args, **kwargs).addErrback(
                    self.__timeout_handler, descr)
            finally:
                if agent is not self._base_agent:
                    agent.close()
                self.agent_proxy = self._base_agent
            results.append((descr, one_result))
            yield lambda thing: fire_eventually(thing)
        defer.returnValue(integrator(results))
コード例 #2
0
ファイル: mibretriever.py プロジェクト: alexanderfefelov/nav
    def _multiquery(self, method, *args, **kwargs):
        """Runs method once for each known MIB instance.

        The internal AgentProxy will be temporarily replaced with one
        representing the current MIB instance for each iteration.

        :param integrator: A function that can take a list of (description,
                           result) tuples. description is the object
                           associated with an instance, as supplied to the
                           class constructor; result is the actual result
                           value of the call to method.

                           If omitted, the default integrator function is
                           self._dictintegrator().

        :returns: A deferred whose result is the return value of the
                  integrator.

        """
        agents = self._make_agents()
        if 'integrator' in kwargs:
            integrator = kwargs['integrator']
            del kwargs['integrator']
        else:
            integrator = self._dictintegrator
        results = []

        for agent, descr in agents:
            self._logger.debug("now querying %r", descr)
            if agent is not self._base_agent:
                agent.open()
            self.agent_proxy = agent
            try:
                one_result = yield method(
                    *args, **kwargs).addErrback(self.__timeout_handler, descr)
            finally:
                if agent is not self._base_agent:
                    agent.close()
                self.agent_proxy = self._base_agent
            results.append((descr, one_result))
            yield lambda thing: fire_eventually(thing)
        defer.returnValue(integrator(results))