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', {})