On 12/30/2013 05:24 AM, lvroyce(a)linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
Add json schema to validate mandatory param of target_type,
Why should target_type be mandatory?
From my perspective, the query param must be optional.
If user would like to use it, we have support, if not, try the default way
also update controller.py.
Signed-off-by: Royce Lv <lvroyce(a)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)
Why do we need a new collection to expose the sources paths?
GET /storageserver/<id> should return all data related to this server
class Config(Resource):
def __init__(self, model, id=None):