diff --git a/gns3server/handlers/api/qemu_handler.py b/gns3server/handlers/api/qemu_handler.py index 72ad79d3..f2edd9b3 100644 --- a/gns3server/handlers/api/qemu_handler.py +++ b/gns3server/handlers/api/qemu_handler.py @@ -27,6 +27,7 @@ from ...schemas.qemu import QEMU_UPDATE_SCHEMA from ...schemas.qemu import QEMU_OBJECT_SCHEMA from ...schemas.qemu import QEMU_BINARY_LIST_SCHEMA from ...schemas.qemu import QEMU_LIST_IMAGES_SCHEMA +from ...schemas.qemu import QEMU_IMAGE_CREATE_SCHEMA from ...modules.qemu import Qemu from ...config import Config @@ -325,7 +326,8 @@ class QEMUHandler: status_codes={ 201: "Image created", }, - description="Create a Qemu image" + description="Create a Qemu image", + input=QEMU_IMAGE_CREATE_SCHEMA ) def create_img(request, response): diff --git a/gns3server/schemas/qemu.py b/gns3server/schemas/qemu.py index dd8765f1..049d1722 100644 --- a/gns3server/schemas/qemu.py +++ b/gns3server/schemas/qemu.py @@ -484,10 +484,74 @@ QEMU_LIST_IMAGES_SCHEMA = { "properties": { "filename": { "description": "Image filename", - "type": ["string"] + "type": "string" }, }, + "additionalProperties": False } ], "additionalProperties": False, } + +QEMU_IMAGE_CREATE_SCHEMA = { + "$schema": "http://json-schema.org/draft-04/schema#", + "description": "Create a new qemu image. Options can be specific to a format. Read qemu-img manual for more informations.", + "type": "object", + "properties": { + "qemu_img": { + "description": "Path to the qemu-img binary", + "type": "string" + }, + "path": { + "description": "Absolute or relative path of the image", + "type": "string" + }, + "format": { + "description": "Image format type", + "enum": ["qcow2", "qcow", "vpc", "vdi", "vmdk", "raw"] + }, + "size": { + "description": "Image size in M", + "type": "integer" + }, + "preallocation": { + "enum": ["off", "metadata", "falloc", "full"] + }, + "cluster_size": { + "type": "integer" + }, + "refcount_bits": { + "type": "integer" + }, + "lazy_refcounts": { + "enum": ["on", "off"] + }, + "subformat": { + "enum": [ + "dynamic", + "fixed", + "streamOptimized", + "twoGbMaxExtentSparse", + "twoGbMaxExtentFlat", + "monolithicSparse", + "monolithicFlat", + ] + }, + "static": { + "enum": ["on", "off"] + }, + "zeroed_grain": { + "enum": ["on", "off"] + }, + "adapter_type": { + "enum": [ + "ide", + "lsilogic", + "buslogic", + "legacyESX" + ] + } + }, + "required": ["qemu_img", "path", "format", "size"], + "additionalProperties": False +}