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

Aline Manera alinefm at linux.vnet.ibm.com
Tue Jan 21 16:37:32 UTC 2014


On 01/21/2014 12:02 AM, zhoumeina wrote:
> On 01/21/2014 04:25 AM, Aline Manera wrote:
>>
>> The patch looks good.
>>
>> But we need to care about Ubuntu issue.
>>
>> There are 2 possible solutions for that:
>>
>> 1) instead of using libvirt to discover storage targets we always use 
>> the commands directly: showmount and iscsiadm
> Are there anyone can explain the davantage and disavantage between 
> libvirt and use commands directly?

Hi Meina,

 From my view, the advantage for using libvirt is we don't need to 
verify the "target_type" value in order to take an action.
Libvirt only expects a xml and it returns the values for us.

For other hand, we can eliminate the libvirt level and run the commands 
direclty.

>>
>> 2) create feature tests to identify the libvirt problem and if so use 
>> the commands directly only in case of failure
>>
>> Checking the libvirt code it uses showmount and iscsiadm internally:
>>
>> /usr/sbin/showmount --no-headers --exports localhost
>> /usr/sbin/iscsiadm --mode discovery --type sendtargets --portal 
>> localhost:3260,1
>>
>> So I tend to prefer the solution 1.
>>
>> Anyone else would like to join the discussion?
>>
>> On 01/20/2014 07:32 AM, 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.
>>> Use lxml to parse result instead of etree.
>>> Use lxml to parse target query result.
>>>
>>> Signed-off-by: Royce Lv <lvroyce at 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 6b009c3..65f1b83 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
>>> @@ -45,6 +46,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
>>>
>>>
>>> @@ -1330,6 +1333,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:
>>> @@ -1540,6 +1561,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):
>>
>> _______________________________________________
>> Kimchi-devel mailing list
>> Kimchi-devel at ovirt.org
>> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>>
>




More information about the Kimchi-devel mailing list