value)
+def volume_glance_metadata_get_all(context):
+ """Return the glance metadata for all volumes."""
+ return IMPL.volume_glance_metadata_get_all(context)
+
+
def volume_glance_metadata_get(context, volume_id):
"""Return the glance metadata for a volume."""
return IMPL.volume_glance_metadata_get(context, volume_id)
####################
+@require_context
+def _volume_glance_metadata_get_all(context, session=None):
+ rows = model_query(context,
+ models.VolumeGlanceMetadata,
+ project_only=True,
+ session=session).\
+ filter_by(deleted=False).\
+ all()
+
+ return rows
+
+
+@require_context
+def volume_glance_metadata_get_all(context):
+ """Return the Glance metadata for all volumes."""
+
+ return _volume_glance_metadata_get_all(context)
+
+
@require_context
@require_volume_exists
def _volume_glance_metadata_get(context, volume_id, session=None):
for key, value in expected_metadata_1.items():
self.assertEqual(metadata[0][key], value)
+ def test_vols_get_glance_metadata(self):
+ ctxt = context.get_admin_context()
+ db.volume_create(ctxt, {'id': '1'})
+ db.volume_create(ctxt, {'id': '2'})
+ db.volume_create(ctxt, {'id': '3'})
+ db.volume_glance_metadata_create(ctxt, '1', 'key1', 'value1')
+ db.volume_glance_metadata_create(ctxt, '2', 'key2', 'value2')
+ db.volume_glance_metadata_create(ctxt, '2', 'key22', 'value22')
+
+ metadata = db.volume_glance_metadata_get_all(ctxt)
+ self.assertEqual(len(metadata), 3)
+ self._assert_metadata_equals('1', 'key1', 'value1', metadata[0])
+ self._assert_metadata_equals('2', 'key2', 'value2', metadata[1])
+ self._assert_metadata_equals('2', 'key22', 'value22', metadata[2])
+
+ def _assert_metadata_equals(self, volume_id, key, value, observed):
+ self.assertEqual(volume_id, observed.volume_id)
+ self.assertEqual(key, observed.key)
+ self.assertEqual(value, observed.value)
+
def test_vol_delete_glance_metadata(self):
ctxt = context.get_admin_context()
db.volume_create(ctxt, {'id': 1})
"""
+import collections
import functools
from oslo.config import cfg
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'])