From f3e7ff1450e1f90fdbfebff7159b41954477ef1e Mon Sep 17 00:00:00 2001 From: Witold Bedyk Date: Mon, 19 Mar 2018 16:08:55 +0100 Subject: [PATCH] Fix libvirt plugin to handle FQDN of compute node The change adds simple logic to check the actual name of the compute node. The list of nova services is filtered with FQDN hostname and if not successful with unqualified name. Change-Id: I9ba044f26b53a52afbac0fcd99552a4135cd4725 Story: 2001679 Task: 6785 --- monasca_agent/collector/checks_d/libvirt.py | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/monasca_agent/collector/checks_d/libvirt.py b/monasca_agent/collector/checks_d/libvirt.py index c7acca0f..4ab8c6b0 100644 --- a/monasca_agent/collector/checks_d/libvirt.py +++ b/monasca_agent/collector/checks_d/libvirt.py @@ -82,6 +82,7 @@ class LibvirtCheck(AgentCheck): self._collect_intervals = {} self._host_aggregate = None + self._nova_host = None self._set_collection_intervals('disk', 'disk_collection_period') self._set_collection_intervals('vnic', 'vnic_collection_period') @@ -136,6 +137,29 @@ class LibvirtCheck(AgentCheck): [rule['remote_ip_prefix']]))): return True + def _get_nova_host(self, nova_client): + if not self._nova_host: + # Find `nova-compute` on current node + services = nova_client.services.list(host=self.hostname, + binary='nova-compute') + if not services: + # Catch the case when `nova-compute` is registered with + # unqualified hostname + services = nova_client.services.list( + host=self.hostname.split('.')[0], binary='nova-compute') + if services: + self._nova_host = services[0].host + self.log.info("Found 'nova-compute' registered with host: {}" + .format(self._nova_host)) + + if self._nova_host: + return self._nova_host + else: + self.log.warn("No 'nova-compute' service found on host: {}" + .format(self.hostname)) + # Return hostname as fallback value + return self.hostname + def _update_instance_cache(self): """Collect instance_id, project_id, and AZ for all instance UUIDs """ @@ -155,7 +179,8 @@ class LibvirtCheck(AgentCheck): client_version=ma_version.version_string) self._get_this_host_aggregate(nova_client) instances = nova_client.servers.list( - search_opts={'all_tenants': 1, 'host': self.hostname.split('.')[0]}) + search_opts={'all_tenants': 1, + 'host': self._get_nova_host(nova_client)}) # Lay the groundwork for fetching VM IPs and network namespaces if self.init_config.get('ping_check'): nu = neutron_client.Client(