diff options
author | Zuul <zuul@review.openstack.org> | 2018-02-26 14:27:23 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2018-02-26 14:27:23 +0000 |
commit | 0e315fd30a12c7fd012d98c6ebfc2ce2fdfb9cb9 (patch) | |
tree | 223266aa44a2ce70ba9abcfdd4df0b9c56eee44f | |
parent | cba031639920366e1d27c055e7efa7528709a478 (diff) | |
parent | afaa7f7c8cbe34b1573c7ade341a7c42b455c28e (diff) | |
download | ceilometer-8.1.4.tar.gz |
-rw-r--r-- | ceilometer/compute/discovery.py | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/ceilometer/compute/discovery.py b/ceilometer/compute/discovery.py index c0a28cb9..b2017268 100644 --- a/ceilometer/compute/discovery.py +++ b/ceilometer/compute/discovery.py @@ -166,42 +166,55 @@ class InstanceDiscovery(plugin_base.DiscoveryBase): # flavor. this is why nova doesn't put the id in the libvirt # metadata - # This implements - flavor_xml = metadata_xml.find("./flavor") - flavor = { - "id": self.get_flavor_id(flavor_xml.attrib["name"]), - "name": flavor_xml.attrib["name"], - "vcpus": self._safe_find_int(flavor_xml, "vcpus"), - "ram": self._safe_find_int(flavor_xml, "memory"), - "disk": self._safe_find_int(flavor_xml, "disk"), - "ephemeral": self._safe_find_int(flavor_xml, "ephemeral"), - "swap": self._safe_find_int(flavor_xml, "swap"), - } + try: + flavor_xml = metadata_xml.find( + "./flavor") + user_id = metadata_xml.find( + "./owner/user").attrib["uuid"] + project_id = metadata_xml.find( + "./owner/project").attrib["uuid"] + instance_name = metadata_xml.find( + "./name").text + instance_arch = os_type_xml.attrib["arch"] + + flavor = { + "id": self.get_flavor_id(flavor_xml.attrib["name"]), + "name": flavor_xml.attrib["name"], + "vcpus": self._safe_find_int(flavor_xml, "vcpus"), + "ram": self._safe_find_int(flavor_xml, "memory"), + "disk": self._safe_find_int(flavor_xml, "disk"), + "ephemeral": self._safe_find_int(flavor_xml, "ephemeral"), + "swap": self._safe_find_int(flavor_xml, "swap"), + } + + # The image description is partial, but Gnocchi only care about + # the id, so we are fine + image_xml = metadata_xml.find("./root[@type='image']") + image = ({'id': image_xml.attrib['uuid']} + if image_xml is not None else None) + except AttributeError: + LOG.error( + "Fail to get domain uuid %s metadata: " + "metadata was missing expected attributes", + domain.UUIDString()) + continue + dom_state = domain.state()[0] vm_state = libvirt_utils.LIBVIRT_POWER_STATE.get(dom_state) status = libvirt_utils.LIBVIRT_STATUS.get(dom_state) - user_id = metadata_xml.find("./owner/user").attrib["uuid"] - project_id = metadata_xml.find("./owner/project").attrib["uuid"] - # From: # https://github.com/openstack/nova/blob/852f40fd0c6e9d8878212ff3120556668023f1c4/nova/api/openstack/compute/views/servers.py#L214-L220 host_id = hashlib.sha224( (project_id + self.conf.host).encode('utf-8')).hexdigest() - # The image description is partial, but Gnocchi only care about the - # id, so we are fine - image_xml = metadata_xml.find("./root[@type='image']") - image = ({'id': image_xml.attrib['uuid']} - if image_xml is not None else None) - instance_data = { "id": domain.UUIDString(), - "name": metadata_xml.find("./name").text, + "name": instance_name, "flavor": flavor, "image": image, "os_type": os_type_xml.text, - "architecture": os_type_xml.attrib["arch"], + "architecture": instance_arch, "OS-EXT-SRV-ATTR:instance_name": domain.name(), "OS-EXT-SRV-ATTR:host": self.conf.host, |