|
|
|
@ -48,6 +48,8 @@ from gns3server.utils.asyncio import aiozipstream
|
|
|
|
|
from gns3server.utils.path import is_safe_path
|
|
|
|
|
from gns3server.config import Config
|
|
|
|
|
from gns3server.db.repositories.rbac import RbacRepository
|
|
|
|
|
from gns3server.db.repositories.templates import TemplatesRepository
|
|
|
|
|
from gns3server.services.templates import TemplatesService
|
|
|
|
|
|
|
|
|
|
from .dependencies.authentication import get_current_active_user
|
|
|
|
|
from .dependencies.database import get_repository
|
|
|
|
@ -437,3 +439,28 @@ async def write_file(file_path: str, request: Request, project: Project = Depend
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED)
|
|
|
|
|
except OSError as e:
|
|
|
|
|
raise ControllerError(str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.post(
|
|
|
|
|
"/{project_id}/templates/{template_id}",
|
|
|
|
|
response_model=schemas.Node,
|
|
|
|
|
status_code=status.HTTP_201_CREATED,
|
|
|
|
|
responses={404: {"model": schemas.ErrorMessage, "description": "Could not find project or template"}},
|
|
|
|
|
)
|
|
|
|
|
async def create_node_from_template(
|
|
|
|
|
project_id: UUID,
|
|
|
|
|
template_id: UUID,
|
|
|
|
|
template_usage: schemas.TemplateUsage,
|
|
|
|
|
templates_repo: TemplatesRepository = Depends(get_repository(TemplatesRepository)),
|
|
|
|
|
) -> schemas.Node:
|
|
|
|
|
"""
|
|
|
|
|
Create a new node from a template.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
template = await TemplatesService(templates_repo).get_template(template_id)
|
|
|
|
|
controller = Controller.instance()
|
|
|
|
|
project = controller.get_project(str(project_id))
|
|
|
|
|
node = await project.add_node_from_template(
|
|
|
|
|
template, x=template_usage.x, y=template_usage.y, compute_id=template_usage.compute_id
|
|
|
|
|
)
|
|
|
|
|
return node.asdict()
|
|
|
|
|