mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-05 06:41:13 +02:00
API for loading a project from a .gns3
This commit is contained in:
3 files changed
+55
-3
No files matched your search
@@ -21,9 +21,12 @@ import asyncio
|
||||
|
||||
from gns3server.web.route import Route
|
||||
from gns3server.controller import Controller
|
||||
from gns3server.config import Config
|
||||
|
||||
|
||||
from gns3server.schemas.project import (
|
||||
PROJECT_OBJECT_SCHEMA,
|
||||
PROJECT_LOAD_SCHEMA,
|
||||
PROJECT_CREATE_SCHEMA
|
||||
)
|
||||
|
||||
@@ -85,7 +88,8 @@ class ProjectHandler:
|
||||
status_codes={
|
||||
204: "The project has been closed",
|
||||
404: "The project doesn't exist"
|
||||
})
|
||||
},
|
||||
output=PROJECT_OBJECT_SCHEMA)
|
||||
def close(request, response):
|
||||
|
||||
controller = Controller.instance()
|
||||
@@ -103,7 +107,8 @@ class ProjectHandler:
|
||||
status_codes={
|
||||
201: "The project has been opened",
|
||||
404: "The project doesn't exist"
|
||||
})
|
||||
},
|
||||
output=PROJECT_OBJECT_SCHEMA)
|
||||
def open(request, response):
|
||||
|
||||
controller = Controller.instance()
|
||||
@@ -112,6 +117,29 @@ class ProjectHandler:
|
||||
response.set_status(201)
|
||||
response.json(project)
|
||||
|
||||
@Route.post(
|
||||
r"/projects/load",
|
||||
description="Open a project (only local server)",
|
||||
parameters={
|
||||
"path": ".gns3 path",
|
||||
},
|
||||
status_codes={
|
||||
201: "The project has been opened",
|
||||
403: "The server is not the local server"
|
||||
},
|
||||
input=PROJECT_LOAD_SCHEMA,
|
||||
output=PROJECT_OBJECT_SCHEMA)
|
||||
def load(request, response):
|
||||
|
||||
controller = Controller.instance()
|
||||
config = Config.instance()
|
||||
if config.get_section_config("Server").getboolean("local", False) is False:
|
||||
response.set_status(403)
|
||||
return
|
||||
project = yield from controller.load_project(request.json.get("path"),)
|
||||
response.set_status(201)
|
||||
response.json(project)
|
||||
|
||||
@Route.delete(
|
||||
r"/projects/{project_id}",
|
||||
description="Delete a project from disk",
|
||||
|
||||
Reference in new issue
Block a user