Merge branch 'unstable' into api_list_images

Conflicts:
	gns3server/handlers/api/iou_handler.py
This commit is contained in:
Jeremy committed 2015-04-23 17:19:37 -06:00
commit 40ce22222e
17 files changed
+238 -35

No files matched your search

+1
View File
@@ -27,6 +27,7 @@ from gns3server.handlers.api.virtualbox_handler import VirtualBoxHandler
from gns3server.handlers.api.vpcs_handler import VPCSHandler
from gns3server.handlers.api.config_handler import ConfigHandler
from gns3server.handlers.api.server_handler import ServerHandler
from gns3server.handlers.api.file_handler import FileHandler
from gns3server.handlers.upload_handler import UploadHandler
from gns3server.handlers.index_handler import IndexHandler
+60
View File
@@ -0,0 +1,60 @@
#
# 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/>.
import asyncio
import aiohttp
from ...web.route import Route
from ...schemas.file import FILE_STREAM_SCHEMA
class FileHandler:
@classmethod
@Route.get(
r"/files/stream",
description="Stream a file from the server",
status_codes={
200: "File retrieved",
404: "File doesn't exist",
409: "Can't access to file"
},
input=FILE_STREAM_SCHEMA
)
def read(request, response):
response.enable_chunked_encoding()
try:
with open(request.json.get("location"), "rb") as f:
loop = asyncio.get_event_loop()
response.content_type = "application/octet-stream"
response.set_status(200)
# Very important: do not send a content lenght otherwise QT close the connection but curl can consume the Feed
response.content_length = None
response.start(request)
while True:
data = yield from loop.run_in_executor(None, f.read, 16)
if len(data) == 0:
yield from asyncio.sleep(0.1)
else:
response.write(data)
except FileNotFoundError:
raise aiohttp.web.HTTPNotFound()
except OSError as e:
raise aiohttp.web.HTTPConflict(text=str(e))
+2 -1
View File
@@ -310,7 +310,7 @@ class IOUHandler:
vm = iou_manager.get_vm(request.match_info["vm_id"],
project_id=request.match_info["project_id"])
response.set_status(200)
response.json({"content": vm.initial_config})
response.json({"content": vm.initial_config_content})
@Route.get(
r"/iou/vms",
@@ -325,3 +325,4 @@ class IOUHandler:
vms = yield from iou_manager.list_images()
response.set_status(200)
response.json(vms)
+8 -1
View File
@@ -21,6 +21,8 @@ import datetime
import sys
import locale
import argparse
import asyncio
import concurrent
from gns3server.server import Server
from gns3server.web.logger import init_logger
@@ -92,6 +94,7 @@ def parse_arguments(argv, config):
"quiet": config.getboolean("quiet", False),
"debug": config.getboolean("debug", False),
"live": config.getboolean("live", False),
"logfile": config.getboolean("logfile", ""),
}
parser = argparse.ArgumentParser(description="GNS3 server version {}".format(__version__))
@@ -109,6 +112,7 @@ def parse_arguments(argv, config):
parser.add_argument("-d", "--debug", action="store_true", help="show debug logs")
parser.add_argument("--live", action="store_true", help="enable code live reload")
parser.add_argument("--shell", action="store_true", help="start a shell inside the server (debugging purpose only you need to install ptpython before)")
parser.add_argument("--log", help="send output to logfile instead of console")
return parser.parse_args(argv)
@@ -141,7 +145,7 @@ def main():
if args.debug:
level = logging.DEBUG
user_log = init_logger(level, quiet=args.quiet)
user_log = init_logger(level, logfile=args.log, quiet=args.quiet)
user_log.info("GNS3 server version {}".format(__version__))
current_year = datetime.date.today().year
user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))
@@ -173,6 +177,9 @@ def main():
Project.clean_project_directory()
executor = concurrent.futures.ThreadPoolExecutor(max_workers=100) # We allow 100 parallel executors
loop = asyncio.get_event_loop().set_default_executor(executor)
CrashReport.instance()
host = server_config["host"]
port = int(server_config["port"])
+8 -8
View File
@@ -317,9 +317,9 @@ class IOUVM(BaseVM):
"""
if self.initial_config_file:
content = self.initial_config
content = self.initial_config_content
content = content.replace(self._name, new_name)
self.initial_config = content
self.initial_config_content = content
super(IOUVM, IOUVM).name.__set__(self, new_name)
@@ -372,8 +372,8 @@ class IOUVM(BaseVM):
Checks for a valid IOU key in the iourc file (paranoid mode).
"""
license_check = self._manager.config.get_section_config("IOU").getboolean("license_check", False)
if license_check:
license_check = self._manager.config.get_section_config("IOU").getboolean("license_check", True)
if license_check is False:
return
config = configparser.ConfigParser()
@@ -939,7 +939,7 @@ class IOUVM(BaseVM):
log.warn("could not determine if layer 1 keepalive messages are supported by {}: {}".format(os.path.basename(self._path), e))
@property
def initial_config(self):
def initial_config_content(self):
"""
Returns the content of the current initial-config file.
"""
@@ -952,10 +952,10 @@ class IOUVM(BaseVM):
with open(config_file) as f:
return f.read()
except OSError as e:
raise IOUError("Can't read configuration file '{}'".format(config_file))
raise IOUError("Can't read configuration file '{}': {}".format(config_file, e))
@initial_config.setter
def initial_config(self, initial_config):
@initial_config_content.setter
def initial_config_content(self, initial_config):
"""
Update the initial config
+1 -1
View File
@@ -67,7 +67,7 @@ class Qemu(BaseManager):
for path in paths:
try:
for f in os.listdir(path):
if (f.startswith("qemu-system") or f == "qemu" or f == "qemu.exe") and \
if (f.startswith("qemu-system") or f.startswith("qemu-kvm") or f == "qemu" or f == "qemu.exe") and \
os.access(os.path.join(path, f), os.X_OK) and \
os.path.isfile(os.path.join(path, f)):
qemu_path = os.path.join(path, f)
-10
View File
@@ -284,20 +284,10 @@ VM_UPDATE_SCHEMA = {
"type": "string",
"minLength": 1,
},
"startup_config": {
"description": "path to the IOS startup configuration file",
"type": "string",
"minLength": 1,
},
"startup_config_content": {
"description": "Content of IOS startup configuration file",
"type": "string",
},
"private_config": {
"description": "path to the IOS private configuration file",
"type": "string",
"minLength": 1,
},
"private_config_content": {
"description": "Content of IOS private configuration file",
"type": "string",
+32
View File
@@ -0,0 +1,32 @@
# -*- 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/>.
FILE_STREAM_SCHEMA = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Request validation retrieval of a file stream",
"type": "object",
"properties": {
"location": {
"description": "File path",
"type": ["string"],
"minLength": 1
}
},
"additionalProperties": False,
"required": ["location"]
}
-4
View File
@@ -127,10 +127,6 @@ IOU_UPDATE_SCHEMA = {
"description": "Always up ethernet interface",
"type": ["boolean", "null"]
},
"initial_config": {
"description": "Path to the initial configuration of IOU",
"type": ["string", "null"]
},
"initial_config_content": {
"description": "Initial configuration of IOU",
"type": ["string", "null"]
+5
View File
@@ -225,6 +225,11 @@ class Server:
try:
self._loop.run_forever()
except OSError as e:
# This is to ignore OSError: [WinError 0] The operation completed successfully
# exception on Windows.
if not sys.platform.startswith("win") and not e.winerror == 0:
raise
except TypeError as e:
# This is to ignore an asyncio.windows_events exception
# on Windows when the process gets the SIGBREAK signal
+5 -2
View File
@@ -78,8 +78,11 @@ class ColouredStreamHandler(logging.StreamHandler):
self.handleError(record)
def init_logger(level, quiet=False):
if sys.platform.startswith("win"):
def init_logger(level, logfile=None, quiet=False):
if logfile and len(logfile) > 0:
stream_handler = logging.FileHandler(logfile)
stream_handler.formatter = ColouredFormatter("{asctime} {levelname} {filename}:{lineno} {message}", "%Y-%m-%d %H:%M:%S", "{")
elif sys.platform.startswith("win"):
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.formatter = ColouredFormatter("{asctime} {levelname} {filename}:{lineno} {message}", "%Y-%m-%d %H:%M:%S", "{")
else: