<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 01/21/2014 07:40 AM, Royce Lv wrote:<br>
</div>
<blockquote cite="mid:52DE40AA.50103@linux.vnet.ibm.com" type="cite">On
2014年01月21日 03:51, Aline Manera wrote:
<br>
<blockquote type="cite">On 01/20/2014 07:32 AM,
<a class="moz-txt-link-abbreviated" href="mailto:lvroyce@linux.vnet.ibm.com">lvroyce@linux.vnet.ibm.com</a> wrote:
<br>
<blockquote type="cite">From: Royce Lv
<a class="moz-txt-link-rfc2396E" href="mailto:lvroyce@linux.vnet.ibm.com"><lvroyce@linux.vnet.ibm.com></a>
<br>
<br>
Add json schema to validate mandatory param of target_type,
<br>
also update controller.py.
<br>
Reload the get_list function because we don't need to query
each target.
<br>
<br>
Signed-off-by: Royce Lv <a class="moz-txt-link-rfc2396E" href="mailto:lvroyce@linux.vnet.ibm.com"><lvroyce@linux.vnet.ibm.com></a>
<br>
---
<br>
src/kimchi/API.json | 11 +++++++++++
<br>
src/kimchi/control/storageserver.py | 17 +++++++++++++++++
<br>
2 files changed, 28 insertions(+)
<br>
<br>
diff --git a/src/kimchi/API.json b/src/kimchi/API.json
<br>
index 9b86164..e942824 100644
<br>
--- a/src/kimchi/API.json
<br>
+++ b/src/kimchi/API.json
<br>
@@ -248,6 +248,17 @@
<br>
},
<br>
"additionalProperties": false
<br>
},
<br>
+ "storagetargets_get_list": {
<br>
+ "type": "object",
<br>
+ "properties": {
<br>
+ "_target_type": {
<br>
+ "description": "List storage servers of given type",
<br>
+ "type": "string",
<br>
+ "pattern": "^netfs$"
<br>
+ }
<br>
+ },
<br>
+ "additionalProperties": false
<br>
+ },
<br>
"template_update": {
<br>
"type": "object",
<br>
"properties": {
<br>
diff --git a/src/kimchi/control/storageserver.py
b/src/kimchi/control/storageserver.py
<br>
index 0d4cb05..7f89bcc 100644
<br>
--- a/src/kimchi/control/storageserver.py
<br>
+++ b/src/kimchi/control/storageserver.py
<br>
@@ -21,6 +21,8 @@
<br>
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA
<br>
<br>
from kimchi.control.base import Collection, Resource
<br>
+from kimchi.control.utils import get_class_name, model_fn
<br>
+import kimchi.template
<br>
</blockquote>
<br>
"import ..." block is before "from ... import ..." block
<br>
</blockquote>
ACK
<br>
<blockquote type="cite">
<br>
<blockquote type="cite">
<br>
class StorageServers(Collection):
<br>
@@ -32,7 +34,22 @@ class StorageServers(Collection):
<br>
class StorageServer(Resource):
<br>
def __init__(self, model, ident):
<br>
super(StorageServer, self).__init__(model, ident)
<br>
+ self.storagetargets = StorageTargets(self.model,
self.ident.decode("utf-8"))
<br>
<br>
@property
<br>
def data(self):
<br>
return self.info
<br>
+
<br>
+
<br>
+class StorageTargets(Collection):
<br>
+ def __init__(self, model, server):
<br>
+ super(StorageTargets, self).__init__(model)
<br>
+ self.server = server
<br>
+ self.resource_args = [self.server, ]
<br>
+ self.model_args = [self.server, ]
<br>
+
<br>
</blockquote>
<br>
<blockquote type="cite">+ def get(self, filter_params):
<br>
+ res_list = []
<br>
+ get_list = getattr(self.model, model_fn(self, 'get_list'))
<br>
+ res_list = get_list(*self.model_args, **filter_params)
<br>
+ return kimchi.template.render(get_class_name(self),
res_list)
<br>
</blockquote>
<br>
<br>
All get() logic has already being done in Collection class.
<br>
You don't need to re-implement it again here.
<br>
<br>
</blockquote>
Because StorageTargets does not have resource and cannot iterate
resource lookup().
<br>
<br>
</blockquote>
<br>
<font face="DejaVu Sans Mono">Ok. Thanks</font><br>
</body>
</html>