mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-26 07:51:08 +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
|
return
|
||||||
|
|
||||||
# VM must be powered off to start it
|
# VM must be powered off to start it
|
||||||
if vm_state != "poweroff":
|
if vm_state == "saved":
|
||||||
raise VirtualBoxError("VirtualBox VM not powered off")
|
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_network_options()
|
||||||
await self._set_serial_console()
|
await self._set_serial_console()
|
||||||
|
else:
|
||||||
|
raise VirtualBoxError("VirtualBox VM not powered off")
|
||||||
|
|
||||||
# check if there is enough RAM to run
|
# check if there is enough RAM to run
|
||||||
self.check_available_ram(self.ram)
|
self.check_available_ram(self.ram)
|
||||||
@ -314,9 +320,11 @@ class VirtualBoxVM(BaseNode):
|
|||||||
await self._stop_ubridge()
|
await self._stop_ubridge()
|
||||||
await self._stop_remote_console()
|
await self._stop_remote_console()
|
||||||
vm_state = await self._get_vm_state()
|
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":
|
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")
|
result = await self._control_vm("savestate")
|
||||||
self.status = "stopped"
|
self.status = "stopped"
|
||||||
log.debug("Stop result: {}".format(result))
|
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))
|
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
|
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:
|
try:
|
||||||
# deactivate the first serial port
|
# deactivate the first serial port
|
||||||
await self._modify_vm("--uart1 off")
|
await self._modify_vm("--uart1 off")
|
||||||
|
Loading…
Reference in New Issue
Block a user