On 2014年01月18日 02:48, Aline Manera wrote:
On 01/14/2014 01:48 PM, lvroyce0210(a)gmail.com wrote:
> From: Royce Lv <lvroyce(a)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(a)linux.vnet.ibm.com>
> ---
> src/kimchi/model.py | 48
> ++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 48 insertions(+)
>
> diff --git a/src/kimchi/model.py b/src/kimchi/model.py
> index 3207e72..c0d82eb 100644
> --- a/src/kimchi/model.py
> +++ b/src/kimchi/model.py
> @@ -45,6 +45,7 @@ import uuid
> from cherrypy.process.plugins import BackgroundTask
> from cherrypy.process.plugins import SimplePlugin
> from collections import defaultdict
> +from lxml import objectify
> from xml.etree import ElementTree
>
>
> @@ -1322,6 +1323,24 @@ class Model(object):
>
> raise NotFoundError
>
> + 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:
> @@ -1532,6 +1551,35 @@ 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))
You need to add which parameters returned in API
I agree, normally, we list the get
list returned parameter under the API.md.
But now, as added GET accept parameter, I added that in API.md, so the
API.md parameter and response need to be refactored.
I will do it in a single patch if you agree.
> + 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
> +
> +
> class StoragePoolDef(object):
> @classmethod
> def create(cls, poolArgs):