Francesco Romani has uploaded a new change for review. Change subject: vm: xml: add method to extract all the channels ......................................................................
vm: xml: add method to extract all the channels The VM code needs to iterate on all the agent channels to possibly fix the links. However, it doesn't need, nor should to directly parse the XML again, since all the XML-related processing should happen, for the greatest extent as possibile, into the vmxml module, This patch is another step on that direction. Please note that this patch mostly moves code around. More aggressive refactoring is planned for future work. Change-Id: I145363ee150b3ab4e527af38c1a232431757acb1 Signed-off-by: Francesco Romani <[email protected]> --- M vdsm/virt/vm.py M vdsm/virt/vmxml.py 2 files changed, 17 insertions(+), 12 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/50/31450/1 diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py index 1e8e7d2..8f6ead4 100644 --- a/vdsm/virt/vm.py +++ b/vdsm/virt/vm.py @@ -2791,18 +2791,7 @@ This is necessary to prevent incoming migrations, restoring of VMs and the upgrade of VDSM with running VMs to fail on this. """ - agentChannelXml = _domParseStr(self._lastXMLDesc).childNodes[0]. \ - getElementsByTagName('devices')[0]. \ - getElementsByTagName('channel') - for channel in agentChannelXml: - try: - name = channel.getElementsByTagName('target')[0].\ - getAttribute('name') - path = channel.getElementsByTagName('source')[0].\ - getAttribute('path') - except IndexError: - continue - + for name, path in vmxml.all_channels(self._lastXMLDesc): if name not in _AGENT_CHANNEL_DEVICES: continue diff --git a/vdsm/virt/vmxml.py b/vdsm/virt/vmxml.py index 802be33..79bca11 100644 --- a/vdsm/virt/vmxml.py +++ b/vdsm/virt/vmxml.py @@ -43,6 +43,22 @@ return False +def all_channels(domXML): + domObj = xml.dom.minidom.parseString(domXML) + for channel in domObj.childNodes[0]. \ + getElementsByTagName('devices')[0]. \ + getElementsByTagName('channel'): + try: + name = channel.getElementsByTagName('target')[0].\ + getAttribute('name') + path = channel.getElementsByTagName('source')[0].\ + getAttribute('path') + except IndexError: + continue + else: + yield name, path + + def all_devices(domXML): domObj = xml.dom.minidom.parseString(domXML) devices = domObj.childNodes[0].getElementsByTagName('devices')[0] -- To view, visit http://gerrit.ovirt.org/31450 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I145363ee150b3ab4e527af38c1a232431757acb1 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Francesco Romani <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
