示例#1
0
    def processOutput(self, plugin, output, command_id, isReport=False):
        output_queue = multiprocessing.JoinableQueue()
        new_elem_queue = multiprocessing.Queue()

        plugin_process = PluginProcess(plugin, output_queue, new_elem_queue,
                                       isReport)

        getLogger(self).debug(
            "Created plugin_process (%d) for plugin instance (%d)" %
            (id(plugin_process), id(plugin)))

        plugin_process.start()

        output_queue.put(output)
        output_queue.put(None)
        output_queue.join()

        self._processAction(modelactions.PLUGINSTART, [plugin.id])

        while True:
            try:
                current_action = new_elem_queue.get(block=False)
                if current_action is None:
                    break
                action = current_action[0]
                parameters = current_action[1:]

                parameters[-1]._metadata.command_id = command_id

                getLogger(self).debug(
                    "Core: Processing a new '%s', parameters (%s)\n" %
                    (action, str(parameters)))
                self._processAction(action, parameters)

            except Queue.Empty:
                continue
            except IOError, e:
                if e.errno == errno.EINTR:
                    continue
                else:
                    getLogger(self).debug("new_elem_queue Exception - "
                                          "something strange happened... "
                                          "unhandled exception?")
                    break
            except Exception:
                getLogger(self).debug("new_elem_queue Exception - "
                                      "something strange happened... "
                                      "unhandled exception?")
                break
示例#2
0
    def processOutput(self, plugin, output, command, isReport=False):
        """
            Process the output of the plugin. This will start the PluginProcess
            and also PluginCommiter (thread) that will informa to faraday server
            when the command finished.

        :param plugin: Plugin to execute
        :param output: read output from plugin or term
        :param command_id: command id that started the plugin
        :param isReport: Report or output from shell
        :return: None
        """
        output_queue = JoinableQueue()
        plugin.set_actions_queue(self.pending_actions)

        plugin_process = PluginProcess(
            plugin, output_queue, isReport)

        getLogger(self).debug(
            "Created plugin_process (%d) for plugin instance (%d)" %
            (id(plugin_process), id(plugin)))

        self.pending_actions.put((Modelactions.PLUGINSTART, plugin.id, command.getID()))
        output_queue.put((output, command.getID()))
        plugin_commiter = PluginCommiter(
            output_queue,
            output,
            self.pending_actions,
            plugin,
            command,
            self._mapper_manager,
            self.end_event,
        )
        plugin_commiter.start()
        # This process is stopped when plugin commiter joins output queue
        plugin_process.start()