[Kimchi-devel] [PATCH V4 3/5] Validate graphics parameters input by users

apporc appleorchard2000 at gmail.com
Wed Dec 25 14:52:00 UTC 2013


1.  Validate graphics parameters from rest requester, with newly added
    json schema in kimchi.

2.  To use "format" property, i need to hook format_checker for Draft3Validator in controller.py.

Signed-off-by: apporc <appleorchard2000 at gmail.com>
---
 src/kimchi/API.json      | 30 +++++++++++++++++++++++++++---
 src/kimchi/controller.py |  4 ++--
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/kimchi/API.json b/src/kimchi/API.json
index 7b90826..21341fd 100644
--- a/src/kimchi/API.json
+++ b/src/kimchi/API.json
@@ -3,6 +3,27 @@
     "title": "Kimchi API",
     "description": "Json schema for Kimchi API",
     "type": "object",
+    "kimchitype": {
+        "graphics": {
+            "description": "Configure graphics parameters for the new VM",
+            "type": "object",
+            "properties": {
+                "type": { "enum": ["spice", "vnc"] },
+                "listen": {
+                    "type": [
+                        {
+                            "type": "string",
+                            "format": "ip-address"
+                        },
+                        {
+                            "type": "string",
+                            "format": "ipv6"
+                        }
+                        ]
+                }
+            }
+        }
+    },
     "properties": {
         "vms_create": {
             "type": "object",
@@ -21,7 +42,8 @@
                     "description": "Assign a specefic Storage Pool to the new VM",
                     "type": "string",
                     "pattern": "^/storagepools/[^/]+/?$"
-                }
+                },
+                "graphics": { "$ref": "#/kimchitype/graphics" }
             }
         },
         "vm_update": {
@@ -129,7 +151,8 @@
                     "description": "Folder",
                     "type": "array",
                     "items": { "type": "string" }
-                }
+                },
+                "graphics": { "$ref": "#/kimchitype/graphics" }
             },
             "additionalProperties": false
         },
@@ -202,7 +225,8 @@
                     "description": "Folder",
                     "type": "array",
                     "items": { "type": "string" }
-                }
+                },
+                "graphics": { "$ref": "#/kimchitype/graphics" }
             },
             "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)
-- 
1.8.1.2




More information about the Kimchi-devel mailing list