mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-05 14:51:13 +02:00
fix: keep default node naming aligned with batch submission order
The controller assigns default names (R-1, R-2, ...) and console ports in request arrival order. A parallel batch fan-out lets thread scheduling decide that order, so the first submitted node could end up as R-2. Batches that rely on default naming (any node without a name) are now created sequentially; batches with explicit names stay parallel. The node_create tool description documents the ordering semantics and tells callers to correlate nodes by node_id.
This commit is contained in:
3 files changed
+51
No files matched your search
@@ -334,6 +334,14 @@ def create_node_handler(params: dict[str, Any], gns3_ctx: dict[str, Any]) -> dic
|
||||
return {"template_id": tid, "status": "success", "node": _filter_node_response(resp, fields)}
|
||||
except Exception as e:
|
||||
return {"template_id": tid, "status": "error", "error": str(e)}
|
||||
if any(not node.get("name") for node in nodes):
|
||||
# The controller assigns default names (R-1, R-2, ...) and console
|
||||
# ports in request arrival order, and a parallel fan-out makes the
|
||||
# arrival order depend on thread scheduling. Batches that rely on
|
||||
# default naming are therefore created sequentially so those
|
||||
# server-side assignments follow the submission order; batches
|
||||
# where every node has an explicit name stay parallel.
|
||||
return [_create_one(node) for node in nodes]
|
||||
with ThreadPoolExecutor(max_workers=min(len(nodes), BATCH_MAX_WORKERS)) as pool:
|
||||
# pool.map keeps the submission order, so callers can correlate
|
||||
# results with the nodes they sent regardless of completion order
|
||||
|
||||
@@ -510,6 +510,9 @@ async def node_create(
|
||||
Single mode: provide template_id, x, y (optional compute_id)
|
||||
Batch mode: provide nodes=[{name, template_id?, x?, y?, compute_id?}] — creates up to 100 in parallel.
|
||||
Top-level template_id applies to all nodes; individual nodes can override.
|
||||
Results are always returned in submission order; correlate nodes by node_id, not name.
|
||||
When a node omits `name`, the server assigns a default name (R-1, R-2, ...) and console
|
||||
port — such batches are created sequentially so those assignments follow submission order.
|
||||
"""
|
||||
if nodes is not None:
|
||||
return await asyncio.to_thread(_run_handler_sync, create_node_handler, {
|
||||
|
||||
Reference in new issue
Block a user