1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 03:08:14 +00:00

Fix opening a project whith the same non linked VM as current project

Fix https://github.com/GNS3/gns3-gui/issues/1646
This commit is contained in:
Julien Duponchelle 2016-11-17 12:21:38 +01:00
parent 75890c8f5a
commit 14fd8104b8
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 58 additions and 10 deletions

View File

@ -66,11 +66,6 @@ class VirtualBoxVM(BaseNode):
self._ethernet_adapters = {}
self._headless = False
self._acpi_shutdown = False
if not self.linked_clone:
for node in self.manager.nodes:
if node.vmname == vmname:
raise VirtualBoxError("Sorry a node without the linked clone setting enabled can only be used once on your server. {} is already used by {}".format(vmname, node.name))
self._vmname = vmname
self._use_any_adapter = False
self._ram = 0
@ -150,8 +145,37 @@ class VirtualBoxVM(BaseNode):
args = shlex.split(params)
yield from self.manager.execute("modifyvm", [self._vmname] + args)
@asyncio.coroutine
def _check_duplicate_linked_clone(self):
"""
Without linked clone two VM using the same image can't run
at the same time.
To avoid issue like false detection when a project close
and another open we try multiple times.
"""
trial = 0
while True:
found = False
for node in self.manager.nodes:
if node != self and node.vmname == self.vmname:
found = True
if node.project != self.project:
if trial >= 30:
raise VirtualBoxError("Sorry a node without the linked clone setting enabled can only be used once on your server.\n{} is already used by {} in project {}".format(self.vmname, node.name, self.project.name))
else:
if trial >= 5:
raise VirtualBoxError("Sorry a node without the linked clone setting enabled can only be used once on your server.\n{} is already used by {} in this project".format(self.vmname, node.name))
if not found:
return
trial += 1
yield from asyncio.sleep(1)
@asyncio.coroutine
def create(self):
if not self.linked_clone:
yield from self._check_duplicate_linked_clone()
yield from self._get_system_properties()
if "API version" not in self._system_properties:

View File

@ -56,11 +56,6 @@ class VMwareVM(BaseNode):
self._started = False
self._closed = False
if not self.linked_clone:
for node in self.manager.nodes:
if node.vmx_path == vmx_path:
raise VMwareError("Sorry a node without the linked clone setting enabled can only be used once on your server. {} is already used by {}".format(vmx_path, node.name))
# VMware VM settings
self._headless = False
self._vmx_path = vmx_path
@ -133,11 +128,40 @@ class VMwareVM(BaseNode):
return True
return False
@asyncio.coroutine
def _check_duplicate_linked_clone(self):
"""
Without linked clone two VM using the same image can't run
at the same time.
To avoid issue like false detection when a project close
and another open we try multiple times.
"""
trial = 0
while True:
found = False
for node in self.manager.nodes:
if node != self and node.vmx_path == self._vmx_path:
found = True
if node.project != self.project:
if trial >= 30:
raise VMwareError("Sorry a node without the linked clone setting enabled can only be used once on your server.\n{} is already used by {} in project {}".format(self.vmx_path, node.name, self.project.name))
else:
if trial >= 5:
raise VMwareError("Sorry a node without the linked clone setting enabled can only be used once on your server.\n{} is already used by {} in this project".format(self.vmx_path, node.name))
if not found:
return
trial += 1
yield from asyncio.sleep(1)
@asyncio.coroutine
def create(self):
"""
Creates this VM and handle linked clones.
"""
if not self.linked_clone:
yield from self._check_duplicate_linked_clone()
yield from self.manager.check_vmrun_version()
if self.linked_clone and not os.path.exists(os.path.join(self.working_dir, os.path.basename(self._vmx_path))):