Save image name in Server.image_name method

The api.nova.Server.image_name @property can be called multiple times
for a given server. It can result in so many calls to glance.get_image.

This patch saves the result of the image name as returned by the
glance.get_image call in the Server.image dict, so that subsequent calls
to image_name can return faster.

Change-Id: I38993f13619f1725bcc7c763fe364f415e88eb62
Closes-bug: #1676420
This commit is contained in:
Guillaume Espanel 2017-03-27 14:49:42 +02:00 committed by Mateusz Kowalski
parent 98ac7666a0
commit 1faf8c2dd9
1 changed files with 2 additions and 0 deletions

View File

@ -132,9 +132,11 @@ class Server(base.APIResourceWrapper):
else:
try:
image = glance.image_get(self.request, self.image['id'])
self.image['name'] = image.name
return image.name
except (glance_exceptions.ClientException,
horizon_exceptions.ServiceCatalogException):
self.image['name'] = None
return None
@property