Save state feature for VirtualBox and VMware. New "On close" setting to

select the action to execute when closing/stopping a Qemu/VirtualBox/VMware VM.
This commit is contained in:
grossmj committed 2018-03-30 21:18:44 +07:00
1 parent 3d1ee4da3f
commit ea0009db6c
9 files changed
+100 -112

No files matched your search

+16 -44
View File
@@ -116,8 +116,7 @@ class QemuVM(BaseNode):
self._kernel_image = ""
self._kernel_command_line = ""
self._legacy_networking = False
self._acpi_shutdown = False
self._save_vm_state = False
self._on_close = "power_off"
self._cpu_throttling = 0 # means no CPU throttling
self._process_priority = "low"
@@ -573,52 +572,25 @@ class QemuVM(BaseNode):
self._legacy_networking = legacy_networking
@property
def acpi_shutdown(self):
def on_close(self):
"""
Returns either this QEMU VM can be ACPI shutdown.
Returns the action to execute when the VM is stopped/closed
:returns: boolean
:returns: string
"""
return self._acpi_shutdown
return self._on_close
@acpi_shutdown.setter
def acpi_shutdown(self, acpi_shutdown):
@on_close.setter
def on_close(self, on_close):
"""
Sets either this QEMU VM can be ACPI shutdown.
Sets the action to execute when the VM is stopped/closed
:param acpi_shutdown: boolean
:param on_close: string
"""
if acpi_shutdown:
log.info('QEMU VM "{name}" [{id}] has enabled ACPI shutdown'.format(name=self._name, id=self._id))
else:
log.info('QEMU VM "{name}" [{id}] has disabled ACPI shutdown'.format(name=self._name, id=self._id))
self._acpi_shutdown = acpi_shutdown
@property
def save_vm_state(self):
"""
Returns either this QEMU VM state can be saved.
:returns: boolean
"""
return self._save_vm_state
@save_vm_state.setter
def save_vm_state(self, save_vm_state):
"""
Sets either this QEMU VM state can be saved.
:param save_vm_state: boolean
"""
if save_vm_state:
log.info('QEMU VM "{name}" [{id}] has enabled the save VM state option'.format(name=self._name, id=self._id))
else:
log.info('QEMU VM "{name}" [{id}] has disabled the save VM state option'.format(name=self._name, id=self._id))
self._save_vm_state = save_vm_state
log.info('QEMU VM "{name}" [{id}] set the close action to "{action}"'.format(name=self._name, id=self._id, action=on_close))
self._on_close = on_close
@property
def cpu_throttling(self):
@@ -1030,7 +1002,7 @@ class QemuVM(BaseNode):
log.info('Stopping QEMU VM "{}" PID={}'.format(self._name, self._process.pid))
try:
if self.save_vm_state:
if self.on_close == "save_vm_state":
yield from self._control_vm("stop")
yield from self._control_vm("savevm GNS3_SAVED_STATE")
wait_for_savevm = 120
@@ -1041,7 +1013,7 @@ class QemuVM(BaseNode):
if status != []:
break
if self.acpi_shutdown and not self.save_vm_state:
if self.on_close == "shutdown_signal":
yield from self._control_vm("system_powerdown")
yield from gns3server.utils.asyncio.wait_for_process_termination(self._process, timeout=30)
else:
@@ -1059,7 +1031,7 @@ class QemuVM(BaseNode):
log.warning('QEMU VM "{}" PID={} is still running'.format(self._name, self._process.pid))
self._process = None
self._stop_cpulimit()
if not self.save_vm_state:
if self.on_close != "save_vm_state":
yield from self._clear_save_vm_stated()
yield from super().stop()
@@ -1164,7 +1136,7 @@ class QemuVM(BaseNode):
if not (yield from super().close()):
return False
self.acpi_shutdown = False
self.on_close = "power_off"
yield from self.stop()
for adapter in self._ethernet_adapters:
@@ -1951,7 +1923,7 @@ class QemuVM(BaseNode):
command.extend(self._monitor_options())
command.extend((yield from self._network_options()))
command.extend(self._graphic())
if not self.save_vm_state:
if self.on_close != "save_vm_state":
yield from self._clear_save_vm_stated()
else:
command.extend((yield from self._saved_state_option()))
+19 -17
View File
@@ -66,7 +66,7 @@ class VirtualBoxVM(BaseNode):
self._adapters = adapters
self._ethernet_adapters = {}
self._headless = False
self._acpi_shutdown = False
self._on_close = "power_off"
self._vmname = vmname
self._use_any_adapter = False
self._ram = 0
@@ -81,7 +81,7 @@ class VirtualBoxVM(BaseNode):
"project_id": self.project.id,
"vmname": self.vmname,
"headless": self.headless,
"acpi_shutdown": self.acpi_shutdown,
"on_close": self.on_close,
"adapters": self._adapters,
"adapter_type": self.adapter_type,
"ram": self.ram,
@@ -307,7 +307,12 @@ class VirtualBoxVM(BaseNode):
yield from self._stop_remote_console()
vm_state = yield from self._get_vm_state()
if vm_state == "running" or vm_state == "paused" or vm_state == "stuck":
if self.acpi_shutdown:
if self.on_close == "save_vm_state":
result = yield from self._control_vm("savestate")
self.status = "stopped"
log.debug("Stop result: {}".format(result))
elif self.on_close == "shutdown_signal":
# use ACPI to shutdown the VM
result = yield from self._control_vm("acpipowerbutton")
trial = 0
@@ -509,7 +514,7 @@ class VirtualBoxVM(BaseNode):
self.manager.port_manager.release_udp_port(udp_tunnel[1].lport, self._project)
self._local_udp_tunnels = {}
self.acpi_shutdown = False
self.on_close = "power_off"
yield from self.stop()
if self.linked_clone:
@@ -564,28 +569,25 @@ class VirtualBoxVM(BaseNode):
self._headless = headless
@property
def acpi_shutdown(self):
def on_close(self):
"""
Returns either the VM will use ACPI shutdown
Returns the action to execute when the VM is stopped/closed
:returns: boolean
:returns: string
"""
return self._acpi_shutdown
return self._on_close
@acpi_shutdown.setter
def acpi_shutdown(self, acpi_shutdown):
@on_close.setter
def on_close(self, on_close):
"""
Sets either the VM will use ACPI shutdown
Sets the action to execute when the VM is stopped/closed
:param acpi_shutdown: boolean
:param on_close: string
"""
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
log.info('VirtualBox VM "{name}" [{id}] set the close action to "{action}"'.format(name=self._name, id=self._id, action=on_close))
self._on_close = on_close
@property
def ram(self):
+16 -17
View File
@@ -58,7 +58,7 @@ class VMwareVM(BaseNode):
# VMware VM settings
self._headless = False
self._vmx_path = vmx_path
self._acpi_shutdown = False
self._on_close = "power_off"
self._adapters = 0
self._ethernet_adapters = {}
self._adapter_type = "e1000"
@@ -80,7 +80,7 @@ class VMwareVM(BaseNode):
"project_id": self.project.id,
"vmx_path": self.vmx_path,
"headless": self.headless,
"acpi_shutdown": self.acpi_shutdown,
"on_close": self.on_close,
"adapters": self._adapters,
"adapter_type": self.adapter_type,
"use_any_adapter": self.use_any_adapter,
@@ -482,7 +482,9 @@ class VMwareVM(BaseNode):
try:
if (yield from self.is_running()):
if self.acpi_shutdown:
if self.on_close == "save_vm_state":
yield from self._control_vm("suspend")
elif self.on_close == "shutdown_signal":
# use ACPI to shutdown the VM
yield from self._control_vm("stop", "soft")
else:
@@ -563,7 +565,7 @@ class VMwareVM(BaseNode):
if nio and isinstance(nio, NIOUDP):
self.manager.port_manager.release_udp_port(nio.lport, self._project)
try:
self.acpi_shutdown = False
self.on_close = "power_off"
yield from self.stop()
except VMwareError:
pass
@@ -596,28 +598,25 @@ class VMwareVM(BaseNode):
self._headless = headless
@property
def acpi_shutdown(self):
def on_close(self):
"""
Returns either the VM will use ACPI shutdown
Returns the action to execute when the VM is stopped/closed
:returns: boolean
:returns: string
"""
return self._acpi_shutdown
return self._on_close
@acpi_shutdown.setter
def acpi_shutdown(self, acpi_shutdown):
@on_close.setter
def on_close(self, on_close):
"""
Sets either the VM will use ACPI shutdown
Sets the action to execute when the VM is stopped/closed
:param acpi_shutdown: boolean
:param on_close: string
"""
if acpi_shutdown:
log.info("VMware VM '{name}' [{id}] has enabled the ACPI shutdown mode".format(name=self.name, id=self.id))
else:
log.info("VMware VM '{name}' [{id}] has disabled the ACPI shutdown mode".format(name=self.name, id=self.id))
self._acpi_shutdown = acpi_shutdown
log.info('VMware VM "{name}" [{id}] set the close action to "{action}"'.format(name=self._name, id=self._id, action=on_close))
self._on_close = on_close
@property
def vmx_path(self):