On 01/21/2014 07:40 AM, Royce Lv wrote:
On 2014年01月21日 03:51, Aline Manera wrote:
> On 01/20/2014 07:32 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,
>> also update controller.py.
>> Reload the get_list function because we don't need to query each
>> target.
>>
>> Signed-off-by: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
>> ---
>> src/kimchi/API.json | 11 +++++++++++
>> src/kimchi/control/storageserver.py | 17 +++++++++++++++++
>> 2 files changed, 28 insertions(+)
>>
>> diff --git a/src/kimchi/API.json b/src/kimchi/API.json
>> index 9b86164..e942824 100644
>> --- a/src/kimchi/API.json
>> +++ b/src/kimchi/API.json
>> @@ -248,6 +248,17 @@
>> },
>> "additionalProperties": false
>> },
>> + "storagetargets_get_list": {
>> + "type": "object",
>> + "properties": {
>> + "_target_type": {
>> + "description": "List storage servers of given type",
>> + "type": "string",
>> + "pattern": "^netfs$"
>> + }
>> + },
>> + "additionalProperties": false
>> + },
>> "template_update": {
>> "type": "object",
>> "properties": {
>> diff --git a/src/kimchi/control/storageserver.py
>> b/src/kimchi/control/storageserver.py
>> index 0d4cb05..7f89bcc 100644
>> --- a/src/kimchi/control/storageserver.py
>> +++ b/src/kimchi/control/storageserver.py
>> @@ -21,6 +21,8 @@
>> # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
>> 02110-1301 USA
>>
>> from kimchi.control.base import Collection, Resource
>> +from kimchi.control.utils import get_class_name, model_fn
>> +import kimchi.template
>
> "import ..." block is before "from ... import ..." block
ACK
>
>>
>> class StorageServers(Collection):
>> @@ -32,7 +34,22 @@ class StorageServers(Collection):
>> class StorageServer(Resource):
>> def __init__(self, model, ident):
>> super(StorageServer, self).__init__(model, ident)
>> + self.storagetargets = StorageTargets(self.model,
>> self.ident.decode("utf-8"))
>>
>> @property
>> def data(self):
>> return self.info
>> +
>> +
>> +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, filter_params):
>> + res_list = []
>> + get_list = getattr(self.model, model_fn(self, 'get_list'))
>> + res_list = get_list(*self.model_args, **filter_params)
>> + return kimchi.template.render(get_class_name(self), res_list)
>
>
> All get() logic has already being done in Collection class.
> You don't need to re-implement it again here.
>
Because StorageTargets does not have resource and cannot iterate
resource lookup().
Ok. Thanks