mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-15 12:59:06 +00:00
Support for modifications to a base Qemu VM (not a linked clone).
This commit is contained in:
parent
2fbc391319
commit
ce4727e51a
@ -58,6 +58,7 @@ class QEMUHandler:
|
|||||||
vm = yield from qemu.create_vm(request.json.pop("name"),
|
vm = yield from qemu.create_vm(request.json.pop("name"),
|
||||||
request.match_info["project_id"],
|
request.match_info["project_id"],
|
||||||
request.json.pop("vm_id", None),
|
request.json.pop("vm_id", None),
|
||||||
|
linked_clone=request.json.get("linked_clone", True),
|
||||||
qemu_path=request.json.pop("qemu_path", None),
|
qemu_path=request.json.pop("qemu_path", None),
|
||||||
console=request.json.pop("console", None),
|
console=request.json.pop("console", None),
|
||||||
console_type=request.json.pop("console_type", "telnet"),
|
console_type=request.json.pop("console_type", "telnet"),
|
||||||
|
@ -61,12 +61,13 @@ class QemuVM(BaseVM):
|
|||||||
:param console: TCP console port
|
:param console: TCP console port
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name, vm_id, project, manager, qemu_path=None, console=None, console_type="telnet", platform=None):
|
def __init__(self, name, vm_id, project, manager, linked_clone=True, qemu_path=None, console=None, console_type="telnet", platform=None):
|
||||||
|
|
||||||
super().__init__(name, vm_id, project, manager, console=console, console_type=console_type)
|
super().__init__(name, vm_id, project, manager, console=console, console_type=console_type)
|
||||||
server_config = manager.config.get_section_config("Server")
|
server_config = manager.config.get_section_config("Server")
|
||||||
self._host = server_config.get("host", "127.0.0.1")
|
self._host = server_config.get("host", "127.0.0.1")
|
||||||
self._monitor_host = server_config.get("monitor_host", "127.0.0.1")
|
self._monitor_host = server_config.get("monitor_host", "127.0.0.1")
|
||||||
|
self._linked_clone = linked_clone
|
||||||
self._command = []
|
self._command = []
|
||||||
self._process = None
|
self._process = None
|
||||||
self._cpulimit_process = None
|
self._cpulimit_process = None
|
||||||
@ -1226,8 +1227,10 @@ class QemuVM(BaseVM):
|
|||||||
raise QemuError("hda disk image '{}' linked to '{}' is not accessible".format(self._hda_disk_image, os.path.realpath(self._hda_disk_image)))
|
raise QemuError("hda disk image '{}' linked to '{}' is not accessible".format(self._hda_disk_image, os.path.realpath(self._hda_disk_image)))
|
||||||
else:
|
else:
|
||||||
raise QemuError("hda disk image '{}' is not accessible".format(self._hda_disk_image))
|
raise QemuError("hda disk image '{}' is not accessible".format(self._hda_disk_image))
|
||||||
|
if self._linked_clone:
|
||||||
hda_disk = os.path.join(self.working_dir, "hda_disk.qcow2")
|
hda_disk = os.path.join(self.working_dir, "hda_disk.qcow2")
|
||||||
if not os.path.exists(hda_disk):
|
if not os.path.exists(hda_disk):
|
||||||
|
# create the disk
|
||||||
try:
|
try:
|
||||||
process = yield from asyncio.create_subprocess_exec(qemu_img_path, "create", "-o",
|
process = yield from asyncio.create_subprocess_exec(qemu_img_path, "create", "-o",
|
||||||
"backing_file={}".format(self._hda_disk_image),
|
"backing_file={}".format(self._hda_disk_image),
|
||||||
@ -1236,6 +1239,8 @@ class QemuVM(BaseVM):
|
|||||||
log.info("{} returned with {}".format(qemu_img_path, retcode))
|
log.info("{} returned with {}".format(qemu_img_path, retcode))
|
||||||
except (OSError, subprocess.SubprocessError) as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
raise QemuError("Could not create hda disk image {}".format(e))
|
raise QemuError("Could not create hda disk image {}".format(e))
|
||||||
|
else:
|
||||||
|
hda_disk = self._hda_disk_image
|
||||||
options.extend(["-drive", 'file={},if={},index=0,media=disk'.format(hda_disk, self.hda_disk_interface)])
|
options.extend(["-drive", 'file={},if={},index=0,media=disk'.format(hda_disk, self.hda_disk_interface)])
|
||||||
|
|
||||||
if self._hdb_disk_image:
|
if self._hdb_disk_image:
|
||||||
@ -1244,6 +1249,7 @@ class QemuVM(BaseVM):
|
|||||||
raise QemuError("hdb disk image '{}' linked to '{}' is not accessible".format(self._hdb_disk_image, os.path.realpath(self._hdb_disk_image)))
|
raise QemuError("hdb disk image '{}' linked to '{}' is not accessible".format(self._hdb_disk_image, os.path.realpath(self._hdb_disk_image)))
|
||||||
else:
|
else:
|
||||||
raise QemuError("hdb disk image '{}' is not accessible".format(self._hdb_disk_image))
|
raise QemuError("hdb disk image '{}' is not accessible".format(self._hdb_disk_image))
|
||||||
|
if self._linked_clone:
|
||||||
hdb_disk = os.path.join(self.working_dir, "hdb_disk.qcow2")
|
hdb_disk = os.path.join(self.working_dir, "hdb_disk.qcow2")
|
||||||
if not os.path.exists(hdb_disk):
|
if not os.path.exists(hdb_disk):
|
||||||
try:
|
try:
|
||||||
@ -1254,6 +1260,8 @@ class QemuVM(BaseVM):
|
|||||||
log.info("{} returned with {}".format(qemu_img_path, retcode))
|
log.info("{} returned with {}".format(qemu_img_path, retcode))
|
||||||
except (OSError, subprocess.SubprocessError) as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
raise QemuError("Could not create hdb disk image {}".format(e))
|
raise QemuError("Could not create hdb disk image {}".format(e))
|
||||||
|
else:
|
||||||
|
hdb_disk = self._hdb_disk_image
|
||||||
options.extend(["-drive", 'file={},if={},index=1,media=disk'.format(hdb_disk, self.hdb_disk_interface)])
|
options.extend(["-drive", 'file={},if={},index=1,media=disk'.format(hdb_disk, self.hdb_disk_interface)])
|
||||||
|
|
||||||
if self._hdc_disk_image:
|
if self._hdc_disk_image:
|
||||||
@ -1262,6 +1270,7 @@ class QemuVM(BaseVM):
|
|||||||
raise QemuError("hdc disk image '{}' linked to '{}' is not accessible".format(self._hdc_disk_image, os.path.realpath(self._hdc_disk_image)))
|
raise QemuError("hdc disk image '{}' linked to '{}' is not accessible".format(self._hdc_disk_image, os.path.realpath(self._hdc_disk_image)))
|
||||||
else:
|
else:
|
||||||
raise QemuError("hdc disk image '{}' is not accessible".format(self._hdc_disk_image))
|
raise QemuError("hdc disk image '{}' is not accessible".format(self._hdc_disk_image))
|
||||||
|
if self._linked_clone:
|
||||||
hdc_disk = os.path.join(self.working_dir, "hdc_disk.qcow2")
|
hdc_disk = os.path.join(self.working_dir, "hdc_disk.qcow2")
|
||||||
if not os.path.exists(hdc_disk):
|
if not os.path.exists(hdc_disk):
|
||||||
try:
|
try:
|
||||||
@ -1272,6 +1281,8 @@ class QemuVM(BaseVM):
|
|||||||
log.info("{} returned with {}".format(qemu_img_path, retcode))
|
log.info("{} returned with {}".format(qemu_img_path, retcode))
|
||||||
except (OSError, subprocess.SubprocessError) as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
raise QemuError("Could not create hdc disk image {}".format(e))
|
raise QemuError("Could not create hdc disk image {}".format(e))
|
||||||
|
else:
|
||||||
|
hdc_disk = self._hdc_disk_image
|
||||||
options.extend(["-drive", 'file={},if={},index=2,media=disk'.format(hdc_disk, self.hdc_disk_interface)])
|
options.extend(["-drive", 'file={},if={},index=2,media=disk'.format(hdc_disk, self.hdc_disk_interface)])
|
||||||
|
|
||||||
if self._hdd_disk_image:
|
if self._hdd_disk_image:
|
||||||
@ -1280,6 +1291,7 @@ class QemuVM(BaseVM):
|
|||||||
raise QemuError("hdd disk image '{}' linked to '{}' is not accessible".format(self._hdd_disk_image, os.path.realpath(self._hdd_disk_image)))
|
raise QemuError("hdd disk image '{}' linked to '{}' is not accessible".format(self._hdd_disk_image, os.path.realpath(self._hdd_disk_image)))
|
||||||
else:
|
else:
|
||||||
raise QemuError("hdd disk image '{}' is not accessible".format(self._hdd_disk_image))
|
raise QemuError("hdd disk image '{}' is not accessible".format(self._hdd_disk_image))
|
||||||
|
if self._linked_clone:
|
||||||
hdd_disk = os.path.join(self.working_dir, "hdd_disk.qcow2")
|
hdd_disk = os.path.join(self.working_dir, "hdd_disk.qcow2")
|
||||||
if not os.path.exists(hdd_disk):
|
if not os.path.exists(hdd_disk):
|
||||||
try:
|
try:
|
||||||
@ -1290,6 +1302,8 @@ class QemuVM(BaseVM):
|
|||||||
log.info("{} returned with {}".format(qemu_img_path, retcode))
|
log.info("{} returned with {}".format(qemu_img_path, retcode))
|
||||||
except (OSError, subprocess.SubprocessError) as e:
|
except (OSError, subprocess.SubprocessError) as e:
|
||||||
raise QemuError("Could not create hdd disk image {}".format(e))
|
raise QemuError("Could not create hdd disk image {}".format(e))
|
||||||
|
else:
|
||||||
|
hdd_disk = self._hdd_disk_image
|
||||||
options.extend(["-drive", 'file={},if={},index=3,media=disk'.format(hdd_disk, self.hdd_disk_interface)])
|
options.extend(["-drive", 'file={},if={},index=3,media=disk'.format(hdd_disk, self.hdd_disk_interface)])
|
||||||
|
|
||||||
return options
|
return options
|
||||||
|
@ -38,6 +38,10 @@ QEMU_CREATE_SCHEMA = {
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 1,
|
"minLength": 1,
|
||||||
},
|
},
|
||||||
|
"linked_clone": {
|
||||||
|
"description": "either the VM is a linked clone or not",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"qemu_path": {
|
"qemu_path": {
|
||||||
"description": "Path to QEMU",
|
"description": "Path to QEMU",
|
||||||
"type": ["string", "null"],
|
"type": ["string", "null"],
|
||||||
|
Loading…
Reference in New Issue
Block a user