mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 22:11:14 +02:00
Support a platform parameter for Qemu
I'm sure we will discover a distribution with a different naming conventions... Fix #220
This commit is contained in:
1 parent
fb79543342
commit
2da0b36ee7
5 files changed
+123
-20
No files matched your search
@@ -51,9 +51,10 @@ class QEMUHandler:
|
||||
qemu = Qemu.instance()
|
||||
vm = yield from qemu.create_vm(request.json.pop("name"),
|
||||
request.match_info["project_id"],
|
||||
request.json.get("vm_id"),
|
||||
qemu_path=request.json.get("qemu_path"),
|
||||
console=request.json.get("console"))
|
||||
request.json.pop("vm_id", None),
|
||||
qemu_path=request.json.pop("qemu_path", None),
|
||||
platform=request.json.pop("platform", None),
|
||||
console=request.json.pop("console", None))
|
||||
|
||||
for name, value in request.json.items():
|
||||
if hasattr(vm, name) and getattr(vm, name) != value:
|
||||
|
||||
@@ -22,6 +22,7 @@ order to run a QEMU VM.
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import shlex
|
||||
@@ -35,13 +36,16 @@ from ..nios.nio_udp import NIOUDP
|
||||
from ..nios.nio_tap import NIOTAP
|
||||
from ..nios.nio_nat import NIONAT
|
||||
from ..base_vm import BaseVM
|
||||
from ...schemas.qemu import QEMU_OBJECT_SCHEMA
|
||||
from ...schemas.qemu import QEMU_OBJECT_SCHEMA, QEMU_PLATFORMS
|
||||
from ...utils.asyncio import monitor_process
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class QemuVM(BaseVM):
|
||||
module_name = 'qemu'
|
||||
|
||||
@@ -54,10 +58,11 @@ class QemuVM(BaseVM):
|
||||
:param manager: Manager instance
|
||||
:param console: TCP console port
|
||||
:param qemu_path: path to the QEMU binary
|
||||
:param platform: Platform to emulate
|
||||
:param console: TCP console port
|
||||
"""
|
||||
|
||||
def __init__(self, name, vm_id, project, manager, qemu_path=None, console=None):
|
||||
def __init__(self, name, vm_id, project, manager, qemu_path=None, console=None, platform=None):
|
||||
|
||||
super().__init__(name, vm_id, project, manager, console=console)
|
||||
server_config = manager.config.get_section_config("Server")
|
||||
@@ -70,7 +75,18 @@ class QemuVM(BaseVM):
|
||||
self._stdout_file = ""
|
||||
|
||||
# QEMU VM settings
|
||||
self.qemu_path = qemu_path
|
||||
|
||||
if qemu_path:
|
||||
try:
|
||||
self.qemu_path = qemu_path
|
||||
except QemuError as e:
|
||||
if platform:
|
||||
self.platform = platform
|
||||
else:
|
||||
raise e
|
||||
else:
|
||||
self.platform = platform
|
||||
|
||||
self._hda_disk_image = ""
|
||||
self._hdb_disk_image = ""
|
||||
self._hdc_disk_image = ""
|
||||
@@ -124,6 +140,20 @@ class QemuVM(BaseVM):
|
||||
if qemu_path and os.pathsep not in qemu_path:
|
||||
qemu_path = shutil.which(qemu_path)
|
||||
|
||||
self._check_qemu_path(qemu_path)
|
||||
self._qemu_path = qemu_path
|
||||
self._platform = os.path.basename(qemu_path)
|
||||
if self._platform == "qemu-kvm":
|
||||
self._platform = "x86_64"
|
||||
else:
|
||||
self._platform = re.sub(r'^qemu-system-(.*)(w.exe)?$', r'\1', os.path.basename(qemu_path), re.IGNORECASE)
|
||||
if self._platform not in QEMU_PLATFORMS:
|
||||
raise QemuError("Platform {} is unknown".format(self._platform))
|
||||
log.info('QEMU VM "{name}" [{id}] has set the QEMU path to {qemu_path}'.format(name=self._name,
|
||||
id=self._id,
|
||||
qemu_path=qemu_path))
|
||||
|
||||
def _check_qemu_path(self, qemu_path):
|
||||
if qemu_path is None:
|
||||
raise QemuError("QEMU binary path is not set or not found in the path")
|
||||
if not os.path.exists(qemu_path):
|
||||
@@ -131,10 +161,20 @@ class QemuVM(BaseVM):
|
||||
if not os.access(qemu_path, os.X_OK):
|
||||
raise QemuError("QEMU binary '{}' is not executable".format(qemu_path))
|
||||
|
||||
self._qemu_path = qemu_path
|
||||
log.info('QEMU VM "{name}" [{id}] has set the QEMU path to {qemu_path}'.format(name=self._name,
|
||||
id=self._id,
|
||||
qemu_path=qemu_path))
|
||||
@property
|
||||
def platform(self):
|
||||
"""
|
||||
Return the current platform
|
||||
"""
|
||||
return self._platform
|
||||
|
||||
@platform.setter
|
||||
def platform(self, platform):
|
||||
self._platform = platform
|
||||
if sys.platform.startswith("win"):
|
||||
self.qemu_path = "qemu-system-{}w.exe".format(platform)
|
||||
else:
|
||||
self.qemu_path = "qemu-system-{}".format(platform)
|
||||
|
||||
@property
|
||||
def hda_disk_image(self):
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
QEMU_PLATFORMS = ["aarch64", "alpha", "arm", "cris", "i386", "lm32", "m68k", "microblaze", "microblazeel", "mips", "mips64", "mips64el", "mipsel", "moxie", "or32", "ppc", "ppc64", "ppcemb", "s390x", "sh4", "sh4eb", "sparc", "sparc64", "tricore", "unicore32", "x86_64", "xtensa", "xtensaeb"]
|
||||
|
||||
|
||||
QEMU_CREATE_SCHEMA = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
@@ -38,9 +40,13 @@ QEMU_CREATE_SCHEMA = {
|
||||
},
|
||||
"qemu_path": {
|
||||
"description": "Path to QEMU",
|
||||
"type": "string",
|
||||
"type": ["string", "null"],
|
||||
"minLength": 1,
|
||||
},
|
||||
"platform": {
|
||||
"description": "Platform to emulate",
|
||||
"enum": QEMU_PLATFORMS + ["null"]
|
||||
},
|
||||
"console": {
|
||||
"description": "console TCP port",
|
||||
"minimum": 1,
|
||||
@@ -130,7 +136,7 @@ QEMU_CREATE_SCHEMA = {
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["name", "qemu_path"],
|
||||
"required": ["name"],
|
||||
}
|
||||
|
||||
QEMU_UPDATE_SCHEMA = {
|
||||
@@ -148,6 +154,10 @@ QEMU_UPDATE_SCHEMA = {
|
||||
"type": ["string", "null"],
|
||||
"minLength": 1,
|
||||
},
|
||||
"platform": {
|
||||
"description": "Platform to emulate",
|
||||
"enum": QEMU_PLATFORMS + ["null"]
|
||||
},
|
||||
"console": {
|
||||
"description": "console TCP port",
|
||||
"minimum": 1,
|
||||
@@ -264,6 +274,10 @@ QEMU_OBJECT_SCHEMA = {
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
},
|
||||
"platform": {
|
||||
"description": "Platform to emulate",
|
||||
"enum": QEMU_PLATFORMS
|
||||
},
|
||||
"hda_disk_image": {
|
||||
"description": "QEMU hda disk image path",
|
||||
"type": "string",
|
||||
@@ -352,7 +366,7 @@ QEMU_OBJECT_SCHEMA = {
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["vm_id", "project_id", "name", "qemu_path", "hda_disk_image", "hdb_disk_image",
|
||||
"required": ["vm_id", "project_id", "name", "qemu_path", "platform", "hda_disk_image", "hdb_disk_image",
|
||||
"hdc_disk_image", "hdd_disk_image", "ram", "adapters", "adapter_type", "mac_address", "console",
|
||||
"initrd", "kernel_image", "kernel_command_line", "legacy_networking", "acpi_shutdown", "kvm",
|
||||
"cpu_throttling", "process_priority", "options"]
|
||||
|
||||
Reference in new issue
Block a user