mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Upload images API
Conflicts: requirements.txt setup.py
This commit is contained in:
1 parent
61fb641215
commit
bb4ebbfe64
9 files changed
+121
-4
No files matched your search
@@ -463,3 +463,16 @@ class DynamipsVMHandler:
|
||||
vms = yield from dynamips_manager.list_images()
|
||||
response.set_status(200)
|
||||
response.json(vms)
|
||||
|
||||
@Route.post(
|
||||
r"/dynamips/vms/{filename}",
|
||||
status_codes={
|
||||
204: "Image uploaded",
|
||||
},
|
||||
raw=True,
|
||||
description="Upload Dynamips image.")
|
||||
def upload_vm(request, response):
|
||||
|
||||
dynamips_manager = Dynamips.instance()
|
||||
yield from dynamips_manager.write_image(request.match_info["filename"], request.content)
|
||||
response.set_status(204)
|
||||
@@ -330,3 +330,16 @@ class IOUHandler:
|
||||
vms = yield from iou_manager.list_images()
|
||||
response.set_status(200)
|
||||
response.json(vms)
|
||||
|
||||
@Route.post(
|
||||
r"/iou/vms/{filename}",
|
||||
status_codes={
|
||||
204: "Image uploaded",
|
||||
},
|
||||
raw=True,
|
||||
description="Upload IOU image.")
|
||||
def upload_vm(request, response):
|
||||
|
||||
iou_manager = IOU.instance()
|
||||
yield from iou_manager.write_image(request.match_info["filename"], request.content)
|
||||
response.set_status(204)
|
||||
@@ -305,3 +305,16 @@ class QEMUHandler:
|
||||
vms = yield from qemu_manager.list_images()
|
||||
response.set_status(200)
|
||||
response.json(vms)
|
||||
|
||||
@Route.post(
|
||||
r"/qemu/vms/{filename}",
|
||||
status_codes={
|
||||
204: "Image uploaded",
|
||||
},
|
||||
raw=True,
|
||||
description="Upload Qemu image.")
|
||||
def upload_vm(request, response):
|
||||
|
||||
qemu_manager = Qemu.instance()
|
||||
yield from qemu_manager.write_image(request.match_info["filename"], request.content)
|
||||
response.set_status(204)
|
||||
@@ -444,3 +444,20 @@ class BaseManager:
|
||||
"""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
@asyncio.coroutine
|
||||
def write_image(self, filename, stream):
|
||||
directory = self.get_images_directory()
|
||||
path = os.path.join(directory, os.path.basename(filename))
|
||||
log.info("Writting image file %s", path)
|
||||
try:
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
with open(path, 'wb+') as f:
|
||||
while True:
|
||||
packet = yield from stream.read(512)
|
||||
if not packet:
|
||||
break
|
||||
f.write(packet)
|
||||
os.chmod(path, stat.S_IWRITE | stat.S_IREAD | stat.S_IEXEC)
|
||||
except OSError as e:
|
||||
raise aiohttp.web.HTTPConflict(text="Could not write image: {} to {}".format(filename, e))
|
||||
@@ -89,6 +89,7 @@ class Route(object):
|
||||
output_schema = kw.get("output", {})
|
||||
input_schema = kw.get("input", {})
|
||||
api_version = kw.get("api_version", 1)
|
||||
raw = kw.get("raw", False)
|
||||
|
||||
# If it's a JSON api endpoint just register the endpoint an do nothing
|
||||
if api_version is None:
|
||||
@@ -119,8 +120,9 @@ class Route(object):
|
||||
# This block is executed at each method call
|
||||
|
||||
# Non API call
|
||||
if api_version is None:
|
||||
if api_version is None or raw is True:
|
||||
response = Response(request=request, route=route, output_schema=output_schema)
|
||||
|
||||
yield from func(request, response)
|
||||
return response
|
||||
|
||||
|
||||
Reference in new issue
Block a user