mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-19 12:57:56 +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:
parent
75890c8f5a
commit
14fd8104b8
@ -66,11 +66,6 @@ class VirtualBoxVM(BaseNode):
|
|||||||
self._ethernet_adapters = {}
|
self._ethernet_adapters = {}
|
||||||
self._headless = False
|
self._headless = False
|
||||||
self._acpi_shutdown = 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._vmname = vmname
|
||||||
self._use_any_adapter = False
|
self._use_any_adapter = False
|
||||||
self._ram = 0
|
self._ram = 0
|
||||||
@ -150,8 +145,37 @@ class VirtualBoxVM(BaseNode):
|
|||||||
args = shlex.split(params)
|
args = shlex.split(params)
|
||||||
yield from self.manager.execute("modifyvm", [self._vmname] + args)
|
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
|
@asyncio.coroutine
|
||||||
def create(self):
|
def create(self):
|
||||||
|
if not self.linked_clone:
|
||||||
|
yield from self._check_duplicate_linked_clone()
|
||||||
|
|
||||||
yield from self._get_system_properties()
|
yield from self._get_system_properties()
|
||||||
if "API version" not in self._system_properties:
|
if "API version" not in self._system_properties:
|
||||||
|
@ -56,11 +56,6 @@ class VMwareVM(BaseNode):
|
|||||||
self._started = False
|
self._started = False
|
||||||
self._closed = 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
|
# VMware VM settings
|
||||||
self._headless = False
|
self._headless = False
|
||||||
self._vmx_path = vmx_path
|
self._vmx_path = vmx_path
|
||||||
@ -133,11 +128,40 @@ class VMwareVM(BaseNode):
|
|||||||
return True
|
return True
|
||||||
return False
|
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
|
@asyncio.coroutine
|
||||||
def create(self):
|
def create(self):
|
||||||
"""
|
"""
|
||||||
Creates this VM and handle linked clones.
|
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()
|
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))):
|
if self.linked_clone and not os.path.exists(os.path.join(self.working_dir, os.path.basename(self._vmx_path))):
|
||||||
|
Loading…
Reference in New Issue
Block a user