[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type
From: |
Cleber Rosa |
Subject: |
[Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type based on arch |
Date: |
Tue, 9 Oct 2018 19:26:04 -0400 |
Some targets require a machine type to be set, as there's no default
(aarch64 is one example). To give a consistent interface to users of
this API, this changes set_machine() so that a predefined default can
be used, if one is not given. The approach used is exactly the same
with the console device type.
Also, even when there's a default machine type, for some purposes,
testing included, it's better if outside code is explicit about the
machine type, instead of relying on whatever is set internally.
Signed-off-by: Cleber Rosa <address@hidden>
---
scripts/qemu.py | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/scripts/qemu.py b/scripts/qemu.py
index d9e24a0c1a..fca9b76990 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -36,6 +36,15 @@ CONSOLE_DEV_TYPES = {
r'^s390-ccw-virtio.*': 'sclpconsole',
}
+#: Maps archictures to the preferred machine type
+MACHINE_TYPES = {
+ r'^aarch64$': 'virt',
+ r'^ppc$': 'g3beige',
+ r'^ppc64$': 'pseries',
+ r'^s390x$': 's390-ccw-virtio',
+ r'^x86_64$': 'q35',
+ }
+
class QEMUMachineError(Exception):
"""
@@ -413,13 +422,24 @@ class QEMUMachine(object):
"""
self._arch = arch
- def set_machine(self, machine_type):
+ def set_machine(self, machine_type=None):
'''
Sets the machine type
If set, the machine type will be added to the base arguments
of the resulting QEMU command line.
'''
+ if machine_type is None:
+ if self._arch is None:
+ raise QEMUMachineError("Can not set a default machine type: "
+ "QEMU instance without a defined arch")
+ for regex, machine in MACHINE_TYPES.items():
+ if re.match(regex, self._arch):
+ machine_type = machine
+ break
+ if machine_type is None:
+ raise QEMUMachineError("Can not set a machine type: no "
+ "matching machine type definition")
self._machine = machine_type
def set_console(self, device_type=None):
--
2.17.1
- [Qemu-devel] [PATCH v2 0/7] Acceptance Tests: basic architecture support, Cleber Rosa, 2018/10/09
- [Qemu-devel] [PATCH v2 1/7] Acceptance Tests: improve docstring on pick_default_qemu_bin(), Cleber Rosa, 2018/10/09
- [Qemu-devel] [PATCH v2 3/7] scripts/qemu.py: add method and private attribute for arch, Cleber Rosa, 2018/10/09
- [Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type based on arch,
Cleber Rosa <=
- Re: [Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type based on arch, Philippe Mathieu-Daudé, 2018/10/10
- Re: [Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type based on arch, Cleber Rosa, 2018/10/10
- Re: [Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type based on arch, Eduardo Habkost, 2018/10/10
- Re: [Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type based on arch, Cleber Rosa, 2018/10/10
- Re: [Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type based on arch, Cleber Rosa, 2018/10/10
- Re: [Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type based on arch, Eduardo Habkost, 2018/10/10
- Re: [Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type based on arch, Philippe Mathieu-Daudé, 2018/10/10
- Re: [Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type based on arch, Cleber Rosa, 2018/10/10
- Re: [Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type based on arch, Philippe Mathieu-Daudé, 2018/10/10
- Re: [Qemu-devel] [PATCH v2 4/7] scripts/qemu.py: set predefined machine type based on arch, Cleber Rosa, 2018/10/10