[Kimchi-devel] [PATCH v2] model/storagetargets: filtering used nfs paths

Daniel H Barboza danielhb at linux.vnet.ibm.com
Thu Aug 21 14:27:37 UTC 2014


On 08/20/2014 12:36 AM, Royce Lv wrote:
> On 2014年08月20日 00:54, Daniel Henrique Barboza wrote:
>> As described in Github issue #354, this patch filters the storage
>> targets list to not show the nfs paths that are in use by an
>> existing NFS pool.
>>
>> Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
>> ---
>>   src/kimchi/model/storagetargets.py | 22 ++++++++++++++++++++++
>>   1 file changed, 22 insertions(+)
>>
>> diff --git a/src/kimchi/model/storagetargets.py 
>> b/src/kimchi/model/storagetargets.py
>> index 6f29a49..3572ac4 100644
>> --- a/src/kimchi/model/storagetargets.py
>> +++ b/src/kimchi/model/storagetargets.py
>> @@ -57,6 +57,28 @@ class StorageTargetsModel(object):
>>                   targets = 
>> self._parse_target_source_result(target_type, ret)
>>
>>               target_list.extend(targets)
>> +
>> +        if 'netfs' in target_types:
> Good catch! But instead of if/else , I think we can use a map for 
> different types of target_type (like iscsi) can be properly filtered.
I'll make the code more generic and able to treat both netfs and iscsi 
pools and send a v3.

Thanks!


>> +            # Get all netfs pools to determine which nfs paths are 
>> in use
>> +            nfs_paths_used = []
>> +            try:
>> +                conn = self.conn.get()
>> +                pools = conn.listAllStoragePools(
>> + libvirt.VIR_CONNECT_LIST_STORAGE_POOLS_NETFS)
>> +                for pool in pools:
>> +                    pool_xml = pool.XMLDesc(0)
>> +                    root = objectify.fromstring(pool_xml)
>> +                    if root.source.dir is not None:
>> + nfs_paths_used.append(root.source.dir.get('path'))
>> +
>> +            except libvirt.libvirtError as e:
>> +                err = "Query storage pool source fails because of %s"
>> +                kimchi_log.warning(err, e.get_error_message())
>> +
>> +            # Filter target_list to not not show the used nfs paths
>> +            target_list = [elem for elem in target_list
>> +                           if elem.get('target') not in nfs_paths_used]
>> +
>>           return target_list
>>
>>       def _get_storage_server_spec(self, **kwargs):
>




More information about the Kimchi-devel mailing list