mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-25 23:41:07 +00:00
Fix cannot power on VirtualBox VM in saved state. Ref #1702
This commit is contained in:
parent
060871cc42
commit
50b507f76c
@ -269,11 +269,17 @@ class VirtualBoxVM(BaseNode):
|
||||
return
|
||||
|
||||
# VM must be powered off to start it
|
||||
if vm_state != "poweroff":
|
||||
raise VirtualBoxError("VirtualBox VM not powered off")
|
||||
|
||||
if vm_state == "saved":
|
||||
result = await self.manager.execute("guestproperty", ["get", self._uuid, "SavedByGNS3"])
|
||||
if result == ['No value set!']:
|
||||
raise VirtualBoxError("VirtualBox VM was not saved from GNS3")
|
||||
else:
|
||||
await self.manager.execute("guestproperty", ["delete", self._uuid, "SavedByGNS3"])
|
||||
elif vm_state == "poweroff":
|
||||
await self._set_network_options()
|
||||
await self._set_serial_console()
|
||||
else:
|
||||
raise VirtualBoxError("VirtualBox VM not powered off")
|
||||
|
||||
# check if there is enough RAM to run
|
||||
self.check_available_ram(self.ram)
|
||||
@ -314,9 +320,11 @@ class VirtualBoxVM(BaseNode):
|
||||
await self._stop_ubridge()
|
||||
await self._stop_remote_console()
|
||||
vm_state = await self._get_vm_state()
|
||||
if vm_state == "running" or vm_state == "paused" or vm_state == "stuck":
|
||||
if vm_state in ("running", "paused", "stuck"):
|
||||
|
||||
if self.on_close == "save_vm_state":
|
||||
# add a guest property to know the VM has been saved
|
||||
await self.manager.execute("guestproperty", ["set", self._uuid, "SavedByGNS3", "yes"])
|
||||
result = await self._control_vm("savestate")
|
||||
self.status = "stopped"
|
||||
log.debug("Stop result: {}".format(result))
|
||||
@ -343,6 +351,8 @@ class VirtualBoxVM(BaseNode):
|
||||
|
||||
log.info("VirtualBox VM '{name}' [{id}] stopped".format(name=self.name, id=self.id))
|
||||
await asyncio.sleep(0.5) # give some time for VirtualBox to unlock the VM
|
||||
if self.on_close != "save_vm_state":
|
||||
# do some cleaning when the VM is powered off
|
||||
try:
|
||||
# deactivate the first serial port
|
||||
await self._modify_vm("--uart1 off")
|
||||
|
Loading…
Reference in New Issue
Block a user