[Kimchi-devel] [PATCH] model.host: changing listDevices() to listAllDevices()
Daniel Henrique Barboza
danielhb at linux.vnet.ibm.com
Fri Aug 29 19:49:12 UTC 2014
The method listDevices() has unexpected behavior in certain
situations and architectures. According the libvirt API,
listAllDevices() delivers more control over the results and
it does not present the same problems.
For those reasons, this commit changes all the occurences of
listDevices() to use listAllDevices() instead.
Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
---
src/kimchi/model/host.py | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
index 39f45d8..553ad7c 100644
--- a/src/kimchi/model/host.py
+++ b/src/kimchi/model/host.py
@@ -18,6 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import grp
+import libvirt
import os
import time
import platform
@@ -277,31 +278,45 @@ class PartitionModel(object):
class DevicesModel(object):
def __init__(self, **kargs):
self.conn = kargs['conn']
+ self.cap_map = \
+ {'fc_host': libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST,
+ 'net': libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET,
+ 'pci': libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV,
+ 'scsi': libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI,
+ 'scsi_host': libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST,
+ 'storage': libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE,
+ 'usb_device': libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV,
+ 'usb':
+ libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE}
def get_list(self, _cap=None):
+ if _cap == 'fc_host':
+ return self._get_devices_fc_host()
+ return self._get_devices_with_capability(_cap)
+
+ def _get_devices_with_capability(self, cap):
conn = self.conn.get()
- if _cap is None:
- dev_names = [name.name() for name in conn.listAllDevices(0)]
- elif _cap == 'fc_host':
- dev_names = self._get_devices_fc_host()
+ if cap is None:
+ cap_flag = 0
else:
- # Get devices with required capability
- dev_names = conn.listDevices(_cap, 0)
- return dev_names
+ cap_flag = self.cap_map.get(cap)
+ if cap_flag is None:
+ return []
+ return [name.name() for name in conn.listAllDevices(cap_flag)]
def _get_devices_fc_host(self):
conn = self.conn.get()
# Libvirt < 1.0.5 does not support fc_host capability
if not CapabilitiesModel().fc_host_support:
ret = []
- scsi_hosts = conn.listDevices('scsi_host', 0)
+ scsi_hosts = self._get_devices_with_capability('scsi_host')
for host in scsi_hosts:
xml = conn.nodeDeviceLookupByName(host).XMLDesc(0)
path = '/device/capability/capability/@type'
if 'fc_host' in xmlutils.xpath_get_text(xml, path):
ret.append(host)
return ret
- return conn.listDevices('fc_host', 0)
+ return self._get_devices_with_capability('fc_host')
class DeviceModel(object):
--
1.8.3.1
More information about the Kimchi-devel
mailing list