On 2013年12月31日 03:28, Aline Manera wrote:
On 12/30/2013 12:17 AM, lvroyce(a)linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
>
> Add storage server collection and resource to report
> used storage server.
>
> Signed-off-by: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
> ---
> src/kimchi/API.json | 11 +++++++++++
> src/kimchi/controller.py | 17 +++++++++++++++++
> src/kimchi/root.py | 1 +
> 3 files changed, 29 insertions(+)
>
> diff --git a/src/kimchi/API.json b/src/kimchi/API.json
> index 7b90826..29d8172 100644
> --- a/src/kimchi/API.json
> +++ b/src/kimchi/API.json
> @@ -205,6 +205,17 @@
> }
> },
> "additionalProperties": false
> + },
> + "storageservers_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 c99a811..bdd3cab 100644
> --- a/src/kimchi/controller.py
> +++ b/src/kimchi/controller.py
> @@ -647,6 +647,23 @@ class DebugReport(Resource):
> 'time': self.info['ctime']}
>
>
> +class StorageServers(Collection):
> + def __init__(self, model):
> + super(StorageServers, self).__init__(model)
> + self.resource = StorageServer
> +
> + 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)
> +
I didn't understand why it is needed as you have already changed
Collection._get_resources() to use query parameters.
The change in Collection._get_resources() should be enough and work
for any collection
:) Glad you notice this, I only exposed /storageservers/
collection
query and server itself does not have any data to return.
Because each server may serve as multiple kinds of server(iscsi, nfs,
gluster,etc at the same time). So I move target information to a single
collection called storagetargets.
So change in collection is to support generic GET params and since we
have several scenario to use it(e.g. interface type query) I wrote that
and demo with a test of the impl.
> +
> +class StorageServer(Resource):
> + pass
> +
> class Config(Resource):
> def __init__(self, model, id=None):
> super(Config, self).__init__(model, id)
> diff --git a/src/kimchi/root.py b/src/kimchi/root.py
> index c43897c..0f80785 100644
> --- a/src/kimchi/root.py
> +++ b/src/kimchi/root.py
> @@ -67,6 +67,7 @@ class Root(controller.Resource):
> self.logout = controller.logout
> self.debugreports = controller.DebugReports(model)
> self.plugins = controller.Plugins(model)
> + self.storageservers = controller.StorageServers(model)
> self.api_schema = json.load(open(get_api_schema_file()))
>
> def get(self):