1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 00:08:11 +00:00

Web interface for debbuging controller

This commit is contained in:
Julien Duponchelle 2016-03-15 11:32:10 +01:00
parent 7a095478fe
commit c0e452133d
No known key found for this signature in database
GPG Key ID: F1E2485547D4595D
8 changed files with 151 additions and 8 deletions

View File

@ -93,6 +93,13 @@ class Project:
except KeyError: except KeyError:
raise aiohttp.web.HTTPNotFound(text="VM ID {} doesn't exist".format(vm_id)) 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 @asyncio.coroutine
def addLink(self): def addLink(self):
""" """
@ -111,6 +118,13 @@ class Project:
except KeyError: except KeyError:
raise aiohttp.web.HTTPNotFound(text="Link ID {} doesn't exist".format(link_id)) 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 @asyncio.coroutine
def close(self): def close(self):
for hypervisor in self._hypervisors: for hypervisor in self._hypervisors:

View File

@ -52,6 +52,10 @@ class VM:
def id(self): def id(self):
return self._id return self._id
@property
def name(self):
return self._name
@property @property
def vm_type(self): def vm_type(self):
return self._vm_type return self._vm_type
@ -76,6 +80,14 @@ class VM:
def hypervisor(self): def hypervisor(self):
return self._hypervisor return self._hypervisor
@property
def host(self):
"""
:returns: Domain or ip for console connection
"""
return self._hypervisor.host
@asyncio.coroutine @asyncio.coroutine
def create(self): def create(self):
data = copy.copy(self._properties) data = copy.copy(self._properties)

View File

@ -16,6 +16,7 @@
from ..web.route import Route from ..web.route import Route
from ..controller import Controller
from ..hypervisor.port_manager import PortManager from ..hypervisor.port_manager import PortManager
from ..hypervisor.project_manager import ProjectManager from ..hypervisor.project_manager import ProjectManager
from ..version import __version__ from ..version import __version__
@ -33,14 +34,33 @@ class IndexHandler:
@classmethod @classmethod
@Route.get( @Route.get(
r"/status", r"/hypervisor",
description="Ressources used by GNS3Server" description="Ressources used by GNS3 Hypervisor"
) )
def ports(request, response): def hypervisor(request, response):
response.template("status.html", response.template("hypervisor.html",
port_manager=PortManager.instance(), port_manager=PortManager.instance(),
project_manager=ProjectManager.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 @classmethod
@Route.get( @Route.get(

View File

@ -0,0 +1,41 @@
{% extends "layout.html" %}
{% block body %}
<h1>
Controller status
</h1>
The purpose of this page is to help for GNS3 debug. This can be dropped
in futur GNS3 versions.
<h2>Opened projects</h2>
<table border="1">
<tr>
<th>Name</th>
<th>ID</td>
<th>VMs</th>
<th>Links</th>
</tr>
{% for project in controller.projects.values() %}
<tr>
<td><a href="/projects/{{project.id}}">{{project.name}}</a></td>
<td><a href="/projects/{{project.id}}">{{project.id}}</a></td>
<td>{{project.vms|length}}</td>
<td>{{project.links|length}}</td>
</tr>
{% endfor %}
</table>
<h2>Hypervisors</h2>
<table border="1">
<tr>
<th>ID</td>
</tr>
{% for hypervisor in controller.hypervisors.values() %}
<tr>
<td>{{hypervisor.id}}</td>
</tr>
{% endfor %}
</table>
{%endblock%}

View File

@ -3,7 +3,8 @@
<h1> <h1>
Server status Server status
</h1> </h1>
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.
<h2>Opened projects</h2> <h2>Opened projects</h2>
<table border="1"> <table border="1">

View File

@ -16,7 +16,9 @@
| |
<a href="/backup/projects.tar">Backup projects</a> <a href="/backup/projects.tar">Backup projects</a>
| |
<a href="/status">Status</a> <a href="/controller">Controller status</a>
|
<a href="/hypervisor">Hypervisor status</a>
</div> </div>
{% block body %}{% endblock %} {% block body %}{% endblock %}
</body> </body>

View File

@ -0,0 +1,39 @@
{% extends "layout.html" %}
{% block body %}
<h1>
{{project.name}}
</h1>
The purpose of this page is to help for GNS3 debug. This can be dropped
in futur GNS3 versions.
<h2>VMs</h2>
<table border="1">
<tr>
<th>Name</th>
<th>ID</td>
<th>Console</th>
</tr>
{% for vm in project.vms.values() %}
<tr>
<td>{{vm.name}}</td>
<td>{{vm.id}}</td>
<td><a href="{{vm.console_type}}://{{vm.host}}:{{vm.console}}">Console</a>
</tr>
{% endfor %}
</table>
<h2>Links</h2>
<table border="1">
<tr>
<th>ID</td>
</tr>
{% for link in project.links.values() %}
<tr>
<td>{{link.id}}</td>
</tr>
{% endfor %}
</table>
{%endblock%}

View File

@ -21,6 +21,7 @@ import os
from unittest.mock import patch from unittest.mock import patch
from gns3server.version import __version__ from gns3server.version import __version__
from gns3server.controller import Controller
def test_index(http_root): def test_index(http_root):
@ -31,8 +32,21 @@ def test_index(http_root):
assert __version__ in html assert __version__ in html
def test_status(http_root): def test_controller(http_root, async_run):
response = http_root.get('/status') 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 assert response.status == 200