mirror of
https://github.com/GNS3/gns3-server
synced 2025-02-10 07:02:38 +00:00
Fix "Creating multiple IOU nodes at once assigns the same application id". Fixes #1239.
This commit is contained in:
parent
30e8949985
commit
e5e2b7a8ac
@ -1142,6 +1142,7 @@ class IOUVM(BaseNode):
|
|||||||
:returns: integer between 1 and 512
|
:returns: integer between 1 and 512
|
||||||
"""
|
"""
|
||||||
if self._application_id is None:
|
if self._application_id is None:
|
||||||
|
#FIXME: is this necessary? application ID is allocated by controller and should not be None
|
||||||
return self._manager.get_application_id(self.id)
|
return self._manager.get_application_id(self.id)
|
||||||
return self._application_id
|
return self._application_id
|
||||||
|
|
||||||
|
@ -86,6 +86,7 @@ class Project:
|
|||||||
self._show_grid = show_grid
|
self._show_grid = show_grid
|
||||||
self._show_interface_labels = show_interface_labels
|
self._show_interface_labels = show_interface_labels
|
||||||
self._loading = False
|
self._loading = False
|
||||||
|
self._add_node_lock = asyncio.Lock()
|
||||||
|
|
||||||
# Disallow overwrite of existing project
|
# Disallow overwrite of existing project
|
||||||
if project_id is None and path is not None:
|
if project_id is None and path is not None:
|
||||||
@ -438,30 +439,34 @@ class Project:
|
|||||||
if node_id in self._nodes:
|
if node_id in self._nodes:
|
||||||
return self._nodes[node_id]
|
return self._nodes[node_id]
|
||||||
|
|
||||||
if node_type == "iou" and 'application_id' not in kwargs.keys():
|
with (yield from self._add_node_lock):
|
||||||
kwargs['application_id'] = get_next_application_id(self._nodes.values())
|
# wait for a node to be completely created before adding a new one
|
||||||
|
# this is important otherwise we allocate the same application ID
|
||||||
|
# when creating multiple IOU node at the same time
|
||||||
|
if node_type == "iou" and 'application_id' not in kwargs.keys():
|
||||||
|
kwargs['application_id'] = get_next_application_id(self._nodes.values())
|
||||||
|
|
||||||
node = Node(self, compute, name, node_id=node_id, node_type=node_type, **kwargs)
|
node = Node(self, compute, name, node_id=node_id, node_type=node_type, **kwargs)
|
||||||
if compute not in self._project_created_on_compute:
|
if compute not in self._project_created_on_compute:
|
||||||
# For a local server we send the project path
|
# For a local server we send the project path
|
||||||
if compute.id == "local":
|
if compute.id == "local":
|
||||||
yield from compute.post("/projects", data={
|
yield from compute.post("/projects", data={
|
||||||
"name": self._name,
|
"name": self._name,
|
||||||
"project_id": self._id,
|
"project_id": self._id,
|
||||||
"path": self._path
|
"path": self._path
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
yield from compute.post("/projects", data={
|
yield from compute.post("/projects", data={
|
||||||
"name": self._name,
|
"name": self._name,
|
||||||
"project_id": self._id,
|
"project_id": self._id,
|
||||||
})
|
})
|
||||||
|
|
||||||
self._project_created_on_compute.add(compute)
|
self._project_created_on_compute.add(compute)
|
||||||
yield from node.create()
|
yield from node.create()
|
||||||
self._nodes[node.id] = node
|
self._nodes[node.id] = node
|
||||||
self.controller.notification.emit("node.created", node.__json__())
|
self.controller.notification.emit("node.created", node.__json__())
|
||||||
if dump:
|
if dump:
|
||||||
self.dump()
|
self.dump()
|
||||||
return node
|
return node
|
||||||
|
|
||||||
@locked_coroutine
|
@locked_coroutine
|
||||||
|
Loading…
Reference in New Issue
Block a user