1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-15 04:49:10 +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:
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:

View File

@ -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)

View File

@ -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(

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>
Server status
</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>
<table border="1">

View File

@ -16,7 +16,9 @@
|
<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>
{% block body %}{% endblock %}
</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 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