Change in vdsm[master]: vm: add getMetadata helper
fromani at redhat.com
fromani at redhat.com
Thu Aug 7 14:35:17 UTC 2014
Francesco Romani has uploaded a new change for review.
Change subject: vm: add getMetadata helper
......................................................................
vm: add getMetadata helper
introduce a getMetadata helper method to get the
libvirt domain metadata xml.
This factors out the common code to deal with the fact
we can't have yet a hard dependency to make sure
libvirt supports the metadata.
Change-Id: If29df44b26870884eb2900d14b11f3f3282cb97e
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/virt/vm.py
1 file changed, 21 insertions(+), 12 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/10/31210/1
diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py
index 9e93425..0405726 100644
--- a/vdsm/virt/vm.py
+++ b/vdsm/virt/vm.py
@@ -3401,6 +3401,19 @@
return {'status': doneCode}
+ def _getVmMetadata(self, uri, fallback):
+ metadata_xml = fallback
+
+ try:
+ metadata_xml = self._dom.metadata(
+ libvirt.VIR_DOMAIN_METADATA_ELEMENT, uri, 0)
+ except libvirt.libvirtError as e:
+ if e.get_error_code() != libvirt.VIR_ERR_NO_DOMAIN_METADATA:
+ self.log.exception("getVmMetadata for %s failed", uri)
+ return None
+
+ return metadata_xml
+
def _getVmPolicy(self):
"""
This method gets the current qos block from the libvirt metadata.
@@ -3410,19 +3423,15 @@
:return: XML DOM object representing the root qos element
"""
- metadata_xml = "<qos></qos>"
+ metadata_xml = self._getVmMetadata(
+ METADATA_VM_TUNE_URI,
+ "<qos></qos>")
- try:
- metadata_xml = self._dom.metadata(
- libvirt.VIR_DOMAIN_METADATA_ELEMENT,
- METADATA_VM_TUNE_URI, 0)
- except libvirt.libvirtError as e:
- if e.get_error_code() != libvirt.VIR_ERR_NO_DOMAIN_METADATA:
- self.log.exception("getVmPolicy failed")
- return None
-
- metadata = xml.dom.minidom.parseString(metadata_xml)
- return metadata.getElementsByTagName("qos")[0]
+ if metadata_xml is None:
+ return None
+ else:
+ metadata = xml.dom.minidom.parseString(metadata_xml)
+ return metadata.getElementsByTagName("qos")[0]
def _findDeviceByNameOrPath(self, device_name, device_path):
for device in self._devices[DISK_DEVICES]:
--
To view, visit http://gerrit.ovirt.org/31210
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If29df44b26870884eb2900d14b11f3f3282cb97e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
More information about the vdsm-patches
mailing list