From 81f92525547af9cf22dc24c4ee5506b04c705573 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 2 Feb 2015 18:56:13 -0700 Subject: [PATCH] Fixes nasty bug when close a cloned VirtualBox VM. --- gns3server/handlers/virtualbox_handler.py | 8 ++++---- gns3server/modules/base_manager.py | 2 +- gns3server/modules/project.py | 8 +++++--- gns3server/modules/virtualbox/virtualbox_vm.py | 10 ++++++++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/gns3server/handlers/virtualbox_handler.py b/gns3server/handlers/virtualbox_handler.py index ef074d51..dfb8da7a 100644 --- a/gns3server/handlers/virtualbox_handler.py +++ b/gns3server/handlers/virtualbox_handler.py @@ -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(): diff --git a/gns3server/modules/base_manager.py b/gns3server/modules/base_manager.py index 8fb3772a..c2efd9dc 100644 --- a/gns3server/modules/base_manager.py +++ b/gns3server/modules/base_manager.py @@ -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 diff --git a/gns3server/modules/project.py b/gns3server/modules/project.py index afd6c271..d385f143 100644 --- a/gns3server/modules/project.py +++ b/gns3server/modules/project.py @@ -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) diff --git a/gns3server/modules/virtualbox/virtualbox_vm.py b/gns3server/modules/virtualbox/virtualbox_vm.py index 462d846c..fd8242e2 100644 --- a/gns3server/modules/virtualbox/virtualbox_vm.py +++ b/gns3server/modules/virtualbox/virtualbox_vm.py @@ -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): """