_translate_from_glance() can cause an unnecessary HTTP request
After returning from a get() call to python-glanceclient, nova runs a
translation function on the returned Image to get the data it wants. Part of
this process is checking for an expected set of attributes, one of which is
the deletion time ('deleted_at'). However, if the image has not been deleted,
deleted_at key will not exist. This forces another call to glance to occur for
the same image. A similar problem exists for the checksum attribute, which does
not exist before an image is active. The fix here is to only consider
deleted_at and checksum if they are expected to be present.
Change-Id: I67b7dd16a94fe60d873c012f6bd246ab24500d5a
Closes-Bug: #1275173
(cherry picked from commit 8fcefef5c6
)
This commit is contained in:
parent
d7afa2a417
commit
aff80d58bb
|
@ -509,14 +509,25 @@ def _convert_to_string(metadata):
|
|||
|
||||
|
||||
def _extract_attributes(image):
|
||||
#NOTE(hdd): If a key is not found, base.Resource.__getattr__() may perform
|
||||
# a get(), resulting in a useless request back to glance. This list is
|
||||
# therefore sorted, with dependent attributes as the end
|
||||
# 'deleted_at' depends on 'deleted'
|
||||
# 'checksum' depends on 'status' == 'active'
|
||||
IMAGE_ATTRIBUTES = ['size', 'disk_format', 'owner',
|
||||
'container_format', 'checksum', 'id',
|
||||
'container_format', 'status', 'id',
|
||||
'name', 'created_at', 'updated_at',
|
||||
'deleted_at', 'deleted', 'status',
|
||||
'deleted', 'deleted_at', 'checksum',
|
||||
'min_disk', 'min_ram', 'is_public']
|
||||
output = {}
|
||||
|
||||
for attr in IMAGE_ATTRIBUTES:
|
||||
output[attr] = getattr(image, attr, None)
|
||||
if attr == 'deleted_at' and not output['deleted']:
|
||||
output[attr] = None
|
||||
elif attr == 'checksum' and output['status'] != 'active':
|
||||
output[attr] = None
|
||||
else:
|
||||
output[attr] = getattr(image, attr)
|
||||
|
||||
output['properties'] = getattr(image, 'properties', {})
|
||||
|
||||
|
|
Loading…
Reference in New Issue