Fix duplicate node names

Fix https://github.com/GNS3/gns3-gui/issues/1796
pull/874/head
Julien Duponchelle 7 years ago
parent e5dba5e66a
commit d74769c824
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8

@ -286,7 +286,6 @@ class Project:
if base_name is None:
return None
base_name = re.sub(r"[ ]", "", base_name)
self.remove_allocated_node_name(base_name)
if '{0}' in base_name or '{id}' in base_name:
# base name is a template, replace {0} or {id} by an unique identifier
for number in range(1, 1000000):
@ -306,22 +305,10 @@ class Project:
return name
raise aiohttp.web.HTTPConflict(text="A node name could not be allocated (node limit reached?)")
def has_allocated_node_name(self, name):
"""
Returns either a node name is already allocated or not.
:param name: node name
:returns: boolean
"""
if name in self._allocated_node_names:
return True
return False
def update_node_name(self, node, new_name):
if new_name and node.name != new_name:
self.remove_allocated_node_name(node.name)
return self.update_allocated_node_name(new_name)
return new_name

@ -76,6 +76,10 @@ def test_name(compute, project):
properties={"startup_script": "echo test"})
assert node.name == "PC2"
# If we change the name to a name already used we patch the name to a free
node.name == "PC1"
assert node.name == "PC2"
def test_eq(compute, project, node, controller):
assert node == Node(project, compute, "demo1", node_id=node.id, node_type="qemu")

Loading…
Cancel
Save