The last changes in the file didn't consider the case where
the fc_host capability isn't implemented by libvirt < 1.0.5
(such as RHEL6 distros). This patch fixes a crash that occurs
in such ocasions.
Signed-off-by: Daniel Henrique Barboza <danielhb(a)linux.vnet.ibm.com>
---
src/kimchi/model/host.py | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
index 553ad7c..4637b1c 100644
--- a/src/kimchi/model/host.py
+++ b/src/kimchi/model/host.py
@@ -279,8 +279,7 @@ 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,
+ {'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,
@@ -288,6 +287,15 @@ class DevicesModel(object):
'usb_device': libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV,
'usb':
libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE}
+ # TODO: when no longer supporting Libvirt < 1.0.5 distros
+ # (like RHEL6) remove this verification and insert the
+ # key 'fc_host' with the libvirt variable in the hash
+ # declaration above.
+ try:
+ self.cap_map['fc_host'] = \
+ libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST
+ except AttributeError:
+ self.cap_map['fc_host'] = None
def get_list(self, _cap=None):
if _cap == 'fc_host':
@@ -316,6 +324,12 @@ class DevicesModel(object):
if 'fc_host' in xmlutils.xpath_get_text(xml, path):
ret.append(host)
return ret
+ # Double verification to catch the case where the libvirt
+ # supports fc_host but does not, for some reason, recognize
+ # the libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST
+ # attribute.
+ if not self.cap_map['fc_host']:
+ return conn.listDevices('fc_host', 0)
return self._get_devices_with_capability('fc_host')
--
1.8.3.1