[PATCHv2 0/3] Storage targets support

From: Royce Lv <lvroyce@linux.vnet.ibm.com> v1>v2, when showmount got no result, instead of fail the request, return empty list to user. NOTE: this patchset depends on storage server support patchset. Tested in Fedora 19, due to libvirt bug, ubuntu 13.10 cannot be tested, fixing. Usage: GET /storageservers/<ip or hostname>/storagetargets?target_type=netfs Royce Lv (3): storage target: Update API.md storage target: Update controller and json schema storage target: Add model support docs/API.md | 9 +++++++++ src/kimchi/API.json | 11 +++++++++++ src/kimchi/controller.py | 30 ++++++++++++++++++++++++++++-- src/kimchi/model.py | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) -- 1.8.1.2

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Add colleciton of storage targets to API.md. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- docs/API.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/API.md b/docs/API.md index ad58889..8a7228b 100644 --- a/docs/API.md +++ b/docs/API.md @@ -453,6 +453,15 @@ creation. * **GET**: Retrieve a summarized list of used storage servers. * target_type: Filter server list with given type, currently support 'netfs'. +### Collection: Storage Targets + +**URI:** /storageservers/*:name*/storagetargets + +**Methods:** + +* **GET**: Retrieve a list of available storage targets. + * target_type: Filter target list with given type, currently support 'netfs'. + ### Collection: Distros **URI:** /config/distros -- 1.8.1.2

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 12/30/2013 05:24 AM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Add colleciton of storage targets to API.md.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- docs/API.md | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/docs/API.md b/docs/API.md index ad58889..8a7228b 100644 --- a/docs/API.md +++ b/docs/API.md @@ -453,6 +453,15 @@ creation. * **GET**: Retrieve a summarized list of used storage servers. * target_type: Filter server list with given type, currently support 'netfs'.
+### Collection: Storage Targets + +**URI:** /storageservers/*:name*/storagetargets + +**Methods:** + +* **GET**: Retrieve a list of available storage targets. + * target_type: Filter target list with given type, currently support 'netfs'. + ### Collection: Distros
**URI:** /config/distros

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Add json schema to validate mandatory param of target_type, also update controller.py. Signed-off-by: Royce Lv <lvroyce@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) class Config(Resource): def __init__(self, model, id=None): -- 1.8.1.2

On 12/30/2013 05:24 AM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@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@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):

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Construct xml to query storage targets information from storage server. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/kimchi/model.py b/src/kimchi/model.py index 20f68f6..f79dc37 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -1233,6 +1233,20 @@ class Model(object): return server_list + def storagetargets_get_list(self, storage_server, target_type): + xml = _get_storage_server_spec(server=storage_server, target_type=target_type) + conn = self.conn.get() + + try: + ret = conn.findStoragePoolSources(target_type, xml, 0) + except libvirt.libvirtError as e: + kimchi_log.warning("Query storage pool source fails because of %s", + e.get_error_message()) + return list() + + target_list = _parse_target_source_result(target_type, ret) + return target_list + def _get_screenshot(self, vm_uuid): with self.objstore as session: try: @@ -1442,6 +1456,34 @@ class LibvirtVMScreenshot(VMScreenshot): finally: os.close(fd) +def _parse_target_source_result(target_type, xml_str): + root = ElementTree.fromstring(xml_str) + ret = [] + for source in root.getchildren(): + if target_type == 'netfs': + host_name = source.find('host').attrib.values()[0] + target_path = source.find('dir').attrib.values()[0] + type = source.find('format').attrib.values()[0] + ret.append(dict(host=host_name, type=type, target=target_path)) + + return ret + +def _get_storage_server_spec(**kwargs): + # Required parameters: + # server: + # target_type: + if kwargs['target_type'] == 'netfs': + kwargs['format_type'] = """<format type='nfs'/>""" + else: + kwargs['format_type'] = "" + xml = """ + <source> + <host name='%(server)s'/> + %(format_type)s + </source> + """ % kwargs + return xml + def _get_pool_xml(**kwargs): # Required parameters # name: -- 1.8.1.2

On 2013年12月30日 15:24, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
v1>v2, when showmount got no result, instead of fail the request, return empty list to user. NOTE: this patchset depends on storage server support patchset. Tested in Fedora 19, due to libvirt bug, ubuntu 13.10 cannot be tested, fixing. Due to Ubuntu bug of libvirt (showmount PATH is not properly configured when build), I report a bug in Ubuntu: https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1264955 If it cannot be back ported by our next release, I will provide a work around for it.
Usage: GET /storageservers/<ip or hostname>/storagetargets?target_type=netfs
Royce Lv (3): storage target: Update API.md storage target: Update controller and json schema storage target: Add model support
docs/API.md | 9 +++++++++ src/kimchi/API.json | 11 +++++++++++ src/kimchi/controller.py | 30 ++++++++++++++++++++++++++++-- src/kimchi/model.py | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-)

Next time, send a single patch to expose storage server and its sources paths. On 12/30/2013 05:24 AM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
v1>v2, when showmount got no result, instead of fail the request, return empty list to user. NOTE: this patchset depends on storage server support patchset. Tested in Fedora 19, due to libvirt bug, ubuntu 13.10 cannot be tested, fixing.
Usage: GET /storageservers/<ip or hostname>/storagetargets?target_type=netfs
Royce Lv (3): storage target: Update API.md storage target: Update controller and json schema storage target: Add model support
docs/API.md | 9 +++++++++ src/kimchi/API.json | 11 +++++++++++ src/kimchi/controller.py | 30 ++++++++++++++++++++++++++++-- src/kimchi/model.py | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-)
participants (3)
-
Aline Manera
-
lvroyce@linux.vnet.ibm.com
-
Royce Lv