本文整理汇总了Python中cuckoo.core.database.Database.list_machines方法的典型用法代码示例。如果您正苦于以下问题:Python Database.list_machines方法的具体用法?Python Database.list_machines怎么用?Python Database.list_machines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cuckoo.core.database.Database
的用法示例。
在下文中一共展示了Database.list_machines方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Machinery
# 需要导入模块: from cuckoo.core.database import Database [as 别名]
# 或者: from cuckoo.core.database.Database import list_machines [as 别名]
#.........这里部分代码省略.........
try:
configured_vms = self._list()
except NotImplementedError:
return
for machine in self.machines():
# If this machine is already in the "correct" state, then we
# go on to the next machine.
if machine.label in configured_vms and \
self._status(machine.label) in [self.POWEROFF, self.ABORTED]:
continue
# This machine is currently not in its correct state, we're going
# to try to shut it down. If that works, then the machine is fine.
try:
self.stop(machine.label)
except CuckooMachineError as e:
raise CuckooCriticalError(
"Please update your configuration. Unable to shut '%s' "
"down or find the machine in its proper state: %s" %
(machine.label, e)
)
if not config("cuckoo:timeouts:vm_state"):
raise CuckooCriticalError(
"Virtual machine state change timeout has not been set "
"properly, please update it to be non-null."
)
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)
示例2: test_machines
# 需要导入模块: from cuckoo.core.database import Database [as 别名]
# 或者: from cuckoo.core.database.Database import list_machines [as 别名]
def test_machines():
set_cwd(tempfile.mkdtemp())
Folders.create(cwd(), "conf")
Files.create(cwd("conf"), "cuckoo.conf", """
[cuckoo]
machinery = virtualbox
[database]
connection =
timeout =
[resultserver]
ip = 9.8.7.6
port = 9876
""")
Files.create(cwd("conf"), "virtualbox.conf", """
[virtualbox]
machines = a, b, c
[a]
label = a
snapshot = derpa
platform = windows
ip = 1.2.3.4
[b]
label = b
snapshot = derpb
platform = windows
ip = 5.6.7.8
resultserver_ip = 7.5.3.1
[c]
label = c
snapshot = derpc
platform = windows
ip = 1.3.5.7
resultserver_port = 4242
""")
class mock(object):
port = 9001
Singleton._instances[ResultServer] = mock()
db = Database()
db.connect()
m = Machinery()
m.set_options(Config("virtualbox"))
m._initialize("virtualbox")
machines = db.list_machines()
assert len(machines) == 3
assert machines[0].label == "a"
assert machines[0].snapshot == "derpa"
assert machines[0].ip == "1.2.3.4"
assert machines[0].resultserver_ip == "9.8.7.6"
assert machines[0].resultserver_port == 9001
assert machines[1].label == "b"
assert machines[1].snapshot == "derpb"
assert machines[1].ip == "5.6.7.8"
assert machines[1].resultserver_ip == "7.5.3.1"
assert machines[1].resultserver_port == 9001
assert machines[2].label == "c"
assert machines[2].snapshot == "derpc"
assert machines[2].ip == "1.3.5.7"
assert machines[2].resultserver_ip == "9.8.7.6"
assert machines[2].resultserver_port == 4242
Singleton._instances.pop(ResultServer)