mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-11 16:41:04 +00:00
ACPI shutdown support for VirtualBox VMs.
This commit is contained in:
parent
edff447483
commit
933bc5a7b0
@ -65,6 +65,7 @@ class VirtualBoxVM(BaseVM):
|
|||||||
self._adapters = adapters
|
self._adapters = adapters
|
||||||
self._ethernet_adapters = {}
|
self._ethernet_adapters = {}
|
||||||
self._headless = False
|
self._headless = False
|
||||||
|
self._acpi_shutdown = False
|
||||||
self._enable_remote_console = False
|
self._enable_remote_console = False
|
||||||
self._vmname = vmname
|
self._vmname = vmname
|
||||||
self._use_any_adapter = False
|
self._use_any_adapter = False
|
||||||
@ -79,6 +80,7 @@ class VirtualBoxVM(BaseVM):
|
|||||||
"project_id": self.project.id,
|
"project_id": self.project.id,
|
||||||
"vmname": self.vmname,
|
"vmname": self.vmname,
|
||||||
"headless": self.headless,
|
"headless": self.headless,
|
||||||
|
"acpi_shutdown": self.acpi_shutdown,
|
||||||
"enable_remote_console": self.enable_remote_console,
|
"enable_remote_console": self.enable_remote_console,
|
||||||
"adapters": self._adapters,
|
"adapters": self._adapters,
|
||||||
"adapter_type": self.adapter_type,
|
"adapter_type": self.adapter_type,
|
||||||
@ -205,11 +207,16 @@ class VirtualBoxVM(BaseVM):
|
|||||||
self._stop_remote_console()
|
self._stop_remote_console()
|
||||||
vm_state = yield from self._get_vm_state()
|
vm_state = yield from self._get_vm_state()
|
||||||
if vm_state == "running" or vm_state == "paused" or vm_state == "stuck":
|
if vm_state == "running" or vm_state == "paused" or vm_state == "stuck":
|
||||||
# power off the VM
|
if self.acpi_shutdown:
|
||||||
result = yield from self._control_vm("poweroff")
|
# use ACPI to shutdown the VM
|
||||||
log.info("VirtualBox VM '{name}' [{id}] stopped".format(name=self.name, id=self.id))
|
result = yield from self._control_vm("acpipowerbutton")
|
||||||
log.debug("Stop result: {}".format(result))
|
log.debug("ACPI shutdown result: {}".format(result))
|
||||||
|
else:
|
||||||
|
# power off the VM
|
||||||
|
result = yield from self._control_vm("poweroff")
|
||||||
|
log.debug("Stop result: {}".format(result))
|
||||||
|
|
||||||
|
log.info("VirtualBox VM '{name}' [{id}] stopped".format(name=self.name, id=self.id))
|
||||||
# yield from asyncio.sleep(0.5) # give some time for VirtualBox to unlock the VM
|
# yield from asyncio.sleep(0.5) # give some time for VirtualBox to unlock the VM
|
||||||
try:
|
try:
|
||||||
# deactivate the first serial port
|
# deactivate the first serial port
|
||||||
@ -389,6 +396,30 @@ class VirtualBoxVM(BaseVM):
|
|||||||
log.info("VirtualBox VM '{name}' [{id}] has disabled the headless mode".format(name=self.name, id=self.id))
|
log.info("VirtualBox VM '{name}' [{id}] has disabled the headless mode".format(name=self.name, id=self.id))
|
||||||
self._headless = headless
|
self._headless = headless
|
||||||
|
|
||||||
|
@property
|
||||||
|
def acpi_shutdown(self):
|
||||||
|
"""
|
||||||
|
Returns either the VM will use ACPI shutdown
|
||||||
|
|
||||||
|
:returns: boolean
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self._acpi_shutdown
|
||||||
|
|
||||||
|
@acpi_shutdown.setter
|
||||||
|
def acpi_shutdown(self, acpi_shutdown):
|
||||||
|
"""
|
||||||
|
Sets either the VM will use ACPI shutdown
|
||||||
|
|
||||||
|
:param acpi_shutdown: boolean
|
||||||
|
"""
|
||||||
|
|
||||||
|
if acpi_shutdown:
|
||||||
|
log.info("VirtualBox VM '{name}' [{id}] has enabled the ACPI shutdown mode".format(name=self.name, id=self.id))
|
||||||
|
else:
|
||||||
|
log.info("VirtualBox VM '{name}' [{id}] has disabled the ACPI shutdown mode".format(name=self.name, id=self.id))
|
||||||
|
self._acpi_shutdown = acpi_shutdown
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def enable_remote_console(self):
|
def enable_remote_console(self):
|
||||||
"""
|
"""
|
||||||
|
@ -80,6 +80,10 @@ VBOX_CREATE_SCHEMA = {
|
|||||||
"description": "headless mode",
|
"description": "headless mode",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"acpi_shutdown": {
|
||||||
|
"description": "ACPI shutdown",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"required": ["name", "vmname", "linked_clone"],
|
"required": ["name", "vmname", "linked_clone"],
|
||||||
@ -135,6 +139,10 @@ VBOX_UPDATE_SCHEMA = {
|
|||||||
"description": "headless mode",
|
"description": "headless mode",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"acpi_shutdown": {
|
||||||
|
"description": "ACPI shutdown",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
}
|
}
|
||||||
@ -191,6 +199,10 @@ VBOX_OBJECT_SCHEMA = {
|
|||||||
"description": "headless mode",
|
"description": "headless mode",
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"acpi_shutdown": {
|
||||||
|
"description": "ACPI shutdown",
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"adapters": {
|
"adapters": {
|
||||||
"description": "number of adapters",
|
"description": "number of adapters",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
Loading…
Reference in New Issue
Block a user