mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 09:18:08 +00:00
Fix duplicate node names
Fix https://github.com/GNS3/gns3-gui/issues/1796
This commit is contained in:
parent
e5dba5e66a
commit
d74769c824
@ -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…
Reference in New Issue
Block a user