mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-12 09:00:57 +00:00
Implement full restart if user reload a Qemu VM which has been updated. Fixes https://github.com/GNS3/gns3-gui/issues/3038
This commit is contained in:
parent
90ecefd455
commit
992cd7fc6c
@ -81,12 +81,13 @@ class QemuVM(BaseNode):
|
|||||||
self._execute_lock = asyncio.Lock()
|
self._execute_lock = asyncio.Lock()
|
||||||
self._local_udp_tunnels = {}
|
self._local_udp_tunnels = {}
|
||||||
self._guest_cid = None
|
self._guest_cid = None
|
||||||
|
self._command_line_changed = False
|
||||||
|
|
||||||
# QEMU VM settings
|
# QEMU VM settings
|
||||||
if qemu_path:
|
if qemu_path:
|
||||||
try:
|
try:
|
||||||
self.qemu_path = qemu_path
|
self.qemu_path = qemu_path
|
||||||
except QemuError as e:
|
except QemuError:
|
||||||
# If the binary is not found for topologies 1.4 and later
|
# If the binary is not found for topologies 1.4 and later
|
||||||
# search via the platform otherwise use the binary name
|
# search via the platform otherwise use the binary name
|
||||||
if platform:
|
if platform:
|
||||||
@ -444,7 +445,18 @@ class QemuVM(BaseNode):
|
|||||||
else:
|
else:
|
||||||
self._cdrom_image = ""
|
self._cdrom_image = ""
|
||||||
|
|
||||||
async def update_cdrom_image(self):
|
async def update(self, name, value):
|
||||||
|
"""
|
||||||
|
Update Qemu VM properties.
|
||||||
|
"""
|
||||||
|
|
||||||
|
setattr(self, name, value)
|
||||||
|
if name == "cdrom_image":
|
||||||
|
# let the guest know about the new cdrom image
|
||||||
|
await self._update_cdrom_image()
|
||||||
|
self._command_line_changed = True
|
||||||
|
|
||||||
|
async def _update_cdrom_image(self):
|
||||||
"""
|
"""
|
||||||
Update the cdrom image path for the Qemu guest OS
|
Update the cdrom image path for the Qemu guest OS
|
||||||
"""
|
"""
|
||||||
@ -1007,6 +1019,7 @@ class QemuVM(BaseNode):
|
|||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
cwd=self.working_dir)
|
cwd=self.working_dir)
|
||||||
log.info('QEMU VM "{}" started PID={}'.format(self._name, self._process.pid))
|
log.info('QEMU VM "{}" started PID={}'.format(self._name, self._process.pid))
|
||||||
|
self._command_line_changed = False
|
||||||
self.status = "started"
|
self.status = "started"
|
||||||
monitor_process(self._process, self._termination_callback)
|
monitor_process(self._process, self._termination_callback)
|
||||||
except (OSError, subprocess.SubprocessError, UnicodeEncodeError) as e:
|
except (OSError, subprocess.SubprocessError, UnicodeEncodeError) as e:
|
||||||
@ -1282,7 +1295,11 @@ class QemuVM(BaseNode):
|
|||||||
Reloads this QEMU VM.
|
Reloads this QEMU VM.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
await self._control_vm("system_reset")
|
if self._command_line_changed:
|
||||||
|
await self.stop()
|
||||||
|
await self.start()
|
||||||
|
else:
|
||||||
|
await self._control_vm("system_reset")
|
||||||
log.debug("QEMU VM has been reset")
|
log.debug("QEMU VM has been reset")
|
||||||
|
|
||||||
async def resume(self):
|
async def resume(self):
|
||||||
@ -2015,7 +2032,7 @@ class QemuVM(BaseNode):
|
|||||||
command.extend(["-name", self._name])
|
command.extend(["-name", self._name])
|
||||||
command.extend(["-m", "{}M".format(self._ram)])
|
command.extend(["-m", "{}M".format(self._ram)])
|
||||||
command.extend(["-smp", "cpus={}".format(self._cpus)])
|
command.extend(["-smp", "cpus={}".format(self._cpus)])
|
||||||
if (await self._run_with_hardware_acceleration(self.qemu_path, self._options)):
|
if await self._run_with_hardware_acceleration(self.qemu_path, self._options):
|
||||||
if sys.platform.startswith("linux"):
|
if sys.platform.startswith("linux"):
|
||||||
command.extend(["-enable-kvm"])
|
command.extend(["-enable-kvm"])
|
||||||
version = await self.manager.get_qemu_version(self.qemu_path)
|
version = await self.manager.get_qemu_version(self.qemu_path)
|
||||||
|
@ -124,11 +124,7 @@ class QEMUHandler:
|
|||||||
vm.console = request.json.pop("console", vm.console)
|
vm.console = request.json.pop("console", vm.console)
|
||||||
for name, value in request.json.items():
|
for name, value in request.json.items():
|
||||||
if hasattr(vm, name) and getattr(vm, name) != value:
|
if hasattr(vm, name) and getattr(vm, name) != value:
|
||||||
setattr(vm, name, value)
|
await vm.update(name, value)
|
||||||
if name == "cdrom_image":
|
|
||||||
# let the guest know about the new cdrom image
|
|
||||||
await vm.update_cdrom_image()
|
|
||||||
|
|
||||||
vm.updated()
|
vm.updated()
|
||||||
response.json(vm)
|
response.json(vm)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user