Skip to content

Fix regression in VM selection. #1035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions lib/cuckoo/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,19 @@ def guest_stop(self, guest_id):
finally:
session.close()

@staticmethod
def filter_machines_by_arch(machines, arch):
"""Add a filter to the given query for the architecture of the machines.
Allow x64 machines to be returned when requesting x86.
"""
if arch:
if arch == "x86":
# Prefer x86 machines over x64 if x86 is what was requested.
machines = machines.filter(Machine.arch.in_(("x64", "x86"))).order_by(Machine.arch.desc())
else:
machines = machines.filter_by(arch=arch)
return machines

@classlock
def list_machines(self, locked=None, label=None, platform=None, tags=[], arch=None):
"""Lists virtual machines.
Expand All @@ -961,8 +974,7 @@ def list_machines(self, locked=None, label=None, platform=None, tags=[], arch=No
machines = machines.filter_by(label=label)
if platform:
machines = machines.filter_by(platform=platform)
if arch:
machines = machines.filter_by(arch=arch)
machines = self.filter_machines_by_arch(machines, arch)
if tags:
for tag in tags:
machines = machines.filter(Machine.tags.any(name=tag))
Expand Down Expand Up @@ -1002,8 +1014,7 @@ def lock_machine(self, label=None, platform=None, tags=None, arch=None):
machines = machines.filter_by(label=label)
if platform:
machines = machines.filter_by(platform=platform)
if arch:
machines = machines.filter_by(arch=arch)
machines = self.filter_machines_by_arch(machines, arch)
if tags:
for tag in tags:
machines = machines.filter(Machine.tags.any(name=tag))
Expand Down