On 01/07/2014 05:43 PM, 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,
also update controller.py.
Signed-off-by: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
---
src/kimchi/API.json | 10 ++++++++++
src/kimchi/control/storageserver.py | 25 +++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/src/kimchi/API.json b/src/kimchi/API.json
index e135ebb..9c5bb23 100644
--- a/src/kimchi/API.json
+++ b/src/kimchi/API.json
@@ -218,6 +218,16 @@
}
}
},
+ "storagetargets_get_list": {
+ "type": "object",
+ "properties": {
+ "target_type": {
+ "description": "List storage servers of given
type",
+ "type": "string",
+ "pattern": "^netfs$"
+ }
+ }
+ },
"template_update": {
"type": "object",
"properties": {
diff --git a/src/kimchi/control/storageserver.py b/src/kimchi/control/storageserver.py
index 0d4cb05..fbaf898 100644
--- a/src/kimchi/control/storageserver.py
+++ b/src/kimchi/control/storageserver.py
@@ -21,6 +21,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from kimchi.control.base import Collection, Resource
+from kimchi.control.utils import parse_param, validate_params
+from kimchi.control.utils import get_class_name, model_fn
+import kimchi.template
class StorageServers(Collection):
@@ -36,3 +39,25 @@ class StorageServer(Resource):
@property
def data(self):
return self.info
+
+ 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_param()
+ validate_params(params, self, 'get_list')
I'm really wonder
why not just one entry to get the get query params and
validate it?
you have get and validate in father class once _get_resources
Here you get and validate it in child class.
why not in father:
@cherrypy.expose
def index(self, *args):
method = validate_method(('GET', 'POST'))
if method == 'GET':
params = parse_param()
validate_params(params, self, 'get_list')
try:
return self.get(params)
+ 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)
--
Thanks and best regards!
Sheldon Feng(冯少合)<shaohef(a)linux.vnet.ibm.com>
IBM Linux Technology Center