1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-15 21:08:55 +00:00

Fixes nasty bug when close a cloned VirtualBox VM.

This commit is contained in:
Jeremy 2015-02-02 18:56:13 -07:00
parent 66569f26a4
commit 81f9252554
4 changed files with 18 additions and 10 deletions

View File

@ -58,11 +58,11 @@ class VirtualBoxHandler:
def create(request, response):
vbox_manager = VirtualBox.instance()
vm = yield from vbox_manager.create_vm(request.json["name"],
request.json["project_uuid"],
vm = yield from vbox_manager.create_vm(request.json.pop("name"),
request.json.pop("project_uuid"),
request.json.get("uuid"),
request.json["vmname"],
request.json["linked_clone"],
request.json.pop("vmname"),
request.json.pop("linked_clone"),
adapters=request.json.get("adapters", 0))
for name, value in request.json.items():

View File

@ -144,12 +144,12 @@ class BaseManager:
uuid = str(uuid4())
vm = self._VM_CLASS(name, uuid, project, self, *args, **kwargs)
project.add_vm(vm)
if asyncio.iscoroutinefunction(vm.create):
yield from vm.create()
else:
vm.create()
self._vms[vm.uuid] = vm
project.add_vm(vm)
return vm
@asyncio.coroutine

View File

@ -17,7 +17,6 @@
import aiohttp
import os
import tempfile
import shutil
import asyncio
from uuid import UUID, uuid4
@ -181,7 +180,7 @@ class Project:
@asyncio.coroutine
def close(self):
"""Close the project, but keep informations on disk"""
"""Close the project, but keep information on disk"""
yield from self._close_and_clean(self._temporary)
@ -194,7 +193,10 @@ class Project:
"""
for vm in self._vms:
vm.close()
if asyncio.iscoroutinefunction(vm.close):
yield from vm.close()
else:
vm.close()
if cleanup and os.path.exists(self.path):
try:
yield from wait_run_in_executor(shutil.rmtree, self.path)

View File

@ -57,6 +57,7 @@ class VirtualBoxVM(BaseVM):
self._system_properties = {}
self._telnet_server_thread = None
self._serial_pipe = None
self._closed = False
# VirtualBox settings
self._console = None
@ -322,6 +323,10 @@ class VirtualBoxVM(BaseVM):
Closes this VirtualBox VM.
"""
if self._closed:
# VM is already closed
return
self.stop()
if self._console:
@ -370,6 +375,7 @@ class VirtualBoxVM(BaseVM):
log.info("VirtualBox VM '{name}' [{uuid}] closed".format(name=self.name,
uuid=self.uuid))
self._closed = True
@property
def headless(self):
@ -697,14 +703,14 @@ class VirtualBoxVM(BaseVM):
"--register"]
result = yield from self.manager.execute("clonevm", args)
log.debug("cloned VirtualBox VM: {}".format(result))
log.debug("VirtualBox VM: {} cloned".format(result))
self._vmname = self._name
yield from self.manager.execute("setextradata", [self._vmname, "GNS3/Clone", "yes"])
args = [self._vmname, "take", "reset"]
result = yield from self.manager.execute("snapshot", args)
log.debug("Snapshot reset created: {}".format(result))
log.debug("Snapshot 'reset' created: {}".format(result))
def _start_remote_console(self):
"""