mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Prevent corruption of VM in VirtualBox when using linked clone
Fix https://github.com/GNS3/gns3-gui/issues/1821
This commit is contained in:
4 files changed
+37
-10
No files matched your search
@@ -161,7 +161,7 @@ class VirtualBox(BaseManager):
|
||||
continue
|
||||
|
||||
@asyncio.coroutine
|
||||
def list_vms(self):
|
||||
def list_vms(self, allow_clone=False):
|
||||
"""
|
||||
Gets VirtualBox VM list.
|
||||
"""
|
||||
@@ -176,7 +176,7 @@ class VirtualBox(BaseManager):
|
||||
if vmname == "<inaccessible>":
|
||||
continue # ignore inaccessible VMs
|
||||
extra_data = yield from self.execute("getextradata", [vmname, "GNS3/Clone"])
|
||||
if len(extra_data) == 0 or not extra_data[0].strip() == "Value: yes":
|
||||
if allow_clone or len(extra_data) == 0 or not extra_data[0].strip() == "Value: yes":
|
||||
# get the amount of RAM
|
||||
info_results = yield from self.execute("showvminfo", [vmname, "--machinereadable"])
|
||||
ram = 0
|
||||
|
||||
@@ -603,9 +603,16 @@ class VirtualBoxVM(BaseNode):
|
||||
:param vmname: VirtualBox VM name
|
||||
"""
|
||||
|
||||
if vmname == self._vmname:
|
||||
return
|
||||
|
||||
if self.linked_clone:
|
||||
if self.status == "started":
|
||||
raise VirtualBoxError("You can't change the name of running VM {}".format(self._name))
|
||||
# We can't rename a VM to name that already exists
|
||||
vms = yield from self.manager.list_vms(allow_clone=True)
|
||||
if vmname in [vm["vmname"] for vm in vms]:
|
||||
raise VirtualBoxError("You can't change the name to {} it's already use in VirtualBox".format(vmname))
|
||||
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))
|
||||
|
||||
@@ -112,10 +112,13 @@ class VirtualBoxHandler:
|
||||
vbox_manager = VirtualBox.instance()
|
||||
vm = vbox_manager.get_node(request.match_info["node_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 "name" in request.json:
|
||||
name = request.json.pop("name")
|
||||
vmname = request.json.pop("vmname", None)
|
||||
if name != vm.name:
|
||||
vm.name = name
|
||||
if vm.linked_clone:
|
||||
yield from vm.set_vmname(vm.name)
|
||||
|
||||
if "adapters" in request.json:
|
||||
adapters = int(request.json.pop("adapters"))
|
||||
|
||||
Reference in new issue
Block a user