From fb3bcf3b8ff1d4c4a4d6f025733791cdc5d2fa65 Mon Sep 17 00:00:00 2001 From: grossmj Date: Thu, 15 Mar 2018 15:21:29 +0700 Subject: [PATCH] Basic project stats. --- gns3server/controller/project.py | 9 +++++++++ .../handlers/api/controller/project_handler.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+) 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={