当前位置: 首页>>代码示例>>Python>>正文


Python Database.fetch_and_process方法代码示例

本文整理汇总了Python中lib.cuckoo.core.database.Database.fetch_and_process方法的典型用法代码示例。如果您正苦于以下问题:Python Database.fetch_and_process方法的具体用法?Python Database.fetch_and_process怎么用?Python Database.fetch_and_process使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.cuckoo.core.database.Database的用法示例。


在下文中一共展示了Database.fetch_and_process方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import fetch_and_process [as 别名]
class Scheduler:
    """Tasks Scheduler.

    This class is responsible for the main execution loop of the tool. It
    prepares the analysis machines and keep waiting and loading for new
    analysis tasks.
    Whenever a new task is available, it launches AnalysisManager which will
    take care of running the full analysis process and operating with the
    assigned analysis machine.
    """

    def __init__(self):
        self.running = True
        self.cfg = Config()
        self.db = Database()

    def initialize(self):
        """Initialize the machine manager."""
        global mmanager

        mmanager_name = self.cfg.cuckoo.machine_manager

        log.info("Using \"%s\" machine manager" % mmanager_name)

        # Get registered class name. Only one machine manager is imported,
        # therefore there should be only one class in the list.
        plugin = list_plugins("machinemanagers")[0]
        # Initialize the machine manager.
        mmanager = plugin()

        # Find its configuration file.
        conf = os.path.join(CUCKOO_ROOT, "conf", "%s.conf" % mmanager_name)

        if not os.path.exists(conf):
            raise CuckooCriticalError("The configuration file for machine "
                                      "manager \"%s\" does not exist at path: "
                                      "%s" % (mmanager_name, conf))

        # Provide a dictionary with the configuration options to the
        # machine manager instance.
        mmanager.set_options(Config(conf))
        # Initialize the machine manager.
        mmanager.initialize(mmanager_name)

        # At this point all the available machines should have been identified
        # and added to the list. If none were found, Cuckoo needs to abort the
        # execution.
        if mmanager.machines().count() == 0:
            raise CuckooCriticalError("No machines available")
        else:
            log.info("Loaded %s machine/s" % mmanager.machines().count())

    def stop(self):
        """Stop scheduler."""
        self.running = False
        # Shutdown machine manager (used to kill machines that still alive).
        mmanager.shutdown()

    def start(self):
        """Start scheduler."""
        self.initialize()

        log.info("Waiting for analysis tasks...")

        # This loop runs forever.
        while self.running:
            time.sleep(1)

            # If no machines are available, it's pointless to fetch for
            # pending tasks. Loop over.
            if mmanager.availables() == 0:
                continue

            # Fetch a pending analysis task.
            task = self.db.fetch_and_process()

            if task:
                log.debug("Processing task #%s" % task.id)

                # Initialize the analysis manager.
                analysis = AnalysisManager(task)
                analysis.daemon = True
                # Start.
                analysis.start()
开发者ID:Missuniverse110,项目名称:cuckoo,代码行数:86,代码来源:scheduler.py

示例2: __init__

# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import fetch_and_process [as 别名]
class Scheduler:
    """Tasks Scheduler.

    This class is responsible for the main execution loop of the tool. It
    prepares the analysis machines and keep waiting and loading for new
    analysis tasks.
    Whenever a new task is available, it launches AnalysisManager which will
    take care of running the full analysis process and operating with the
    assigned analysis machine.
    """

    def __init__(self):
        self.running = True
        self.cfg = Config()
        self.db = Database()

    def initialize(self):
        """Initialize the machine manager."""
        global mmanager

        mmanager_name = self.cfg.cuckoo.machine_manager

        log.info("Using \"%s\" machine manager", mmanager_name)

        # Get registered class name. Only one machine manager is imported,
        # therefore there should be only one class in the list.
        plugin = list_plugins("machinemanagers")[0]
        # Initialize the machine manager.
        mmanager = plugin()

        # Find its configuration file.
        conf = os.path.join(CUCKOO_ROOT, "conf", "%s.conf" % mmanager_name)

        if not os.path.exists(conf):
            raise CuckooCriticalError("The configuration file for machine "
                                      "manager \"{0}\" does not exist at path: "
                                      "{1}".format(mmanager_name, conf))

        # Provide a dictionary with the configuration options to the
        # machine manager instance.
        mmanager.set_options(Config(conf))
        # Initialize the machine manager.
        mmanager.initialize(mmanager_name)

        # At this point all the available machines should have been identified
        # and added to the list. If none were found, Cuckoo needs to abort the
        # execution.
        if len(mmanager.machines()) == 0:
            raise CuckooCriticalError("No machines available")
        else:
            log.info("Loaded %s machine/s", len(mmanager.machines()))

        ### JG: restore snapshots of all virtual machines
        virtualMachinesList = mmanager.machines()
        for vm in virtualMachinesList:
            mmanager.restore_snapshot(vm.label)

    def stop(self):
        """Stop scheduler."""
        self.running = False
        # Shutdown machine manager (used to kill machines that still alive).
        mmanager.shutdown()

    def start(self):
        """Start scheduler."""
        self.initialize()

        log.info("Waiting for analysis tasks...")

        # Message queue with threads to transmit exceptions (used as IPC).
        errors = Queue.Queue()

        # This loop runs forever.
        while self.running:
            ### JG: added try except to catch keyboard interrrupt and restore VMs
            try:
                time.sleep(1)

                # If no machines are available, it's pointless to fetch for
                # pending tasks. Loop over.
                if mmanager.availables() == 0:
                    continue

                # Fetch a pending analysis task.
                task = self.db.fetch_and_process()

                if task:
                    log.debug("Processing task #%s", task.id)

                    # Initialize the analysis manager.
                    analysis = AnalysisManager(task, errors)
                    # Start.
                    analysis.start()

                # Deal with errors.
                try:
                    exc = errors.get(block=False)
                except Queue.Empty:
                    pass
                else:
#.........这里部分代码省略.........
开发者ID:zeroq,项目名称:cuckoo,代码行数:103,代码来源:scheduler.py


注:本文中的lib.cuckoo.core.database.Database.fetch_and_process方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。