mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Accept a node name when creating a node from a template using the API. Fixes #1708
This commit is contained in:
1 parent
688b1ac0e4
commit
0a87ee573c
3 files changed
+9
-4
No files matched your search
@@ -490,7 +490,7 @@ class Project:
|
||||
return new_name
|
||||
|
||||
@open_required
|
||||
async def add_node_from_template(self, template_id, x=0, y=0, compute_id=None):
|
||||
async def add_node_from_template(self, template_id, x=0, y=0, name=None, compute_id=None):
|
||||
"""
|
||||
Create a node from a template.
|
||||
"""
|
||||
@@ -508,9 +508,10 @@ class Project:
|
||||
compute = self.controller.get_compute(compute_id)
|
||||
else:
|
||||
compute = self.controller.get_compute(template.pop("compute_id", compute_id))
|
||||
name = template.pop("name")
|
||||
template_name = template.pop("name")
|
||||
default_name_format = template.pop("default_name_format", "{name}-{0}")
|
||||
name = default_name_format.replace("{name}", name)
|
||||
if name is None:
|
||||
name = default_name_format.replace("{name}", template_name)
|
||||
node_id = str(uuid.uuid4())
|
||||
node = await self.add_node(compute, name, node_id, node_type=node_type, **template)
|
||||
return node
|
||||
|
||||
@@ -97,6 +97,10 @@ TEMPLATE_USAGE_SCHEMA = {
|
||||
"description": "Y position",
|
||||
"type": "integer"
|
||||
},
|
||||
"name": {
|
||||
"description": "Use this name to create a new node",
|
||||
"type": ["null", "string"]
|
||||
},
|
||||
"compute_id": {
|
||||
"description": "If the template don't have a default compute use this compute",
|
||||
"type": ["null", "string"]
|
||||
|
||||
Reference in new issue
Block a user