|
|
|
@ -159,7 +159,7 @@ class VirtualBoxVM(BaseVM):
|
|
|
|
|
if self.id and os.path.isdir(os.path.join(self.working_dir, self._vmname)):
|
|
|
|
|
vbox_file = os.path.join(self.working_dir, self._vmname, self._vmname + ".vbox")
|
|
|
|
|
yield from self.manager.execute("registervm", [vbox_file])
|
|
|
|
|
yield from self._reattach_hdds()
|
|
|
|
|
yield from self._reattach_linked_hdds()
|
|
|
|
|
else:
|
|
|
|
|
yield from self._create_linked_clone()
|
|
|
|
|
|
|
|
|
@ -314,7 +314,10 @@ class VirtualBoxVM(BaseVM):
|
|
|
|
|
return hdds
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
|
def _reattach_hdds(self):
|
|
|
|
|
def _reattach_linked_hdds(self):
|
|
|
|
|
"""
|
|
|
|
|
Reattach linked cloned hard disks.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
hdd_info_file = os.path.join(self.working_dir, self._vmname, "hdd_info.json")
|
|
|
|
|
try:
|
|
|
|
@ -333,37 +336,32 @@ class VirtualBoxVM(BaseVM):
|
|
|
|
|
device=hdd_info["device"],
|
|
|
|
|
medium=hdd_file))
|
|
|
|
|
|
|
|
|
|
yield from self._storage_attach('--storagectl "{}" --port {} --device {} --type hdd --medium "{}"'.format(hdd_info["controller"],
|
|
|
|
|
hdd_info["port"],
|
|
|
|
|
hdd_info["device"],
|
|
|
|
|
hdd_file))
|
|
|
|
|
try:
|
|
|
|
|
yield from self._storage_attach('--storagectl "{}" --port {} --device {} --type hdd --medium "{}"'.format(hdd_info["controller"],
|
|
|
|
|
hdd_info["port"],
|
|
|
|
|
hdd_info["device"],
|
|
|
|
|
hdd_file))
|
|
|
|
|
|
|
|
|
|
except VirtualBoxError as e:
|
|
|
|
|
log.warn("VirtualBox VM '{name}' [{id}] error reattaching HDD {controller} {port} {device} {medium}: {error}".format(name=self.name,
|
|
|
|
|
id=self.id,
|
|
|
|
|
controller=hdd_info["controller"],
|
|
|
|
|
port=hdd_info["port"],
|
|
|
|
|
device=hdd_info["device"],
|
|
|
|
|
medium=hdd_file,
|
|
|
|
|
error=e))
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
|
def close(self):
|
|
|
|
|
def save_linked_hdds_info(self):
|
|
|
|
|
"""
|
|
|
|
|
Closes this VirtualBox VM.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
if self._closed:
|
|
|
|
|
# VM is already closed
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
log.debug("VirtualBox VM '{name}' [{id}] is closing".format(name=self.name, id=self.id))
|
|
|
|
|
if self._console:
|
|
|
|
|
self._manager.port_manager.release_tcp_port(self._console, self._project)
|
|
|
|
|
self._console = None
|
|
|
|
|
Save linked cloned hard disks information.
|
|
|
|
|
|
|
|
|
|
for adapter in self._ethernet_adapters.values():
|
|
|
|
|
if adapter is not None:
|
|
|
|
|
for nio in adapter.ports.values():
|
|
|
|
|
if nio and isinstance(nio, NIOUDP):
|
|
|
|
|
self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
|
|
|
|
|
|
|
|
|
self.acpi_shutdown = False
|
|
|
|
|
yield from self.stop()
|
|
|
|
|
:returns: disk table information
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
hdd_table = []
|
|
|
|
|
if self._linked_clone:
|
|
|
|
|
hdd_table = []
|
|
|
|
|
if os.path.exists(self.working_dir):
|
|
|
|
|
hdd_files = yield from self._get_all_hdd_files()
|
|
|
|
|
vm_info = yield from self._get_vm_info()
|
|
|
|
@ -379,9 +377,6 @@ class VirtualBoxVM(BaseVM):
|
|
|
|
|
controller=controller,
|
|
|
|
|
port=port,
|
|
|
|
|
device=device))
|
|
|
|
|
yield from self._storage_attach('--storagectl "{}" --port {} --device {} --type hdd --medium none'.format(controller,
|
|
|
|
|
port,
|
|
|
|
|
device))
|
|
|
|
|
hdd_table.append(
|
|
|
|
|
{
|
|
|
|
|
"hdd": os.path.basename(value),
|
|
|
|
@ -391,9 +386,6 @@ class VirtualBoxVM(BaseVM):
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
log.info("VirtualBox VM '{name}' [{id}] unregistering".format(name=self.name, id=self.id))
|
|
|
|
|
yield from self.manager.execute("unregistervm", [self._name])
|
|
|
|
|
|
|
|
|
|
if hdd_table:
|
|
|
|
|
try:
|
|
|
|
|
hdd_info_file = os.path.join(self.working_dir, self._vmname, "hdd_info.json")
|
|
|
|
@ -404,6 +396,56 @@ class VirtualBoxVM(BaseVM):
|
|
|
|
|
id=self.id,
|
|
|
|
|
error=e.strerror))
|
|
|
|
|
|
|
|
|
|
return hdd_table
|
|
|
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
|
def close(self):
|
|
|
|
|
"""
|
|
|
|
|
Closes this VirtualBox VM.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
if self._closed:
|
|
|
|
|
# VM is already closed
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
log.debug("VirtualBox VM '{name}' [{id}] is closing".format(name=self.name, id=self.id))
|
|
|
|
|
if self._console:
|
|
|
|
|
self._manager.port_manager.release_tcp_port(self._console, self._project)
|
|
|
|
|
self._console = None
|
|
|
|
|
|
|
|
|
|
for adapter in self._ethernet_adapters.values():
|
|
|
|
|
if adapter is not None:
|
|
|
|
|
for nio in adapter.ports.values():
|
|
|
|
|
if nio and isinstance(nio, NIOUDP):
|
|
|
|
|
self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
|
|
|
|
|
|
|
|
|
self.acpi_shutdown = False
|
|
|
|
|
yield from self.stop()
|
|
|
|
|
|
|
|
|
|
if self._linked_clone:
|
|
|
|
|
hdd_table = yield from self.save_linked_hdds_info()
|
|
|
|
|
for hdd in hdd_table.copy():
|
|
|
|
|
log.info("VirtualBox VM '{name}' [{id}] detaching HDD {controller} {port} {device}".format(name=self.name,
|
|
|
|
|
id=self.id,
|
|
|
|
|
controller=hdd["controller"],
|
|
|
|
|
port=hdd["port"],
|
|
|
|
|
device=hdd["device"]))
|
|
|
|
|
try:
|
|
|
|
|
yield from self._storage_attach('--storagectl "{}" --port {} --device {} --type hdd --medium none'.format(hdd["controller"],
|
|
|
|
|
hdd["port"],
|
|
|
|
|
hdd["device"]))
|
|
|
|
|
except VirtualBoxError as e:
|
|
|
|
|
log.warn("VirtualBox VM '{name}' [{id}] error detaching HDD {controller} {port} {device}: {error}".format(name=self.name,
|
|
|
|
|
id=self.id,
|
|
|
|
|
controller=hdd["controller"],
|
|
|
|
|
port=hdd["port"],
|
|
|
|
|
device=hdd["device"],
|
|
|
|
|
error=e))
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
log.info("VirtualBox VM '{name}' [{id}] unregistering".format(name=self.name, id=self.id))
|
|
|
|
|
yield from self.manager.execute("unregistervm", [self._name])
|
|
|
|
|
|
|
|
|
|
log.info("VirtualBox VM '{name}' [{id}] closed".format(name=self.name, id=self.id))
|
|
|
|
|
self._closed = True
|
|
|
|
|
|
|
|
|
|