mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 22:11:14 +02:00
Display an upload form (upload is not yet ready)
This commit is contained in:
1 parent
210aa6f12a
commit
f7cd09d5fb
30 files changed
+234
-100
No files matched your search
@@ -1,9 +1,19 @@
|
||||
__all__ = ["version_handler",
|
||||
"network_handler",
|
||||
"vpcs_handler",
|
||||
"project_handler",
|
||||
"virtualbox_handler",
|
||||
"dynamips_vm_handler",
|
||||
"dynamips_device_handler",
|
||||
"iou_handler",
|
||||
"qemu_handler"]
|
||||
#
|
||||
# Copyright (C) 2015 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from gns3server.handlers.api import *
|
||||
from gns3server.handlers.upload_handler import UploadHandler
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
__all__ = ["version_handler",
|
||||
"network_handler",
|
||||
"vpcs_handler",
|
||||
"project_handler",
|
||||
"virtualbox_handler",
|
||||
"dynamips_vm_handler",
|
||||
"dynamips_device_handler",
|
||||
"iou_handler",
|
||||
"qemu_handler"]
|
||||
+7
-7
@@ -17,13 +17,13 @@
|
||||
|
||||
import os
|
||||
import asyncio
|
||||
from ..web.route import Route
|
||||
from ..schemas.dynamips_device import DEVICE_CREATE_SCHEMA
|
||||
from ..schemas.dynamips_device import DEVICE_UPDATE_SCHEMA
|
||||
from ..schemas.dynamips_device import DEVICE_CAPTURE_SCHEMA
|
||||
from ..schemas.dynamips_device import DEVICE_OBJECT_SCHEMA
|
||||
from ..schemas.dynamips_device import DEVICE_NIO_SCHEMA
|
||||
from ..modules.dynamips import Dynamips
|
||||
from ...web.route import Route
|
||||
from ...schemas.dynamips_device import DEVICE_CREATE_SCHEMA
|
||||
from ...schemas.dynamips_device import DEVICE_UPDATE_SCHEMA
|
||||
from ...schemas.dynamips_device import DEVICE_CAPTURE_SCHEMA
|
||||
from ...schemas.dynamips_device import DEVICE_OBJECT_SCHEMA
|
||||
from ...schemas.dynamips_device import DEVICE_NIO_SCHEMA
|
||||
from ...modules.dynamips import Dynamips
|
||||
|
||||
|
||||
class DynamipsDeviceHandler:
|
||||
+9
-9
@@ -19,16 +19,16 @@
|
||||
import os
|
||||
import base64
|
||||
import asyncio
|
||||
from ..web.route import Route
|
||||
from ..schemas.dynamips_vm import VM_CREATE_SCHEMA
|
||||
from ..schemas.dynamips_vm import VM_UPDATE_SCHEMA
|
||||
from ..schemas.dynamips_vm import VM_CAPTURE_SCHEMA
|
||||
from ..schemas.dynamips_vm import VM_OBJECT_SCHEMA
|
||||
from ..schemas.dynamips_vm import VM_NIO_SCHEMA
|
||||
from ..schemas.dynamips_vm import VM_CONFIGS_SCHEMA
|
||||
from ..modules.dynamips import Dynamips
|
||||
from ..modules.project_manager import ProjectManager
|
||||
|
||||
from ...web.route import Route
|
||||
from ...schemas.dynamips_vm import VM_CREATE_SCHEMA
|
||||
from ...schemas.dynamips_vm import VM_UPDATE_SCHEMA
|
||||
from ...schemas.dynamips_vm import VM_CAPTURE_SCHEMA
|
||||
from ...schemas.dynamips_vm import VM_OBJECT_SCHEMA
|
||||
from ...schemas.dynamips_vm import VM_NIO_SCHEMA
|
||||
from ...schemas.dynamips_vm import VM_CONFIGS_SCHEMA
|
||||
from ...modules.dynamips import Dynamips
|
||||
from ...modules.project_manager import ProjectManager
|
||||
|
||||
class DynamipsVMHandler:
|
||||
|
||||
@@ -18,15 +18,15 @@
|
||||
import os
|
||||
|
||||
|
||||
from ..web.route import Route
|
||||
from ..modules.port_manager import PortManager
|
||||
from ..schemas.iou import IOU_CREATE_SCHEMA
|
||||
from ..schemas.iou import IOU_UPDATE_SCHEMA
|
||||
from ..schemas.iou import IOU_OBJECT_SCHEMA
|
||||
from ..schemas.iou import IOU_NIO_SCHEMA
|
||||
from ..schemas.iou import IOU_CAPTURE_SCHEMA
|
||||
from ..schemas.iou import IOU_INITIAL_CONFIG_SCHEMA
|
||||
from ..modules.iou import IOU
|
||||
from ...web.route import Route
|
||||
from ...modules.port_manager import PortManager
|
||||
from ...schemas.iou import IOU_CREATE_SCHEMA
|
||||
from ...schemas.iou import IOU_UPDATE_SCHEMA
|
||||
from ...schemas.iou import IOU_OBJECT_SCHEMA
|
||||
from ...schemas.iou import IOU_NIO_SCHEMA
|
||||
from ...schemas.iou import IOU_CAPTURE_SCHEMA
|
||||
from ...schemas.iou import IOU_INITIAL_CONFIG_SCHEMA
|
||||
from ...modules.iou import IOU
|
||||
|
||||
|
||||
class IOUHandler:
|
||||
@@ -15,9 +15,9 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from ..web.route import Route
|
||||
from ..modules.port_manager import PortManager
|
||||
from ..utils.interfaces import interfaces
|
||||
from ...web.route import Route
|
||||
from ...modules.port_manager import PortManager
|
||||
from ...utils.interfaces import interfaces
|
||||
|
||||
|
||||
class NetworkHandler:
|
||||
@@ -15,10 +15,10 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from ..web.route import Route
|
||||
from ..schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA, PROJECT_UPDATE_SCHEMA
|
||||
from ..modules.project_manager import ProjectManager
|
||||
from ..modules import MODULES
|
||||
from ...web.route import Route
|
||||
from ...schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA, PROJECT_UPDATE_SCHEMA
|
||||
from ...modules.project_manager import ProjectManager
|
||||
from ...modules import MODULES
|
||||
|
||||
|
||||
class ProjectHandler:
|
||||
@@ -18,14 +18,14 @@
|
||||
import os
|
||||
|
||||
|
||||
from ..web.route import Route
|
||||
from ..modules.port_manager import PortManager
|
||||
from ..schemas.qemu import QEMU_CREATE_SCHEMA
|
||||
from ..schemas.qemu import QEMU_UPDATE_SCHEMA
|
||||
from ..schemas.qemu import QEMU_OBJECT_SCHEMA
|
||||
from ..schemas.qemu import QEMU_NIO_SCHEMA
|
||||
from ..schemas.qemu import QEMU_BINARY_LIST_SCHEMA
|
||||
from ..modules.qemu import Qemu
|
||||
from ...web.route import Route
|
||||
from ...modules.port_manager import PortManager
|
||||
from ...schemas.qemu import QEMU_CREATE_SCHEMA
|
||||
from ...schemas.qemu import QEMU_UPDATE_SCHEMA
|
||||
from ...schemas.qemu import QEMU_OBJECT_SCHEMA
|
||||
from ...schemas.qemu import QEMU_NIO_SCHEMA
|
||||
from ...schemas.qemu import QEMU_BINARY_LIST_SCHEMA
|
||||
from ...modules.qemu import Qemu
|
||||
|
||||
|
||||
class QEMUHandler:
|
||||
@@ -15,9 +15,9 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from ..web.route import Route
|
||||
from ..schemas.version import VERSION_SCHEMA
|
||||
from ..version import __version__
|
||||
from ...web.route import Route
|
||||
from ...schemas.version import VERSION_SCHEMA
|
||||
from ...version import __version__
|
||||
from aiohttp.web import HTTPConflict
|
||||
|
||||
|
||||
+8
-8
@@ -16,14 +16,14 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
from ..web.route import Route
|
||||
from ..schemas.virtualbox import VBOX_CREATE_SCHEMA
|
||||
from ..schemas.virtualbox import VBOX_UPDATE_SCHEMA
|
||||
from ..schemas.virtualbox import VBOX_NIO_SCHEMA
|
||||
from ..schemas.virtualbox import VBOX_CAPTURE_SCHEMA
|
||||
from ..schemas.virtualbox import VBOX_OBJECT_SCHEMA
|
||||
from ..modules.virtualbox import VirtualBox
|
||||
from ..modules.project_manager import ProjectManager
|
||||
from ...web.route import Route
|
||||
from ...schemas.virtualbox import VBOX_CREATE_SCHEMA
|
||||
from ...schemas.virtualbox import VBOX_UPDATE_SCHEMA
|
||||
from ...schemas.virtualbox import VBOX_NIO_SCHEMA
|
||||
from ...schemas.virtualbox import VBOX_CAPTURE_SCHEMA
|
||||
from ...schemas.virtualbox import VBOX_OBJECT_SCHEMA
|
||||
from ...modules.virtualbox import VirtualBox
|
||||
from ...modules.project_manager import ProjectManager
|
||||
|
||||
|
||||
class VirtualBoxHandler:
|
||||
@@ -15,12 +15,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from ..web.route import Route
|
||||
from ..schemas.vpcs import VPCS_CREATE_SCHEMA
|
||||
from ..schemas.vpcs import VPCS_UPDATE_SCHEMA
|
||||
from ..schemas.vpcs import VPCS_OBJECT_SCHEMA
|
||||
from ..schemas.vpcs import VPCS_NIO_SCHEMA
|
||||
from ..modules.vpcs import VPCS
|
||||
from ...web.route import Route
|
||||
from ...schemas.vpcs import VPCS_CREATE_SCHEMA
|
||||
from ...schemas.vpcs import VPCS_UPDATE_SCHEMA
|
||||
from ...schemas.vpcs import VPCS_OBJECT_SCHEMA
|
||||
from ...schemas.vpcs import VPCS_NIO_SCHEMA
|
||||
from ...modules.vpcs import VPCS
|
||||
|
||||
|
||||
class VPCSHandler:
|
||||
@@ -0,0 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2015 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from ..web.route import Route
|
||||
from ..schemas.version import VERSION_SCHEMA
|
||||
from ..version import __version__
|
||||
from aiohttp.web import HTTPConflict
|
||||
|
||||
|
||||
class UploadHandler:
|
||||
|
||||
@classmethod
|
||||
@Route.get(
|
||||
r"/upload",
|
||||
description="Manage upload of GNS3 images",
|
||||
api_version=None
|
||||
)
|
||||
def index(request, response):
|
||||
response.template("upload.html")
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<title>GNS3 Server</title>
|
||||
</head>
|
||||
<body>
|
||||
{% block body %}{% endblock %}
|
||||
</body>
|
||||
<small>
|
||||
Powered by GNS3 {{gns3_version}}
|
||||
</small>
|
||||
</html>
|
||||
@@ -1,20 +1,16 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<title>Upload Form for GNS3 server {{version}}</title>
|
||||
</head>
|
||||
<body>
|
||||
<p><h1>Select & Upload (v{{version}})</h1></p>
|
||||
<form enctype="multipart/form-data" action="/upload" method="post">
|
||||
File: <input type="file" name="file" />
|
||||
<br />
|
||||
<br />
|
||||
<input type="submit" value="upload" />
|
||||
</form>
|
||||
{%if items%}
|
||||
<h3>Files on {{host}}</h3>
|
||||
{%for item in items%}
|
||||
<p>{{path}}/{{item}}</a></p>
|
||||
{%end%}
|
||||
{%end%}
|
||||
</body>
|
||||
{% extends "layout.html" %}
|
||||
{% block body %}
|
||||
<h1>Select & Upload an image for GNS3</h1>
|
||||
<form enctype="multipart/form-data" action="/upload" method="post">
|
||||
File: <input type="file" name="file" />
|
||||
<br />
|
||||
<br />
|
||||
<input type="submit" value="Upload" />
|
||||
</form>
|
||||
{%if items%}
|
||||
<h3>Files on {{host}}</h3>
|
||||
{%for item in items%}
|
||||
<p>{{path}}/{{item}}</a></p>
|
||||
{%endfor%}
|
||||
{%endif%}
|
||||
{% endblock %}
|
||||
@@ -20,9 +20,12 @@ import jsonschema
|
||||
import aiohttp.web
|
||||
import logging
|
||||
import sys
|
||||
import jinja2
|
||||
|
||||
from ..version import __version__
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
renderer = jinja2.Environment(loader=jinja2.PackageLoader('gns3server', 'templates'))
|
||||
|
||||
|
||||
class Response(aiohttp.web.Response):
|
||||
@@ -47,6 +50,28 @@ class Response(aiohttp.web.Response):
|
||||
log.debug(json.loads(self.body.decode('utf-8')))
|
||||
return super().start(request)
|
||||
|
||||
def html(self, answer):
|
||||
"""
|
||||
Set the response content type to text/html and serialize
|
||||
the content.
|
||||
|
||||
:param anwser The response as a Python object
|
||||
"""
|
||||
|
||||
self.content_type = "text/html"
|
||||
self.body = answer.encode('utf-8')
|
||||
|
||||
def template(self, template_filename, **kwargs):
|
||||
"""
|
||||
Render a template
|
||||
|
||||
:params template: Template name
|
||||
:params kwargs: Template parameters
|
||||
"""
|
||||
template = renderer.get_template(template_filename)
|
||||
kwargs["gns3_version"] = __version__
|
||||
self.html(template.render(**kwargs))
|
||||
|
||||
def json(self, answer):
|
||||
"""
|
||||
Set the response content type to application/json and serialize
|
||||
|
||||
+12
-4
@@ -81,8 +81,11 @@ class Route(object):
|
||||
# This block is executed only the first time
|
||||
output_schema = kw.get("output", {})
|
||||
input_schema = kw.get("input", {})
|
||||
api_version = kw.get("version", 1)
|
||||
cls._path = "/v{version}{path}".format(path=path, version=api_version)
|
||||
api_version = kw.get("api_version", 1)
|
||||
if api_version is None:
|
||||
cls._path = path
|
||||
else:
|
||||
cls._path = "/v{version}{path}".format(path=path, version=api_version)
|
||||
|
||||
def register(func):
|
||||
route = cls._path
|
||||
@@ -123,8 +126,13 @@ class Route(object):
|
||||
response.set_status(500)
|
||||
exc_type, exc_value, exc_tb = sys.exc_info()
|
||||
lines = traceback.format_exception(exc_type, exc_value, exc_tb)
|
||||
tb = "".join(lines)
|
||||
response.json({"message": tb, "status": 500})
|
||||
if api_version is not None:
|
||||
tb = "".join(lines)
|
||||
response.json({"message": tb, "status": 500})
|
||||
else:
|
||||
tb = "\n".join(lines)
|
||||
response.html("<h1>Internal error</h1><pre>{}</pre>".format(tb))
|
||||
|
||||
return response
|
||||
|
||||
cls._routes.append((method, cls._path, control_schema))
|
||||
|
||||
Reference in new issue
Block a user