Support nova compute-api microversion '2.53'

Nova has changed the '/os-hypervisors' API to return compute host UUIDs
instead of internal ids since version 2.53 [1].

However, if version 2.53 is set for the nova_client_version option in
blazar.conf, an internal server error is caused when creating a host
because the nova client exception has been changed from NotFound to
BadRequest since that version.

This patch solves the problem by handling both exceptions.

[1] https://developer.openstack.org/api-ref/compute/#list-hypervisors

Change-Id: I67718490a07ee2edf05d043755dcc02fda3516a9
Closes-Bug: #1780738
This commit is contained in:
Tetsuro Nakamura 2018-07-01 20:46:56 +09:00 committed by Hiroaki Kobayashi
parent 84785b7dde
commit 60e3a01572
1 changed files with 12 additions and 3 deletions

View File

@ -441,12 +441,18 @@ class NovaInventory(NovaClientWrapper):
def get_host_details(self, host):
"""Get Nova capabilities of a single host
:param host: UUID or name of nova-compute host
:param host: UUID, ID or name of nova-compute host
:return: Dict of capabilities or raise HostNotFound
"""
try:
# NOTE(tetsuro): Only id (microversion < 2.53) or uuid
# (microversion >= 2.53) is acceptable for the
# `novaclient.hypervisors.get` argument. The invalid arguments
# result in NotFound exception for microversion < 2.53 and
# BadRequest exception for microversion >= 2.53
hypervisor = self.nova.hypervisors.get(host)
except nova_exception.NotFound:
except (nova_exception.NotFound, nova_exception.BadRequest):
# Name (not id or uuid) is given for the `host` parameter.
try:
hypervisors_list = self.nova.hypervisors.search(host)
except nova_exception.NotFound:
@ -468,12 +474,15 @@ class NovaInventory(NovaClientWrapper):
az_name = zone.zoneName
try:
# NOTE(tetsuro): compute API microversion 2.28 changes cpu_info
# from string to object
cpu_info = str(hypervisor.cpu_info)
return {'id': hypervisor.id,
'availability_zone': az_name,
'hypervisor_hostname': hypervisor.hypervisor_hostname,
'service_name': hypervisor.service['host'],
'vcpus': hypervisor.vcpus,
'cpu_info': hypervisor.cpu_info,
'cpu_info': cpu_info,
'hypervisor_type': hypervisor.hypervisor_type,
'hypervisor_version': hypervisor.hypervisor_version,
'memory_mb': hypervisor.memory_mb,