[Kimchi-devel] [PATCHv5 8/8] storage target: Add model support

Sheldon shaohef at linux.vnet.ibm.com
Tue Jan 7 13:42:05 UTC 2014


On 01/07/2014 05:43 PM, lvroyce at linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>
> Construct xml to query storage targets information from
> storage server.
>
> Signed-off-by: Royce Lv <lvroyce at 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 cc9d640..834bf85 100644
> --- a/src/kimchi/model.py
> +++ b/src/kimchi/model.py
> @@ -1263,6 +1263,24 @@ class Model(object):
>                   pass
>           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:
> @@ -1473,6 +1491,36 @@ class LibvirtVMScreenshot(VMScreenshot):
>               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]
so for netfs, the target source is "dir".
what about iscsi or gluster?
> +        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
> +
> +
>   class StoragePoolDef(object):
>       @classmethod
>       def create(cls, poolArgs):


-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center




More information about the Kimchi-devel mailing list