[Kimchi-devel] [PATCH V5 2/5] Validate graphics parameters input by users

apporc appleorchard2000 at gmail.com
Fri Jan 10 12:44:20 UTC 2014


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/control/utils.py |    4 ++--
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/kimchi/API.json b/src/kimchi/API.json
index 3a3c48f..d79281e 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": {
         "storagepools_create": {
             "type": "object",
@@ -90,7 +111,8 @@
                     "description": "Assign a specefic Storage Pool to the new VM",
                     "type": "string",
                     "pattern": "^/storagepools/[^/]+/?$"
-                }
+                },
+                "graphics": { "$ref": "#/kimchitype/graphics" }
             }
         },
         "vm_update": {
@@ -204,7 +226,8 @@
                     "description": "Folder",
                     "type": "array",
                     "items": { "type": "string" }
-                }
+                },
+                "graphics": { "$ref": "#/kimchitype/graphics" }
             },
             "additionalProperties": false
         },
@@ -283,7 +306,8 @@
                     "description": "Folder",
                     "type": "array",
                     "items": { "type": "string" }
-                }
+                },
+                "graphics": { "$ref": "#/kimchitype/graphics" }
             },
             "additionalProperties": false
         }
diff --git a/src/kimchi/control/utils.py b/src/kimchi/control/utils.py
index c3c5f8e..814ba20 100644
--- a/src/kimchi/control/utils.py
+++ b/src/kimchi/control/utils.py
@@ -27,7 +27,7 @@ import cherrypy
 import json
 
 
-from jsonschema import Draft3Validator, ValidationError
+from jsonschema import Draft3Validator, ValidationError, FormatChecker
 
 
 from kimchi.exception import InvalidParameter
@@ -95,7 +95,7 @@ def validate_params(params, instance, action):
         return
 
     operation = model_fn(instance, action)
-    validator = Draft3Validator(api_schema)
+    validator = Draft3Validator(api_schema, format_checker=FormatChecker())
     request = {operation: params}
 
     try:
-- 
1.7.9.5




More information about the Kimchi-devel mailing list