Accept a node name when creating a node from a template using the API. Fixes #1708

pull/1721/head
grossmj 4 years ago
parent 688b1ac0e4
commit 0a87ee573c

@ -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"]

@ -966,6 +966,6 @@ def test_create_node_from_template(http_controller, controller, project, compute
"x": 42,
"y": 12
})
mock.assert_called_with(id, x=42, y=12, compute_id=None)
mock.assert_called_with(id, x=42, y=12, name=None, compute_id=None)
assert response.route == "/projects/{project_id}/templates/{template_id}"
assert response.status == 201

Loading…
Cancel
Save