Handle newer nova microversions

openstacksdk is requesting a newer nova microversion for server
records to pull new information that's only returned that way.
One of the results is that, on clouds that support that microversion,
nova no longer returns flavor id in the server record (since a flavor
could be deleted by the cloud while the server stays around) but
instead embeds the details about the flavor (ram, vcpus, etc)
in the server.flavor entry. This is neat - since it gives us the
info we need without the extra call. The downside is that we can't
count on the id field existing. SDK could add one - but it would
be None on newer clouds, so we'd still need to check for existence.

Long story short - handle both sides of the behavior.

Change-Id: I1f7b592265ac612ea6ca1b2f977e1507c6251da3
This commit is contained in:
Monty Taylor 2019-10-24 17:14:27 +09:00
parent 36fb6e90a5
commit 5fae5f5e8c
1 changed files with 8 additions and 1 deletions

View File

@ -205,7 +205,14 @@ class OpenStackProvider(Provider):
# It has not leaked.
continue
flavor = flavors.get(server.flavor.id)
# In earlier versions of nova, flavor is an id. In later versions
# it returns the information we're looking for. If we get the
# information, we do not have to attempt to look up the ram or
# vcpus.
if hasattr(server.flavor, 'id'):
flavor = flavors.get(server.flavor.id)
else:
flavor = server.flavor
used_quota.add(QuotaInformation.construct_from_flavor(flavor))
return used_quota