If I have not seen wrongly, the three graphic schemas are similar.
Maybe you could write it once and reuse it with "$ref" keyword.
More details here:
http://spacetelescope.github.io/understanding-json-schema/structuring.html
On 12/22/2013 06:43 AM, apporc wrote:
1. Validate graphics parameters from rest requester, with newly
added
json schema in kimchi.
2. Because we are now using jsonschema.Draft3Validator in kimchi, which
doesn't support 'oneOf' property, so i can not use this:
"listen": {
"type": "string",
"oneOf": [
{ "format": "ip-address" },
{ "format": "ipv6"}
As ipv6 is not urgent, i think just 'ipv4' validation should be enough by
now.
Which is :
"type": { "enum": ["spice", "vnc"] },
"listen": {
"type": "string",
"format": "ip-address"
}
We can add ipv6 validation here when the os distribution we based on provided
high versions of jsonschema, or when we are about to replace Draft3Validator
with Draft4Validator.
3. To use "format" property, i need to hook format_checker for Draft3Validator
in controller.py.
Signed-off-by: apporc <appleorchard2000(a)gmail.com>
---
src/kimchi/API.json | 33 +++++++++++++++++++++++++++++++++
src/kimchi/controller.py | 4 ++--
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/API.json b/src/kimchi/API.json
index 7b90826..0f97f0e 100644
--- a/src/kimchi/API.json
+++ b/src/kimchi/API.json
@@ -21,6 +21,17 @@
"description": "Assign a specefic Storage Pool to
the new VM",
"type": "string",
"pattern": "^/storagepools/[^/]+/?$"
+ },
+ "graphics": {
+ "description": "Configure graphics parameters for the
new VM",
+ "type": "object",
+ "properties": {
+ "type": { "enum": ["spice",
"vnc"] },
+ "listen": {
+ "type": "string",
+ "format": "ip-address"
+ }
+ }
}
}
},
@@ -129,6 +140,17 @@
"description": "Folder",
"type": "array",
"items": { "type": "string" }
+ },
+ "graphics": {
+ "description": "Configure graphics parameters for the
new VM",
+ "type": "object",
+ "properties": {
+ "type": { "enum": ["spice",
"vnc"] },
+ "listen": {
+ "type": "string",
+ "format": "ip-address"
+ }
+ }
}
},
"additionalProperties": false
@@ -202,6 +224,17 @@
"description": "Folder",
"type": "array",
"items": { "type": "string" }
+ },
+ "graphics": {
+ "description": "Configure graphics parameters for the
new VM",
+ "type": "object",
+ "properties": {
+ "type": { "enum": ["spice",
"vnc"] },
+ "listen": {
+ "type": "string",
+ "format": "ip-address"
+ }
+ }
}
},
"additionalProperties": false
diff --git a/src/kimchi/controller.py b/src/kimchi/controller.py
index dacaa6a..003adf2 100644
--- a/src/kimchi/controller.py
+++ b/src/kimchi/controller.py
@@ -26,7 +26,7 @@ import urllib2
from functools import wraps
-from jsonschema import Draft3Validator, ValidationError
+from jsonschema import Draft3Validator, ValidationError, FormatChecker
import kimchi.template
@@ -94,7 +94,7 @@ def validate_params(params, instance, action):
else:
return
operation = model_fn(instance, action)
- validator = Draft3Validator(api_schema)
+ validator = Draft3Validator(api_schema, format_checker=FormatChecker())
request = {operation: params}
try:
validator.validate(request)