diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index d46ea867..77ffbb9e 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -1013,6 +1013,15 @@ class Project: raise e return new_node + def stats(self): + + return { + "nodes": len(self._nodes), + "links": len(self._links), + "drawings": len(self._drawings), + "snapshots": len(self._snapshots) + } + def __json__(self): return { "name": self._name, diff --git a/gns3server/handlers/api/controller/project_handler.py b/gns3server/handlers/api/controller/project_handler.py index 99ede986..e16d4a12 100644 --- a/gns3server/handlers/api/controller/project_handler.py +++ b/gns3server/handlers/api/controller/project_handler.py @@ -92,6 +92,21 @@ class ProjectHandler: project = controller.get_project(request.match_info["project_id"]) response.json(project) + @Route.get( + r"/projects/{project_id}/stats", + description="Get a project statistics", + parameters={ + "project_id": "Project UUID", + }, + status_codes={ + 200: "Project statistics returned", + 404: "The project doesn't exist" + }) + def get(request, response): + controller = Controller.instance() + project = controller.get_project(request.match_info["project_id"]) + response.json(project.stats()) + @Route.put( r"/projects/{project_id}", status_codes={