From c0e452133dbd8bc1a0c37a7aa1ada7c0321e4ef9 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Tue, 15 Mar 2016 11:32:10 +0100 Subject: [PATCH] Web interface for debbuging controller --- gns3server/controller/project.py | 14 +++++++ gns3server/controller/vm.py | 12 ++++++ gns3server/handlers/index_handler.py | 28 +++++++++++-- gns3server/templates/controller.html | 41 +++++++++++++++++++ .../{status.html => hypervisor.html} | 3 +- gns3server/templates/layout.html | 4 +- gns3server/templates/project.html | 39 ++++++++++++++++++ tests/handlers/test_index.py | 18 +++++++- 8 files changed, 151 insertions(+), 8 deletions(-) create mode 100644 gns3server/templates/controller.html rename gns3server/templates/{status.html => hypervisor.html} (88%) create mode 100644 gns3server/templates/project.html diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index fd2e4f47..f82224dd 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -93,6 +93,13 @@ class Project: except KeyError: raise aiohttp.web.HTTPNotFound(text="VM ID {} doesn't exist".format(vm_id)) + @property + def vms(self): + """ + :returns: Dictionnary of the VMS + """ + return self._vms + @asyncio.coroutine def addLink(self): """ @@ -111,6 +118,13 @@ class Project: except KeyError: raise aiohttp.web.HTTPNotFound(text="Link ID {} doesn't exist".format(link_id)) + @property + def links(self): + """ + :returns: Dictionnary of the Links + """ + return self._links + @asyncio.coroutine def close(self): for hypervisor in self._hypervisors: diff --git a/gns3server/controller/vm.py b/gns3server/controller/vm.py index 1c90c956..767cdc79 100644 --- a/gns3server/controller/vm.py +++ b/gns3server/controller/vm.py @@ -52,6 +52,10 @@ class VM: def id(self): return self._id + @property + def name(self): + return self._name + @property def vm_type(self): return self._vm_type @@ -76,6 +80,14 @@ class VM: def hypervisor(self): return self._hypervisor + @property + def host(self): + """ + :returns: Domain or ip for console connection + """ + return self._hypervisor.host + + @asyncio.coroutine def create(self): data = copy.copy(self._properties) diff --git a/gns3server/handlers/index_handler.py b/gns3server/handlers/index_handler.py index 18b1696a..08489b13 100644 --- a/gns3server/handlers/index_handler.py +++ b/gns3server/handlers/index_handler.py @@ -16,6 +16,7 @@ from ..web.route import Route +from ..controller import Controller from ..hypervisor.port_manager import PortManager from ..hypervisor.project_manager import ProjectManager from ..version import __version__ @@ -33,14 +34,33 @@ class IndexHandler: @classmethod @Route.get( - r"/status", - description="Ressources used by GNS3Server" + r"/hypervisor", + description="Ressources used by GNS3 Hypervisor" ) - def ports(request, response): - response.template("status.html", + def hypervisor(request, response): + response.template("hypervisor.html", port_manager=PortManager.instance(), project_manager=ProjectManager.instance() ) + @classmethod + @Route.get( + r"/controller", + description="Ressources used by GNS3 Controller" + ) + def controller(request, response): + response.template("controller.html", + controller=Controller.instance() + ) + + @classmethod + @Route.get( + r"/projects/{project_id}", + description="Ressources used by GNS3 Controller" + ) + def project(request, response): + controller = Controller.instance() + response.template("project.html", + project=controller.getProject(request.match_info["project_id"])) @classmethod @Route.get( diff --git a/gns3server/templates/controller.html b/gns3server/templates/controller.html new file mode 100644 index 00000000..f6619c69 --- /dev/null +++ b/gns3server/templates/controller.html @@ -0,0 +1,41 @@ +{% extends "layout.html" %} +{% block body %} +

+ Controller status +

+The purpose of this page is to help for GNS3 debug. This can be dropped +in futur GNS3 versions. + +

Opened projects

+ + + + + + +{% for project in controller.projects.values() %} + + + + + + +{% endfor %} +
NameID + VMsLinks
{{project.name}}{{project.id}}{{project.vms|length}}{{project.links|length}}
+ +

Hypervisors

+ + + +{% for hypervisor in controller.hypervisors.values() %} + + + +{% endfor %} +
ID +
{{hypervisor.id}}
+ + +{%endblock%} + diff --git a/gns3server/templates/status.html b/gns3server/templates/hypervisor.html similarity index 88% rename from gns3server/templates/status.html rename to gns3server/templates/hypervisor.html index bed8c797..935f8f3d 100644 --- a/gns3server/templates/status.html +++ b/gns3server/templates/hypervisor.html @@ -3,7 +3,8 @@

Server status

-The purpose of this page is to help for GNS3 debug. +The purpose of this page is to help for GNS3 debug. This can be dropped +in futur GNS3 versions.

Opened projects

diff --git a/gns3server/templates/layout.html b/gns3server/templates/layout.html index 54caef09..2873ffe4 100644 --- a/gns3server/templates/layout.html +++ b/gns3server/templates/layout.html @@ -16,7 +16,9 @@ | Backup projects | - Status + Controller status + | + Hypervisor status {% block body %}{% endblock %} diff --git a/gns3server/templates/project.html b/gns3server/templates/project.html new file mode 100644 index 00000000..1fed748a --- /dev/null +++ b/gns3server/templates/project.html @@ -0,0 +1,39 @@ +{% extends "layout.html" %} +{% block body %} +

+ {{project.name}} +

+The purpose of this page is to help for GNS3 debug. This can be dropped +in futur GNS3 versions. + +

VMs

+
+ + + + +{% for vm in project.vms.values() %} + + + + +{% endfor %} +
NameID + Console
{{vm.name}}{{vm.id}}Console +
+ +

Links

+ + + +{% for link in project.links.values() %} + + + +{% endfor %} +
ID +
{{link.id}}
+ + +{%endblock%} + diff --git a/tests/handlers/test_index.py b/tests/handlers/test_index.py index bb8614e1..26515f33 100644 --- a/tests/handlers/test_index.py +++ b/tests/handlers/test_index.py @@ -21,6 +21,7 @@ import os from unittest.mock import patch from gns3server.version import __version__ +from gns3server.controller import Controller def test_index(http_root): @@ -31,8 +32,21 @@ def test_index(http_root): assert __version__ in html -def test_status(http_root): - response = http_root.get('/status') +def test_controller(http_root, async_run): + project = async_run(Controller.instance().addProject(name="test")) + response = http_root.get('/controller') + assert "test" in response.html + assert response.status == 200 + + +def test_hypervisor(http_root): + response = http_root.get('/hypervisor') + assert response.status == 200 + + +def test_project(http_root, async_run): + project = async_run(Controller.instance().addProject(name="test")) + response = http_root.get('/projects/{}'.format(project.id)) assert response.status == 200