Add call to retrieve image metadata for volumes in bulk

When using the GET volume details REST API call, the image metadata API
contribution is making an individual db call for each of the available
volumes. When the number of volumes is large the details call can take
several minutes.

This patch adds a call to the volume.API to retrieve image metadata in
bulk, very similar to the one used to retrieve individual volume image
metadata.

Change-Id: Ic3aa721016704c72b7564cc5ceff71676806a24a
Partial-Bug: #1197612
This commit is contained in:
Luis A. Garcia
2013-11-05 02:19:02 +00:00
parent 54b117d26e
commit bb2daca286
4 changed files with 54 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ Handles all requests relating to volumes.
"""
import collections
import functools
from oslo.config import cfg
@@ -700,6 +701,15 @@ class API(base.Base):
def get_snapshot_metadata_value(self, snapshot, key):
pass
def get_volumes_image_metadata(self, context):
check_policy(context, 'get_volumes_image_metadata')
db_data = self.db.volume_glance_metadata_get_all(context)
results = collections.defaultdict(dict)
for meta_entry in db_data:
results[meta_entry['volume_id']].update({meta_entry['key']:
meta_entry['value']})
return results
@wrap_check_policy
def get_volume_image_metadata(self, context, volume):
db_data = self.db.volume_glance_metadata_get(context, volume['id'])