Some cleaning + move "/version" endpoint to "/server/version".

This commit is contained in:
grossmj committed 2016-06-01 17:50:31 -06:00
1 parent 87f15eafe0
commit cd07a99118
18 files changed
+70 -187

No files matched your search

@@ -228,7 +228,7 @@ class IOUHandler:
iou_manager = IOU.instance()
vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
nio_type = request.json["type"]
if nio_type not in ("nio_udp", "nio_tap", "nio_generic_ethernet"):
if nio_type not in ("nio_udp", "nio_tap", "nio_ethernet", "nio_generic_ethernet"):
raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
nio = iou_manager.create_nio(vm.iouyap_path, request.json)
yield from vm.adapter_add_nio_binding(int(request.match_info["adapter_number"]), int(request.match_info["port_number"]), nio)
@@ -25,7 +25,7 @@ from aiohttp.web import HTTPConflict
class VersionHandler:
@Route.get(
r"/version",
r"/server/version",
description="Retrieve the server version number",
output=VERSION_SCHEMA)
def version(request, response):
@@ -35,7 +35,7 @@ class VersionHandler:
response.json({"version": __version__, "local": local_server})
@Route.post(
r"/version",
r"/server/version",
description="Check if version is the same as the server",
output=VERSION_SCHEMA,
input=VERSION_SCHEMA,
@@ -17,7 +17,6 @@
from .compute_handler import ComputeHandler
from .project_handler import ProjectHandler
from .version_handler import VersionHandler
from .node_handler import NodeHandler
from .link_handler import LinkHandler
from .server_handler import ServerHandler
@@ -15,15 +15,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import asyncio
from aiohttp.web import HTTPForbidden
from gns3server.web.route import Route
from gns3server.config import Config
from gns3server.compute.project_manager import ProjectManager
from gns3server.schemas.compute import COMPUTE_CREATE_SCHEMA, COMPUTE_OBJECT_SCHEMA, COMPUTE_UPDATE_SCHEMA
from gns3server.controller import Controller
from gns3server.schemas.compute import (
COMPUTE_CREATE_SCHEMA,
COMPUTE_OBJECT_SCHEMA,
COMPUTE_UPDATE_SCHEMA
)
import logging
log = logging.getLogger(__name__)
@@ -47,7 +47,7 @@ class ComputeHandler:
@Route.get(
r"/computes",
description="List of compute server",
description="List of compute servers",
status_codes={
200: "Compute servers list returned"
})
@@ -15,10 +15,13 @@
# 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 ....config import Config
from ....controller import Controller
from aiohttp.web import HTTPForbidden
from gns3server.web.route import Route
from gns3server.config import Config
from gns3server.controller import Controller
from gns3server.schemas.version import VERSION_SCHEMA
from gns3server.version import __version__
from aiohttp.web import HTTPConflict, HTTPForbidden
import asyncio
import logging
@@ -42,9 +45,9 @@ class ServerHandler:
if config.get_section_config("Server").getboolean("local", False) is False:
raise HTTPForbidden(text="You can only stop a local server")
log.info("Start shuting down the server")
log.info("Start shutting down the server")
# close all the projets first
# close all the projects first
controller = Controller.instance()
projects = controller.projects
@@ -66,3 +69,27 @@ class ServerHandler:
server = WebServer.instance()
asyncio.async(server.shutdown_server())
response.set_status(201)
@Route.get(
r"/server/version",
description="Retrieve the server version number",
output=VERSION_SCHEMA)
def version(request, response):
config = Config.instance()
local_server = config.get_section_config("Server").getboolean("local", False)
response.json({"version": __version__, "local": local_server})
@Route.post(
r"/server/version",
description="Check if version is the same as the server",
output=VERSION_SCHEMA,
input=VERSION_SCHEMA,
status_codes={
200: "Same version",
409: "Invalid version"
})
def check_version(request, response):
if request.json["version"] != __version__:
raise HTTPConflict(text="Client version {} differs with server version {}".format(request.json["version"], __version__))
response.json({"version": __version__})
@@ -1,49 +0,0 @@
# -*- 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 gns3server.web.route import Route
from gns3server.config import Config
from gns3server.schemas.version import VERSION_SCHEMA
from gns3server.version import __version__
from aiohttp.web import HTTPConflict
class VersionHandler:
@Route.get(
r"/version",
description="Retrieve the server version number",
output=VERSION_SCHEMA)
def version(request, response):
config = Config.instance()
local_server = config.get_section_config("Server").getboolean("local", False)
response.json({"version": __version__, "local": local_server})
@Route.post(
r"/version",
description="Check if version is the same as the server",
output=VERSION_SCHEMA,
input=VERSION_SCHEMA,
status_codes={
200: "Same version",
409: "Invalid version"
})
def check_version(request, response):
if request.json["version"] != __version__:
raise HTTPConflict(text="Client version {} differs with server version {}".format(request.json["version"], __version__))
response.json({"version": __version__})