[PATCHv9 00/10] Support storage targets and servers

From: Royce Lv <lvroyce@linux.vnet.ibm.com> v9>v10, work around ubuntu libvirt problem. v8>v9, split two types of filter params, fix nits v7>v8, address model break, change xml construction to libxml v6>v7, adopt lxml to parse xml, move parse params to get() to avoid duplicate code, fix bugs when one server support multiple target type. v5>v6, change GET param support to cover more scenario of filter collected results. v4>v5, remove storage server list reload function, merge storage server and targets v3>v4, fix inconsistency between doc and json schema v1>v3, fix racing problem, fix style. Royce Lv (10): Support params for GET method Add testcase for GET param Storage server: Update API.md storage server: update controller.py storage server: Update model and mockmodel storage target: Update API.md storage target: Update controller and json schema storage target: Add model support Add showmount function and feature test for libvirt target probe Fix libvirt nfs target probe problem docs/API.md | 37 ++++++++++++++++ src/kimchi/API.json | 22 ++++++++++ src/kimchi/control/base.py | 31 +++++++++++--- src/kimchi/control/storagepools.py | 4 +- src/kimchi/control/storageservers.py | 55 ++++++++++++++++++++++++ src/kimchi/control/storagevolumes.py | 2 +- src/kimchi/featuretests.py | 22 ++++++++++ src/kimchi/mockmodel.py | 30 +++++++++++++ src/kimchi/model.py | 82 +++++++++++++++++++++++++++++++++++- src/kimchi/root.py | 2 + src/kimchi/utils.py | 20 ++++++++- tests/test_rest.py | 23 ++++++++++ 12 files changed, 317 insertions(+), 13 deletions(-) create mode 100644 src/kimchi/control/storageservers.py -- 1.8.1.2

From: Royce Lv <lvroyce@linux.vnet.ibm.com> GET filter parameter will be splited in two types: 1. flag_filter: pass to libvirt api and filter when resource query. flag_filters start with "_" 2. field_filter: take effect in filter out final result. field_filters are keys of dict returned by 'GET' Then we can call it like: GET /collection?filter_field=value Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/control/base.py | 31 ++++++++++++++++++++++++------- src/kimchi/control/storagepools.py | 4 ++-- src/kimchi/control/storagevolumes.py | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py index 185c8d8..55678b1 100644 --- a/src/kimchi/control/base.py +++ b/src/kimchi/control/base.py @@ -212,10 +212,10 @@ class Collection(object): return res.get() - def _get_resources(self): + def _get_resources(self, flag_filter): try: get_list = getattr(self.model, model_fn(self, 'get_list')) - idents = get_list(*self.model_args) + idents = get_list(*self.model_args, **flag_filter) res_list = [] for ident in idents: # internal text, get_list changes ident to unicode for sorted @@ -234,19 +234,36 @@ class Collection(object): args = self.resource_args + [ident.decode("utf-8")] return self.resource(self.model, *args) - def get(self): - resources = self._get_resources() + def filter_data(self, resources, fields_filter): data = [] for res in resources: - data.append(res.data) + if all(key in res.data and res.data[key] == val \ + for key, val in fields_filter.iteritems()): + data.append(res.data) + return data + + def get(self, filter_params): + def _split_filter(params): + flag_filter = dict() + fields_filter = params + for key, val in params.items(): + if key.startswith('_'): + flag_filter[key] = fields_filter.pop(key) + return flag_filter, fields_filter + + flag_filter, fields_filter = _split_filter(filter_params) + resources = self._get_resources(flag_filter) + data = self.filter_data(resources, fields_filter) return kimchi.template.render(get_class_name(self), data) @cherrypy.expose - def index(self, *args): + def index(self, *args, **kwargs): method = validate_method(('GET', 'POST')) if method == 'GET': try: - return self.get() + filter_params = cherrypy.request.params + validate_params(filter_params, self, 'get_list') + return self.get(filter_params) except InvalidOperation, param: error = "Invalid operation: '%s'" % param raise cherrypy.HTTPError(400, error) diff --git a/src/kimchi/control/storagepools.py b/src/kimchi/control/storagepools.py index 06b7196..35e7664 100644 --- a/src/kimchi/control/storagepools.py +++ b/src/kimchi/control/storagepools.py @@ -63,9 +63,9 @@ class StoragePools(Collection): return resp - def _get_resources(self): + def _get_resources(self, filter_params): try: - res_list = super(StoragePools, self)._get_resources() + res_list = super(StoragePools, self)._get_resources(filter_params) # Append reserved pools isos = getattr(self, ISO_POOL_NAME) isos.lookup() diff --git a/src/kimchi/control/storagevolumes.py b/src/kimchi/control/storagevolumes.py index d541807..cd15bcc 100644 --- a/src/kimchi/control/storagevolumes.py +++ b/src/kimchi/control/storagevolumes.py @@ -70,7 +70,7 @@ class IsoVolumes(Collection): super(IsoVolumes, self).__init__(model) self.pool = pool - def get(self): + def get(self, filter_params): res_list = [] try: get_list = getattr(self.model, model_fn(self, 'get_list')) -- 1.8.1.2

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 01/22/2014 02:13 PM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
GET filter parameter will be splited in two types: 1. flag_filter: pass to libvirt api and filter when resource query. flag_filters start with "_" 2. field_filter: take effect in filter out final result. field_filters are keys of dict returned by 'GET' Then we can call it like: GET /collection?filter_field=value
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/control/base.py | 31 ++++++++++++++++++++++++------- src/kimchi/control/storagepools.py | 4 ++-- src/kimchi/control/storagevolumes.py | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py index 185c8d8..55678b1 100644 --- a/src/kimchi/control/base.py +++ b/src/kimchi/control/base.py @@ -212,10 +212,10 @@ class Collection(object):
return res.get()
- def _get_resources(self): + def _get_resources(self, flag_filter): try: get_list = getattr(self.model, model_fn(self, 'get_list')) - idents = get_list(*self.model_args) + idents = get_list(*self.model_args, **flag_filter) res_list = [] for ident in idents: # internal text, get_list changes ident to unicode for sorted @@ -234,19 +234,36 @@ class Collection(object): args = self.resource_args + [ident.decode("utf-8")] return self.resource(self.model, *args)
- def get(self): - resources = self._get_resources() + def filter_data(self, resources, fields_filter): data = [] for res in resources: - data.append(res.data) + if all(key in res.data and res.data[key] == val \ + for key, val in fields_filter.iteritems()): + data.append(res.data) + return data + + def get(self, filter_params): + def _split_filter(params): + flag_filter = dict() + fields_filter = params + for key, val in params.items(): + if key.startswith('_'): + flag_filter[key] = fields_filter.pop(key) + return flag_filter, fields_filter + + flag_filter, fields_filter = _split_filter(filter_params) + resources = self._get_resources(flag_filter) + data = self.filter_data(resources, fields_filter) return kimchi.template.render(get_class_name(self), data)
@cherrypy.expose - def index(self, *args): + def index(self, *args, **kwargs): method = validate_method(('GET', 'POST')) if method == 'GET': try: - return self.get() + filter_params = cherrypy.request.params + validate_params(filter_params, self, 'get_list') + return self.get(filter_params) except InvalidOperation, param: error = "Invalid operation: '%s'" % param raise cherrypy.HTTPError(400, error) diff --git a/src/kimchi/control/storagepools.py b/src/kimchi/control/storagepools.py index 06b7196..35e7664 100644 --- a/src/kimchi/control/storagepools.py +++ b/src/kimchi/control/storagepools.py @@ -63,9 +63,9 @@ class StoragePools(Collection):
return resp
- def _get_resources(self): + def _get_resources(self, filter_params): try: - res_list = super(StoragePools, self)._get_resources() + res_list = super(StoragePools, self)._get_resources(filter_params) # Append reserved pools isos = getattr(self, ISO_POOL_NAME) isos.lookup() diff --git a/src/kimchi/control/storagevolumes.py b/src/kimchi/control/storagevolumes.py index d541807..cd15bcc 100644 --- a/src/kimchi/control/storagevolumes.py +++ b/src/kimchi/control/storagevolumes.py @@ -70,7 +70,7 @@ class IsoVolumes(Collection): super(IsoVolumes, self).__init__(model) self.pool = pool
- def get(self): + def get(self, filter_params): res_list = [] try: get_list = getattr(self.model, model_fn(self, 'get_list'))

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Add a testcase to test GET param passing and demo how GET param work with current model implementation,which means: 1. change the API.json 2. wrap its model implementation to accept parameters Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- tests/test_rest.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_rest.py b/tests/test_rest.py index a8e5842..dd2747b 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -1240,6 +1240,29 @@ class RestTests(unittest.TestCase): self.assertIn('net_recv_rate', stats) self.assertIn('net_sent_rate', stats) + def test_get_param(self): + req = json.dumps({'name': 'test', 'cdrom': '/nonexistent.iso'}) + self.request('/templates', req, 'POST') + + # Create a VM + req = json.dumps({'name': 'test-vm1', 'template': '/templates/test'}) + resp = self.request('/vms', req, 'POST') + self.assertEquals(201, resp.status) + req = json.dumps({'name': 'test-vm2', 'template': '/templates/test'}) + resp = self.request('/vms', req, 'POST') + self.assertEquals(201, resp.status) + + resp = request(host, port, '/vms') + self.assertEquals(200, resp.status) + res = json.loads(resp.read()) + self.assertEquals(2, len(res)) + + resp = request(host, port, '/vms?name=test-vm1') + self.assertEquals(200, resp.status) + res = json.loads(resp.read()) + self.assertEquals(1, len(res)) + self.assertEquals('test-vm1', res[0]['name']) + class HttpsRestTests(RestTests): """ -- 1.8.1.2

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 01/22/2014 02:13 PM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Add a testcase to test GET param passing and demo how GET param work with current model implementation,which means: 1. change the API.json 2. wrap its model implementation to accept parameters
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- tests/test_rest.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
diff --git a/tests/test_rest.py b/tests/test_rest.py index a8e5842..dd2747b 100644 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -1240,6 +1240,29 @@ class RestTests(unittest.TestCase): self.assertIn('net_recv_rate', stats) self.assertIn('net_sent_rate', stats)
+ def test_get_param(self): + req = json.dumps({'name': 'test', 'cdrom': '/nonexistent.iso'}) + self.request('/templates', req, 'POST') + + # Create a VM + req = json.dumps({'name': 'test-vm1', 'template': '/templates/test'}) + resp = self.request('/vms', req, 'POST') + self.assertEquals(201, resp.status) + req = json.dumps({'name': 'test-vm2', 'template': '/templates/test'}) + resp = self.request('/vms', req, 'POST') + self.assertEquals(201, resp.status) + + resp = request(host, port, '/vms') + self.assertEquals(200, resp.status) + res = json.loads(resp.read()) + self.assertEquals(2, len(res)) + + resp = request(host, port, '/vms?name=test-vm1') + self.assertEquals(200, resp.status) + res = json.loads(resp.read()) + self.assertEquals(1, len(res)) + self.assertEquals('test-vm1', res[0]['name']) +
class HttpsRestTests(RestTests): """

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Update API.md to specify storage server api. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- docs/API.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/API.md b/docs/API.md index f872eab..8b1e971 100644 --- a/docs/API.md +++ b/docs/API.md @@ -495,6 +495,29 @@ creation. not tested yet * **POST**: *See Configuration Actions* +**Actions (POST):** + +*No actions defined* + +### Collection: Storage Servers + +**URI:** /storageservers + +**Methods:** + +* **GET**: Retrieve a summarized list of used storage servers. + * Parameters: + * _target_type: Filter server list with given type, currently support 'netfs'. + +### Resource: Storage Server + +**URI:** /storageservers/*:host* + +**Methods:** + +* **GET**: Retrieve description of a Storage Server + * host: IP or host name of storage server + ### Collection: Distros **URI:** /config/distros -- 1.8.1.2

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 01/22/2014 02:13 PM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Update API.md to specify storage server api.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- docs/API.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
diff --git a/docs/API.md b/docs/API.md index f872eab..8b1e971 100644 --- a/docs/API.md +++ b/docs/API.md @@ -495,6 +495,29 @@ creation. not tested yet * **POST**: *See Configuration Actions*
+**Actions (POST):** + +*No actions defined* + +### Collection: Storage Servers + +**URI:** /storageservers + +**Methods:** + +* **GET**: Retrieve a summarized list of used storage servers. + * Parameters: + * _target_type: Filter server list with given type, currently support 'netfs'. + +### Resource: Storage Server + +**URI:** /storageservers/*:host* + +**Methods:** + +* **GET**: Retrieve description of a Storage Server + * host: IP or host name of storage server + ### Collection: Distros
**URI:** /config/distros

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Add storage server collection and resource to report used storage server. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/API.json | 11 ++++++++++ src/kimchi/control/storageservers.py | 41 ++++++++++++++++++++++++++++++++++++ src/kimchi/root.py | 2 ++ 3 files changed, 54 insertions(+) create mode 100644 src/kimchi/control/storageservers.py diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 46818d4..9b86164 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -237,6 +237,17 @@ }, "additionalProperties": false }, + "storageservers_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/storageservers.py b/src/kimchi/control/storageservers.py new file mode 100644 index 0000000..c692fae --- /dev/null +++ b/src/kimchi/control/storageservers.py @@ -0,0 +1,41 @@ +# +# Project Kimchi +# +# Copyright IBM, Corp. 2014 +# +# Authors: +# Royce Lv <lvroyce@linux.vnet.ibm.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# 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 + + +class StorageServers(Collection): + def __init__(self, model): + super(StorageServers, self).__init__(model) + self.resource = StorageServer + + +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 diff --git a/src/kimchi/root.py b/src/kimchi/root.py index 3cc6321..ec531c0 100644 --- a/src/kimchi/root.py +++ b/src/kimchi/root.py @@ -36,6 +36,7 @@ from kimchi.control.interfaces import Interfaces from kimchi.control.networks import Networks from kimchi.control.plugins import Plugins from kimchi.control.storagepools import StoragePools +from kimchi.control.storageserver import StorageServers from kimchi.control.tasks import Tasks from kimchi.control.templates import Templates from kimchi.control.utils import parse_request @@ -60,6 +61,7 @@ class Root(Resource): self.vms = VMs(model) self.templates = Templates(model) self.storagepools = StoragePools(model) + self.storageservers = StorageServers(model) self.interfaces = Interfaces(model) self.networks = Networks(model) self.tasks = Tasks(model) -- 1.8.1.2

On 01/22/2014 02:13 PM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Add storage server collection and resource to report used storage server.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/API.json | 11 ++++++++++ src/kimchi/control/storageservers.py | 41 ++++++++++++++++++++++++++++++++++++ src/kimchi/root.py | 2 ++ 3 files changed, 54 insertions(+) create mode 100644 src/kimchi/control/storageservers.py
diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 46818d4..9b86164 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -237,6 +237,17 @@ }, "additionalProperties": false }, + "storageservers_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/storageservers.py b/src/kimchi/control/storageservers.py new file mode 100644 index 0000000..c692fae --- /dev/null +++ b/src/kimchi/control/storageservers.py @@ -0,0 +1,41 @@ +# +# Project Kimchi +# +# Copyright IBM, Corp. 2014 +# +# Authors: +# Royce Lv <lvroyce@linux.vnet.ibm.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# 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 + + +class StorageServers(Collection): + def __init__(self, model): + super(StorageServers, self).__init__(model) + self.resource = StorageServer + + +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 diff --git a/src/kimchi/root.py b/src/kimchi/root.py index 3cc6321..ec531c0 100644 --- a/src/kimchi/root.py +++ b/src/kimchi/root.py @@ -36,6 +36,7 @@ from kimchi.control.interfaces import Interfaces from kimchi.control.networks import Networks from kimchi.control.plugins import Plugins from kimchi.control.storagepools import StoragePools +from kimchi.control.storageserver import StorageServers
It should be: from kimchi.control.storageservers import StorageServers I will fix it before applying the patch =) So you don't need to send again the patch set
from kimchi.control.tasks import Tasks from kimchi.control.templates import Templates from kimchi.control.utils import parse_request @@ -60,6 +61,7 @@ class Root(Resource): self.vms = VMs(model) self.templates = Templates(model) self.storagepools = StoragePools(model) + self.storageservers = StorageServers(model) self.interfaces = Interfaces(model) self.networks = Networks(model) self.tasks = Tasks(model)

On 01/23/2014 09:01 PM, Aline Manera wrote:
On 01/22/2014 02:13 PM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Add storage server collection and resource to report used storage server.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/API.json | 11 ++++++++++ src/kimchi/control/storageservers.py | 41 ++++++++++++++++++++++++++++++++++++ src/kimchi/root.py | 2 ++ 3 files changed, 54 insertions(+) create mode 100644 src/kimchi/control/storageservers.py
diff --git a/src/kimchi/API.json b/src/kimchi/API.json index 46818d4..9b86164 100644 --- a/src/kimchi/API.json +++ b/src/kimchi/API.json @@ -237,6 +237,17 @@ }, "additionalProperties": false }, + "storageservers_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/storageservers.py b/src/kimchi/control/storageservers.py new file mode 100644 index 0000000..c692fae --- /dev/null +++ b/src/kimchi/control/storageservers.py @@ -0,0 +1,41 @@ +# +# Project Kimchi +# +# Copyright IBM, Corp. 2014 +# +# Authors: +# Royce Lv <lvroyce@linux.vnet.ibm.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# 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 + + +class StorageServers(Collection): + def __init__(self, model): + super(StorageServers, self).__init__(model) + self.resource = StorageServer + + +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 diff --git a/src/kimchi/root.py b/src/kimchi/root.py index 3cc6321..ec531c0 100644 --- a/src/kimchi/root.py +++ b/src/kimchi/root.py @@ -36,6 +36,7 @@ from kimchi.control.interfaces import Interfaces from kimchi.control.networks import Networks from kimchi.control.plugins import Plugins from kimchi.control.storagepools import StoragePools +from kimchi.control.storageserver import StorageServers
It should be:
from kimchi.control.storageservers import StorageServers after my patch, "[PATCH] improve controller" you do not need to touch root.py any more.
I will fix it before applying the patch =) So you don't need to send again the patch set
from kimchi.control.tasks import Tasks from kimchi.control.templates import Templates from kimchi.control.utils import parse_request @@ -60,6 +61,7 @@ class Root(Resource): self.vms = VMs(model) self.templates = Templates(model) self.storagepools = StoragePools(model) + self.storageservers = StorageServers(model) self.interfaces = Interfaces(model) self.networks = Networks(model) self.tasks = Tasks(model)
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
-- Thanks and best regards! Sheldon Feng(???)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Query all storage pool to retrieve storage server we used. If no query param is given, all supported type will be listed. With param given, only specified type of server is listed. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/mockmodel.py | 30 ++++++++++++++++++++++++++++++ src/kimchi/model.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py index 4ef3fa6..9e7dcfd 100644 --- a/src/kimchi/mockmodel.py +++ b/src/kimchi/mockmodel.py @@ -408,6 +408,36 @@ class MockModel(object): iso_volumes.append(res) return iso_volumes + def storageservers_get_list(self, _target_type=None): + # FIXME: When added new storage server support, this needs to be updated + target_type = kimchi.model.STORAGE_SOURCES.keys() \ + if not _target_type else [_target_type] + pools = self.storagepools_get_list() + server_list = [] + for pool in pools: + try: + pool_info = self.storagepool_lookup(pool) + if (pool_info['type'] in target_type and + pool_info['source']['addr'] not in server_list): + server_list.append(pool_info['source']['addr']) + except NotFoundError: + pass + + return server_list + + def storageserver_lookup(self, server): + pools = self.storagepools_get_list() + for pool in pools: + try: + pool_info = self.storagepool_lookup(pool) + if pool_info['source'] and pool_info['source']['addr'] == server: + return dict(host=server) + except NotFoundError: + # Avoid inconsistent pool result because of lease between list and lookup + pass + + raise NotFoundError("storage server %s not used by kimchi" % server) + def dummy_interfaces(self): interfaces = {} ifaces = {"eth1": "nic", "bond0": "bonding", diff --git a/src/kimchi/model.py b/src/kimchi/model.py index ea528c6..67546b8 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -1303,6 +1303,36 @@ class Model(object): else: raise + def storageservers_get_list(self, _target_type=None): + target_type = STORAGE_SOURCES.keys() if not _target_type else [_target_type] + pools = self.storagepools_get_list() + server_list = [] + for pool in pools: + try: + pool_info = self.storagepool_lookup(pool) + if (pool_info['type'] in target_type and + pool_info['source']['addr'] not in server_list): + # Avoid to add same server for multiple times + # if it hosts more than one storage type + server_list.append(pool_info['source']['addr']) + except NotFoundError: + pass + + return server_list + + def storageserver_lookup(self, server): + pools = self.storagepools_get_list() + for pool in pools: + try: + pool_info = self.storagepool_lookup(pool) + if pool_info['source'] and pool_info['source']['addr'] == server: + return dict(host=server) + except NotFoundError: + # Avoid inconsistent pool result because of lease between list and lookup + pass + + raise NotFoundError('server %s does not used by kimchi' % server) + def _get_screenshot(self, vm_uuid): with self.objstore as session: try: -- 1.8.1.2

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 01/22/2014 02:13 PM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Query all storage pool to retrieve storage server we used. If no query param is given, all supported type will be listed. With param given, only specified type of server is listed.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/mockmodel.py | 30 ++++++++++++++++++++++++++++++ src/kimchi/model.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+)
diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py index 4ef3fa6..9e7dcfd 100644 --- a/src/kimchi/mockmodel.py +++ b/src/kimchi/mockmodel.py @@ -408,6 +408,36 @@ class MockModel(object): iso_volumes.append(res) return iso_volumes
+ def storageservers_get_list(self, _target_type=None): + # FIXME: When added new storage server support, this needs to be updated + target_type = kimchi.model.STORAGE_SOURCES.keys() \ + if not _target_type else [_target_type] + pools = self.storagepools_get_list() + server_list = [] + for pool in pools: + try: + pool_info = self.storagepool_lookup(pool) + if (pool_info['type'] in target_type and + pool_info['source']['addr'] not in server_list): + server_list.append(pool_info['source']['addr']) + except NotFoundError: + pass + + return server_list + + def storageserver_lookup(self, server): + pools = self.storagepools_get_list() + for pool in pools: + try: + pool_info = self.storagepool_lookup(pool) + if pool_info['source'] and pool_info['source']['addr'] == server: + return dict(host=server) + except NotFoundError: + # Avoid inconsistent pool result because of lease between list and lookup + pass + + raise NotFoundError("storage server %s not used by kimchi" % server) + def dummy_interfaces(self): interfaces = {} ifaces = {"eth1": "nic", "bond0": "bonding", diff --git a/src/kimchi/model.py b/src/kimchi/model.py index ea528c6..67546b8 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -1303,6 +1303,36 @@ class Model(object): else: raise
+ def storageservers_get_list(self, _target_type=None): + target_type = STORAGE_SOURCES.keys() if not _target_type else [_target_type] + pools = self.storagepools_get_list() + server_list = [] + for pool in pools: + try: + pool_info = self.storagepool_lookup(pool) + if (pool_info['type'] in target_type and + pool_info['source']['addr'] not in server_list): + # Avoid to add same server for multiple times + # if it hosts more than one storage type + server_list.append(pool_info['source']['addr']) + except NotFoundError: + pass + + return server_list + + def storageserver_lookup(self, server): + pools = self.storagepools_get_list() + for pool in pools: + try: + pool_info = self.storagepool_lookup(pool) + if pool_info['source'] and pool_info['source']['addr'] == server: + return dict(host=server) + except NotFoundError: + # Avoid inconsistent pool result because of lease between list and lookup + pass + + raise NotFoundError('server %s does not used by kimchi' % server) + def _get_screenshot(self, vm_uuid): with self.objstore as session: try:

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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/API.md b/docs/API.md index 8b1e971..a86b884 100644 --- a/docs/API.md +++ b/docs/API.md @@ -518,6 +518,20 @@ creation. * **GET**: Retrieve description of a Storage Server * host: IP or host name of storage server +### Collection: Storage Targets + +**URI:** /storageservers/*:name*/storagetargets + +**Methods:** + +* **GET**: Retrieve a list of available storage targets. + * Parameters: + * _target_type: Filter target list with given type, currently support 'netfs'. + * Response: A list with storage targets information. + * host: IP or host name of storage server of this target. + * target_type: Type of storage target, supported: 'nfs'. + * target: Storage target path. + ### Collection: Distros **URI:** /config/distros -- 1.8.1.2

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 01/22/2014 02:13 PM, 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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/docs/API.md b/docs/API.md index 8b1e971..a86b884 100644 --- a/docs/API.md +++ b/docs/API.md @@ -518,6 +518,20 @@ creation. * **GET**: Retrieve description of a Storage Server * host: IP or host name of storage server
+### Collection: Storage Targets + +**URI:** /storageservers/*:name*/storagetargets + +**Methods:** + +* **GET**: Retrieve a list of available storage targets. + * Parameters: + * _target_type: Filter target list with given type, currently support 'netfs'. + * Response: A list with storage targets information. + * host: IP or host name of storage server of this target. + * target_type: Type of storage target, supported: 'nfs'. + * target: Storage target path. + ### 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. Reload the get_list function because we don't need to query each target. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/API.json | 11 +++++++++++ src/kimchi/control/storageservers.py | 14 ++++++++++++++ 2 files changed, 25 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/storageservers.py b/src/kimchi/control/storageservers.py index c692fae..7f89bcc 100644 --- a/src/kimchi/control/storageservers.py +++ b/src/kimchi/control/storageservers.py @@ -39,3 +39,17 @@ class StorageServer(Resource): @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) -- 1.8.1.2

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 01/22/2014 02:13 PM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@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@linux.vnet.ibm.com> --- src/kimchi/API.json | 11 +++++++++++ src/kimchi/control/storageservers.py | 14 ++++++++++++++ 2 files changed, 25 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/storageservers.py b/src/kimchi/control/storageservers.py index c692fae..7f89bcc 100644 --- a/src/kimchi/control/storageservers.py +++ b/src/kimchi/control/storageservers.py @@ -39,3 +39,17 @@ class StorageServer(Resource): @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)

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Construct xml to query storage targets information from storage server. Use lxml to parse result instead of etree. Use lxml to parse target query result. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/kimchi/model.py b/src/kimchi/model.py index 67546b8..c7f063e 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -30,6 +30,7 @@ import ipaddr import json import libvirt import logging +import lxml.etree as ET import os import platform import psutil @@ -46,6 +47,8 @@ import uuid from cherrypy.process.plugins import BackgroundTask from cherrypy.process.plugins import SimplePlugin from collections import defaultdict +from lxml import objectify +from lxml.builder import E from xml.etree import ElementTree @@ -1333,6 +1336,24 @@ class Model(object): raise NotFoundError('server %s does not used by kimchi' % server) + def storagetargets_get_list(self, storage_server, _target_type=None): + target_types = STORAGE_SOURCES.keys() if not _target_type else [_target_type] + target_list = list() + + for target_type in target_types: + 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()) + continue + + target_list.extend(_parse_target_source_result(target_type, ret)) + return target_list + def _get_screenshot(self, vm_uuid): with self.objstore as session: try: @@ -1543,6 +1564,30 @@ class LibvirtVMScreenshot(VMScreenshot): os.close(fd) +def _parse_target_source_result(target_type, xml_str): + root = objectify.fromstring(xml_str) + ret = [] + for source in root.getchildren(): + if target_type == 'netfs': + host_name = source.host.get('name') + target_path = source.dir.get('path') + type = source.format.get('type') + ret.append(dict(host=host_name, target_type=type, target=target_path)) + return ret + + +def _get_storage_server_spec(**kwargs): + # Required parameters: + # server: + # target_type: + extra_args = [] + if kwargs['target_type'] == 'netfs': + extra_args.append(E.format(type='nfs')) + obj = E.source(E.host(name=kwargs['server']), *extra_args) + xml = ET.tostring(obj) + return xml + + class StoragePoolDef(object): @classmethod def create(cls, poolArgs): -- 1.8.1.2

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 01/22/2014 02:13 PM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Construct xml to query storage targets information from storage server. Use lxml to parse result instead of etree. Use lxml to parse target query result.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
diff --git a/src/kimchi/model.py b/src/kimchi/model.py index 67546b8..c7f063e 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -30,6 +30,7 @@ import ipaddr import json import libvirt import logging +import lxml.etree as ET import os import platform import psutil @@ -46,6 +47,8 @@ import uuid from cherrypy.process.plugins import BackgroundTask from cherrypy.process.plugins import SimplePlugin from collections import defaultdict +from lxml import objectify +from lxml.builder import E from xml.etree import ElementTree
@@ -1333,6 +1336,24 @@ class Model(object):
raise NotFoundError('server %s does not used by kimchi' % server)
+ def storagetargets_get_list(self, storage_server, _target_type=None): + target_types = STORAGE_SOURCES.keys() if not _target_type else [_target_type] + target_list = list() + + for target_type in target_types: + 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()) + continue + + target_list.extend(_parse_target_source_result(target_type, ret)) + return target_list + def _get_screenshot(self, vm_uuid): with self.objstore as session: try: @@ -1543,6 +1564,30 @@ class LibvirtVMScreenshot(VMScreenshot): os.close(fd)
+def _parse_target_source_result(target_type, xml_str): + root = objectify.fromstring(xml_str) + ret = [] + for source in root.getchildren(): + if target_type == 'netfs': + host_name = source.host.get('name') + target_path = source.dir.get('path') + type = source.format.get('type') + ret.append(dict(host=host_name, target_type=type, target=target_path)) + return ret + + +def _get_storage_server_spec(**kwargs): + # Required parameters: + # server: + # target_type: + extra_args = [] + if kwargs['target_type'] == 'netfs': + extra_args.append(E.format(type='nfs')) + obj = E.source(E.host(name=kwargs['server']), *extra_args) + xml = ET.tostring(obj) + return xml + + class StoragePoolDef(object): @classmethod def create(cls, poolArgs):

From: Royce Lv <lvroyce@linux.vnet.ibm.com> Add nfs showmount cmd and parse its output, set timeout to be 10s. With bug https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1264955, Ubuntu libvirt run find-storage-pool-sources return error with error code 38, generic system call error. While when server does not export any path, it returns error code 1, internal error. Leverage this to determine whether libvirt works right with target probe. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/featuretests.py | 22 ++++++++++++++++++++++ src/kimchi/utils.py | 20 ++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py index a5755a2..32ad2ec 100644 --- a/src/kimchi/featuretests.py +++ b/src/kimchi/featuretests.py @@ -22,11 +22,15 @@ import cherrypy import libvirt +import lxml.etree as ET import os import subprocess import threading +from lxml.builder import E + + from kimchi import config @@ -70,6 +74,24 @@ class FeatureTests(object): conn is None or conn.close() @staticmethod + def libvirt_support_nfs_probe(): + def _get_xml(): + obj = E.source(E.host(name='localhost'), E.format(type='nfs')) + xml = ET.tostring(obj) + return xml + try: + conn = libvirt.open('qemu:///system') + ret = conn.findStoragePoolSources('netfs', _get_xml(), 0) + except libvirt.libvirtError as e: + if e.get_error_code() == 38: + # if libvirt cannot find showmount, + # it returns 38--general system call failure + return False + finally: + conn is None or conn.close() + return True + + @staticmethod def qemu_supports_iso_stream(): cmd = "qemu-io -r http://127.0.0.1:%d/images/icon-fedora.png \ -c 'read -v 0 512'" % cherrypy.server.socket_port diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py index 5d6e8ea..c7ececf 100644 --- a/src/kimchi/utils.py +++ b/src/kimchi/utils.py @@ -159,6 +159,22 @@ def run_command(cmd, timeout=None): def parse_cmd_output(output, output_items): res = [] for line in output.split("\n"): - res.append(dict(zip(output_items, line.split()))) - + if line: + res.append(dict(zip(output_items, line.split()))) return res + + +def patch_find_nfs_target(nfs_server): + cmd = ["showmount", "--no-headers", "--exports", nfs_server] + try: + out = run_command(cmd, 10)[0] + except TimeoutExpired: + kimchi_log.warning("server %s query timeout, may not have any path exported", + storage_server) + return list() + + targets = parse_cmd_output(out, output_items = ['target']) + for target in targets: + target['type'] = 'nfs' + target['host_name'] = nfs_server + return targets -- 1.8.1.2

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 01/22/2014 02:13 PM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
Add nfs showmount cmd and parse its output, set timeout to be 10s. With bug https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1264955, Ubuntu libvirt run find-storage-pool-sources return error with error code 38, generic system call error. While when server does not export any path, it returns error code 1, internal error. Leverage this to determine whether libvirt works right with target probe.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/featuretests.py | 22 ++++++++++++++++++++++ src/kimchi/utils.py | 20 ++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/featuretests.py b/src/kimchi/featuretests.py index a5755a2..32ad2ec 100644 --- a/src/kimchi/featuretests.py +++ b/src/kimchi/featuretests.py @@ -22,11 +22,15 @@
import cherrypy import libvirt +import lxml.etree as ET import os import subprocess import threading
+from lxml.builder import E + + from kimchi import config
@@ -70,6 +74,24 @@ class FeatureTests(object): conn is None or conn.close()
@staticmethod + def libvirt_support_nfs_probe(): + def _get_xml(): + obj = E.source(E.host(name='localhost'), E.format(type='nfs')) + xml = ET.tostring(obj) + return xml + try: + conn = libvirt.open('qemu:///system') + ret = conn.findStoragePoolSources('netfs', _get_xml(), 0) + except libvirt.libvirtError as e: + if e.get_error_code() == 38: + # if libvirt cannot find showmount, + # it returns 38--general system call failure + return False + finally: + conn is None or conn.close() + return True + + @staticmethod def qemu_supports_iso_stream(): cmd = "qemu-io -r http://127.0.0.1:%d/images/icon-fedora.png \ -c 'read -v 0 512'" % cherrypy.server.socket_port diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py index 5d6e8ea..c7ececf 100644 --- a/src/kimchi/utils.py +++ b/src/kimchi/utils.py @@ -159,6 +159,22 @@ def run_command(cmd, timeout=None): def parse_cmd_output(output, output_items): res = [] for line in output.split("\n"): - res.append(dict(zip(output_items, line.split()))) - + if line: + res.append(dict(zip(output_items, line.split()))) return res + + +def patch_find_nfs_target(nfs_server): + cmd = ["showmount", "--no-headers", "--exports", nfs_server] + try: + out = run_command(cmd, 10)[0] + except TimeoutExpired: + kimchi_log.warning("server %s query timeout, may not have any path exported", + storage_server) + return list() + + targets = parse_cmd_output(out, output_items = ['target']) + for target in targets: + target['type'] = 'nfs' + target['host_name'] = nfs_server + return targets

From: Royce Lv <lvroyce@linux.vnet.ibm.com> If libvirt does not support nfs target probe, run command directly, otherwise parse libvirt result. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/kimchi/model.py b/src/kimchi/model.py index c7f063e..51a4427 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -76,7 +76,7 @@ from kimchi.rollbackcontext import RollbackContext from kimchi.scan import Scanner from kimchi.screenshot import VMScreenshot from kimchi.utils import get_enabled_plugins, is_digit, kimchi_log -from kimchi.utils import run_command, parse_cmd_output +from kimchi.utils import run_command, parse_cmd_output, patch_find_nfs_target from kimchi.vmtemplate import VMTemplate @@ -231,6 +231,7 @@ class Model(object): kimchi_log.info("*** Running feature tests ***") self.qemu_stream = FeatureTests.qemu_supports_iso_stream() self.qemu_stream_dns = FeatureTests.qemu_iso_stream_dns() + self.nfs_target_probe = FeatureTests.libvirt_support_nfs_probe() self.libvirt_stream_protocols = [] for p in ['http', 'https', 'ftp', 'ftps', 'tftp']: @@ -1341,17 +1342,21 @@ class Model(object): target_list = list() for target_type in target_types: - xml = _get_storage_server_spec(server=storage_server, target_type=target_type) - conn = self.conn.get() + if not self.nfs_target_probe and target_type == 'netfs': + targets = patch_find_nfs_target(storage_server) + else: + 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()) - continue + 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()) + continue + targets = _parse_target_source_result(target_type, ret) - target_list.extend(_parse_target_source_result(target_type, ret)) + target_list.extend(targets) return target_list def _get_screenshot(self, vm_uuid): -- 1.8.1.2

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 01/22/2014 02:13 PM, lvroyce@linux.vnet.ibm.com wrote:
From: Royce Lv <lvroyce@linux.vnet.ibm.com>
If libvirt does not support nfs target probe, run command directly, otherwise parse libvirt result.
Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- src/kimchi/model.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/src/kimchi/model.py b/src/kimchi/model.py index c7f063e..51a4427 100644 --- a/src/kimchi/model.py +++ b/src/kimchi/model.py @@ -76,7 +76,7 @@ from kimchi.rollbackcontext import RollbackContext from kimchi.scan import Scanner from kimchi.screenshot import VMScreenshot from kimchi.utils import get_enabled_plugins, is_digit, kimchi_log -from kimchi.utils import run_command, parse_cmd_output +from kimchi.utils import run_command, parse_cmd_output, patch_find_nfs_target from kimchi.vmtemplate import VMTemplate
@@ -231,6 +231,7 @@ class Model(object): kimchi_log.info("*** Running feature tests ***") self.qemu_stream = FeatureTests.qemu_supports_iso_stream() self.qemu_stream_dns = FeatureTests.qemu_iso_stream_dns() + self.nfs_target_probe = FeatureTests.libvirt_support_nfs_probe()
self.libvirt_stream_protocols = [] for p in ['http', 'https', 'ftp', 'ftps', 'tftp']: @@ -1341,17 +1342,21 @@ class Model(object): target_list = list()
for target_type in target_types: - xml = _get_storage_server_spec(server=storage_server, target_type=target_type) - conn = self.conn.get() + if not self.nfs_target_probe and target_type == 'netfs': + targets = patch_find_nfs_target(storage_server) + else: + 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()) - continue + 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()) + continue + targets = _parse_target_source_result(target_type, ret)
- target_list.extend(_parse_target_source_result(target_type, ret)) + target_list.extend(targets) return target_list
def _get_screenshot(self, vm_uuid):
participants (3)
-
Aline Manera
-
lvroyce@linux.vnet.ibm.com
-
Sheldon