Martin Polednik has uploaded a new change for review. Change subject: hostdev: expose parameters needed to support hotunplug ......................................................................
hostdev: expose parameters needed to support hotunplug Change-Id: I09e879051b1d47e48e9ae73c1f7d9bfbea8f1237 Signed-off-by: Martin Polednik <mpoled...@redhat.com> --- M vdsm/virt/vmdevices/hostdevice.py 1 file changed, 30 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/39/54939/1 diff --git a/vdsm/virt/vmdevices/hostdevice.py b/vdsm/virt/vmdevices/hostdevice.py index 37aff3d..3a5a719 100644 --- a/vdsm/virt/vmdevices/hostdevice.py +++ b/vdsm/virt/vmdevices/hostdevice.py @@ -18,6 +18,8 @@ # Refer to the README and COPYING files for full details of the license # +import xml.etree.ElementTree as ET + from vdsm import utils from vdsm.hostdev import get_device_params, detach_detachable, \ CAPABILITY_TO_XML_ATTR @@ -26,13 +28,15 @@ class HostDevice(core.Base): - __slots__ = ('address', 'hostAddress', 'bootOrder', '_deviceParams') + __slots__ = ('address', 'hostAddress', 'bootOrder', '_deviceParams', + 'name') def __init__(self, conf, log, **kwargs): super(HostDevice, self).__init__(conf, log, **kwargs) self._deviceParams = get_device_params(self.device) self.hostAddress = self._deviceParams.get('address') + self.name = self.device def detach(self): """ @@ -41,6 +45,31 @@ """ self._deviceParams = detach_detachable(self.device) + @property + def _xpath(self): + """ + Returns xpath to the device in libvirt dom xml + The path is relative to the root element + """ + def _padding(key): + if CAPABILITY_TO_XML_ATTR[ + self._deviceParams['capability']] == 'pci': + if key == 'domain': + return {'base': '0x', 'padding': '04'} + if key == 'function': + return {'base': '0x', 'padding': ''} + return {'base': '0x', 'padding': '02'} + return {'base': '', 'padding': ''} + + return ('./devices/hostdev/source/address{}'.format( + ''.join(['[@{key}=\'{base}{value:{padding}}\']'.format( + key=key, value=int(value), **_padding(key)) for + key, value in self.hostAddress.items()]))) + + def is_attached_to(self, xml_string): + dom = ET.fromstring(xml_string) + return bool(dom.findall(self._xpath)) + def getXML(self): """ Create domxml for a host device. -- To view, visit https://gerrit.ovirt.org/54939 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I09e879051b1d47e48e9ae73c1f7d9bfbea8f1237 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Martin Polednik <mpoled...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches