summaryrefslogtreecommitdiff
path: root/ceilometer
diff options
context:
space:
mode:
authorPavlo Shchelokovskyy <shchelokovskyy@gmail.com>2022-01-10 14:28:34 +0200
committerPavlo Shchelokovskyy <shchelokovskyy@gmail.com>2022-01-11 10:43:54 +0200
commit2fc72043d31af7acd45f918eeb290d9d7564d168 (patch)
tree070e1bd36087453eb9701beca3bd830e0422b2d6 /ceilometer
parent9325ae36dc9066073b79fdfbe4757b14536679c7 (diff)
downloadceilometer-2fc72043d31af7acd45f918eeb290d9d7564d168.tar.gz
Support two nova metadata versions in instance XML
this is followup to I2aa34cf142c6429a7a0a3b8f232c3ed83f7d9981 In order to support discovery of instances booted before Wallaby, ceilometer must support working with both 1.0 (old, Victoria and before) and 1.1 (new, Wallaby and for now newer) versions of nova metadata. Change-Id: I93b6e92a5f46de5486f30a99fa3917a5932f7360 Related-Bug: #1930446
Diffstat (limited to 'ceilometer')
-rw-r--r--ceilometer/compute/discovery.py13
-rw-r--r--ceilometer/compute/virt/libvirt/utils.py34
2 files changed, 36 insertions, 11 deletions
diff --git a/ceilometer/compute/discovery.py b/ceilometer/compute/discovery.py
index ddbecb5a..01ef1078 100644
--- a/ceilometer/compute/discovery.py
+++ b/ceilometer/compute/discovery.py
@@ -137,17 +137,8 @@ class InstanceDiscovery(plugin_base.DiscoveryBase):
def discover_libvirt_polling(self, manager, param=None):
instances = []
for domain in self.connection.listAllDomains():
- try:
- xml_string = domain.metadata(
- libvirt.VIR_DOMAIN_METADATA_ELEMENT,
- "http://openstack.org/xmlns/libvirt/nova/1.1")
- except libvirt.libvirtError as e:
- if libvirt_utils.is_disconnection_exception(e):
- # Re-raise the exception so it's handled and retries
- raise
- LOG.error(
- "Fail to get domain uuid %s metadata, libvirtError: %s",
- domain.UUIDString(), e)
+ xml_string = libvirt_utils.instance_metadata(domain)
+ if xml_string is None:
continue
full_xml = etree.fromstring(domain.XMLDesc())
diff --git a/ceilometer/compute/virt/libvirt/utils.py b/ceilometer/compute/virt/libvirt/utils.py
index 3dd238d6..b7d62fb5 100644
--- a/ceilometer/compute/virt/libvirt/utils.py
+++ b/ceilometer/compute/virt/libvirt/utils.py
@@ -78,6 +78,12 @@ LIBVIRT_STATUS = {
VIR_DOMAIN_PMSUSPENDED: 'suspended',
}
+# NOTE(pas-ha) in the order from newest to oldest
+NOVA_METADATA_VERSIONS = (
+ "http://openstack.org/xmlns/libvirt/nova/1.1",
+ "http://openstack.org/xmlns/libvirt/nova/1.0",
+)
+
def new_libvirt_connection(conf):
if not libvirt:
@@ -125,3 +131,31 @@ def raise_nodata_if_unsupported(method):
"error": e}
raise virt_inspector.NoDataException(msg)
return inner
+
+
+@retry_on_disconnect
+def instance_metadata(domain):
+ xml_string = None
+ last_error = None
+ for meta_version in NOVA_METADATA_VERSIONS:
+ try:
+ xml_string = domain.metadata(
+ libvirt.VIR_DOMAIN_METADATA_ELEMENT, meta_version)
+ break
+ except libvirt.libvirtError as exc:
+ if exc.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN_METADATA:
+ LOG.warning("Failed to find metadata %s in domain %s",
+ meta_version, domain.UUIDString())
+ last_error = exc
+ continue
+ elif is_disconnection_exception(exc):
+ # Re-raise the exception so it's handled and retries
+ raise
+ last_error = exc
+
+ if xml_string is None:
+ LOG.error(
+ "Fail to get domain uuid %s metadata, libvirtError: %s",
+ domain.UUIDString(), last_error
+ )
+ return xml_string