[Kimchi-devel] [PATCHv2 2/3] storage target: Update controller and json schema

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Mon Dec 30 07:24:17 UTC 2013


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

Add json schema to validate mandatory param of target_type,
also update controller.py.

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/API.json      | 11 +++++++++++
 src/kimchi/controller.py | 30 ++++++++++++++++++++++++++++--
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/src/kimchi/API.json b/src/kimchi/API.json
index 29d8172..24ff6eb 100644
--- a/src/kimchi/API.json
+++ b/src/kimchi/API.json
@@ -216,6 +216,17 @@
                     "required": true
                 }
             }
+        },
+        "storagetargets_get_list": {
+            "type": "object",
+            "properties": {
+                "target_type": {
+                    "description": "List storage servers of given type",
+                    "type": "string",
+                    "pattern": "^netfs$",
+                    "required": true
+                }
+            }
         }
     }
 }
diff --git a/src/kimchi/controller.py b/src/kimchi/controller.py
index bdd3cab..bd94fd4 100644
--- a/src/kimchi/controller.py
+++ b/src/kimchi/controller.py
@@ -660,9 +660,35 @@ class StorageServers(Collection):
         res_list = get_list(*self.model_args, **params)
         return kimchi.template.render(get_class_name(self), res_list)
 
-
 class StorageServer(Resource):
-    pass
+    def __init__(self, model, ident):
+        super(StorageServer, self).__init__(model, ident)
+
+    @property
+    def data(self):
+        return dict(name=self.ident)
+
+    def _cp_dispatch(self, vpath):
+        if vpath:
+            subcollection = vpath.pop(0)
+            if subcollection == 'storagetargets':
+                # incoming text, from URL, is not unicode, need decode
+                return StorageTargets(self.model, self.ident.decode("utf-8"))
+
+class StorageTargets(Collection):
+    def __init__(self, model, server):
+        super(StorageTargets, self).__init__(model)
+        self.server = server
+        self.resource_args = [self.server, ]
+        self.model_args = [self.server, ]
+
+    def get(self):
+        res_list = []
+        params = parse_request()
+        validate_params(params, self, 'get_list')
+        get_list = getattr(self.model, model_fn(self, 'get_list'))
+        res_list = get_list(*self.model_args, **params)
+        return kimchi.template.render(get_class_name(self), res_list)
 
 class Config(Resource):
     def __init__(self, model, id=None):
-- 
1.8.1.2




More information about the Kimchi-devel mailing list