From c3014632a4e600b25d48eae4fde122e618b9f855 Mon Sep 17 00:00:00 2001 From: grossmj Date: Sun, 8 Mar 2015 12:32:36 -0600 Subject: [PATCH] Fixes rename bug for linked clones in VirtualBox. --- gns3server/handlers/api/config_handler.py | 2 -- gns3server/handlers/api/virtualbox_handler.py | 7 +++++-- .../modules/virtualbox/virtualbox_vm.py | 20 +++++++------------ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/gns3server/handlers/api/config_handler.py b/gns3server/handlers/api/config_handler.py index 0025731e..fc1a61d0 100644 --- a/gns3server/handlers/api/config_handler.py +++ b/gns3server/handlers/api/config_handler.py @@ -19,8 +19,6 @@ from ...web.route import Route from ...config import Config from aiohttp.web import HTTPForbidden -import asyncio - class ConfigHandler: diff --git a/gns3server/handlers/api/virtualbox_handler.py b/gns3server/handlers/api/virtualbox_handler.py index e37d9453..f8a71845 100644 --- a/gns3server/handlers/api/virtualbox_handler.py +++ b/gns3server/handlers/api/virtualbox_handler.py @@ -121,6 +121,11 @@ class VirtualBoxHandler: vbox_manager = VirtualBox.instance() vm = vbox_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"]) + if "vmname" in request.json: + vmname = request.json.pop("vmname") + if vmname != vm.vmname: + yield from vm.set_vmname(vmname) + if "enable_remote_console" in request.json: yield from vm.set_enable_remote_console(request.json.pop("enable_remote_console")) @@ -132,8 +137,6 @@ class VirtualBoxHandler: for name, value in request.json.items(): if hasattr(vm, name) and getattr(vm, name) != value: setattr(vm, name, value) - if name == "vmname": - yield from vm.rename_in_virtualbox() response.json(vm) diff --git a/gns3server/modules/virtualbox/virtualbox_vm.py b/gns3server/modules/virtualbox/virtualbox_vm.py index 801d9bb4..7eea8d12 100644 --- a/gns3server/modules/virtualbox/virtualbox_vm.py +++ b/gns3server/modules/virtualbox/virtualbox_vm.py @@ -410,33 +410,27 @@ class VirtualBoxVM(BaseVM): @property def vmname(self): """ - Returns the VM name associated with this VirtualBox VM. + Returns the VirtualBox VM name. :returns: VirtualBox VM name """ return self._vmname - @vmname.setter - def vmname(self, vmname): + @asyncio.coroutine + def set_vmname(self, vmname): """ - Sets the VM name associated with this VirtualBox VM. + Renames the VirtualBox VM. :param vmname: VirtualBox VM name """ + if self._linked_clone: + yield from self._modify_vm('--name "{}"'.format(vmname)) + log.info("VirtualBox VM '{name}' [{id}] has set the VM name to '{vmname}'".format(name=self.name, id=self.id, vmname=vmname)) self._vmname = vmname - @asyncio.coroutine - def rename_in_virtualbox(self): - """ - Renames the VirtualBox VM. - """ - - if self._linked_clone: - yield from self._modify_vm('--name "{}"'.format(self._vmname)) - @property def adapters(self): """