本文整理汇总了Python中lib.cuckoo.core.database.Database.lock_machine方法的典型用法代码示例。如果您正苦于以下问题:Python Database.lock_machine方法的具体用法?Python Database.lock_machine怎么用?Python Database.lock_machine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.cuckoo.core.database.Database
的用法示例。
在下文中一共展示了Database.lock_machine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Machinery
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import lock_machine [as 别名]
#.........这里部分代码省略.........
try:
self.stop(machine.label)
except CuckooMachineError as e:
msg = "Please update your configuration. Unable to shut " \
"'{0}' down or find the machine in its proper state:" \
" {1}".format(machine.label, e)
raise CuckooCriticalError(msg)
if not self.options_globals.timeouts.vm_state:
raise CuckooCriticalError("Virtual machine state change timeout "
"setting not found, please add it to "
"the config file.")
def machines(self):
"""List virtual machines.
@return: virtual machines list
"""
return self.db.list_machines()
def availables(self):
"""How many machines are free.
@return: free machines count.
"""
return self.db.count_machines_available()
def acquire(self, machine_id=None, platform=None, tags=None):
"""Acquire a machine to start analysis.
@param machine_id: machine ID.
@param platform: machine platform.
@param tags: machine tags
@return: machine or None.
"""
if machine_id:
return self.db.lock_machine(label=machine_id)
elif platform:
return self.db.lock_machine(platform=platform, tags=tags)
else:
return self.db.lock_machine(tags=tags)
def release(self, label=None):
"""Release a machine.
@param label: machine name.
"""
self.db.unlock_machine(label)
def running(self):
"""Returns running virtual machines.
@return: running virtual machines list.
"""
return self.db.list_machines(locked=True)
def shutdown(self):
"""Shutdown the machine manager. Kills all alive machines.
@raise CuckooMachineError: if unable to stop machine.
"""
if len(self.running()) > 0:
log.info("Still %s guests alive. Shutting down...",
len(self.running()))
for machine in self.running():
try:
self.stop(machine.label)
except CuckooMachineError as e:
log.warning("Unable to shutdown machine %s, please check "
"manually. Error: %s", machine.label, e)
def set_status(self, label, status):
示例2: MachineManager
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import lock_machine [as 别名]
class MachineManager(object):
"""Base abstract class for analysis machine manager."""
def __init__(self):
self.module_name = ""
self.options = None
self.options_globals = Config(os.path.join(CUCKOO_ROOT, "conf", "cuckoo.conf"))
# Database pointer.
self.db = Database()
# Machine table is cleaned to be filled from configuration file at each start.
self.db.clean_machines()
def set_options(self, options):
"""Set machine manager options.
@param options: machine manager options dict.
"""
self.options = options
def initialize(self, module_name):
"""Read and load machines configuration, try to check the configuration.
@param module_name: module name.
"""
# Load.
self._initialize(module_name)
# Run initialization checks.
self._initialize_check()
def _initialize(self, module_name):
"""Read configuration.
@param module_name: module name.
"""
self.module_name = module_name
mmanager_opts = self.options.get(module_name)
for machine_id in mmanager_opts["machines"].strip().split(","):
# Parse from configuration file.
try:
machine_opts = self.options.get(machine_id.strip())
machine = Dictionary()
machine.id = machine_id.strip()
machine.label = machine_opts["label"].strip()
machine.platform = machine_opts["platform"].strip()
machine.ip = machine_opts["ip"].strip()
# Insert in db.
self.db.add_machine(name=machine.id,
label=machine.label,
ip=machine.ip,
platform=machine.platform)
except (AttributeError, CuckooOperationalError):
log.warning("Configuration details about machine %s are "
"missing. Continue" % machine_id)
continue
def _initialize_check(self):
"""Runs checks against virtualization software when a machine manager
is initialized.
@note: in machine manager modules you may override or superclass
his method.
@raise CuckooMachineError: if a misconfiguration or a unkown vm state
is found.
"""
try:
configured_vm = self._list()
except NotImplementedError:
return
for machine in self.machines():
if machine.label not in configured_vm:
raise CuckooCriticalError("Configured machine %s was not "
"detected or it's not in proper state" % machine.label)
# Options check.
if not self.options_globals.timeouts.vm_state:
raise CuckooCriticalError("Virtual machine state change timeout setting not found, please add it to the config file")
def machines(self):
"""List virtual machines.
@return: virtual machines list
"""
return self.db.list_machines()
def availables(self):
"""How many machines are free.
@return: free machines count.
"""
return self.db.count_machines_available()
def acquire(self, machine_id=None, platform=None):
"""Acquire a machine to start analysis.
@param machine_id: machine ID.
@param platform: machine platform.
@return: machine or None.
"""
if machine_id:
return self.db.lock_machine(name=machine_id)
elif platform:
return self.db.lock_machine(platform=platform)
else:
#.........这里部分代码省略.........