Merge "Copy glance_image_metadata when cloning volumes."
This commit is contained in:
commit
5d33cf07c7
@ -441,6 +441,19 @@ def volume_glance_metadata_delete_by_snapshot(context, snapshot_id):
|
||||
return IMPL.volume_glance_metadata_delete_by_snapshot(context, snapshot_id)
|
||||
|
||||
|
||||
def volume_glance_metadata_copy_from_volume_to_volume(context,
|
||||
src_volume_id,
|
||||
volume_id):
|
||||
"""
|
||||
Update the Glance metadata for a volume by copying all of the key:value
|
||||
pairs from the originating volume. This is so that a volume created from
|
||||
the volume (clone) will retain the original metadata.
|
||||
"""
|
||||
return IMPL.volume_glance_metadata_copy_from_volume_to_volume(
|
||||
context,
|
||||
src_volume_id,
|
||||
volume_id)
|
||||
|
||||
###################
|
||||
|
||||
|
||||
|
@ -1597,6 +1597,33 @@ def volume_glance_metadata_copy_to_snapshot(context, snapshot_id, volume_id,
|
||||
vol_glance_metadata.save(session=session)
|
||||
|
||||
|
||||
@require_context
|
||||
@require_volume_exists
|
||||
def volume_glance_metadata_copy_from_volume_to_volume(context,
|
||||
src_volume_id,
|
||||
volume_id,
|
||||
session=None):
|
||||
"""
|
||||
Update the Glance metadata for a volume by copying all of the key:value
|
||||
pairs from the originating volume. This is so that a volume created from
|
||||
the volume (clone) will retain the original metadata.
|
||||
"""
|
||||
if session is None:
|
||||
session = get_session()
|
||||
|
||||
metadata = volume_glance_metadata_get(context,
|
||||
src_volume_id,
|
||||
session=session)
|
||||
with session.begin():
|
||||
for meta in metadata:
|
||||
vol_glance_metadata = models.VolumeGlanceMetadata()
|
||||
vol_glance_metadata.volume_id = volume_id
|
||||
vol_glance_metadata.key = meta['key']
|
||||
vol_glance_metadata.value = meta['value']
|
||||
|
||||
vol_glance_metadata.save(session=session)
|
||||
|
||||
|
||||
@require_context
|
||||
@require_volume_exists
|
||||
def volume_glance_metadata_copy_to_volume(context, volume_id, snapshot_id,
|
||||
|
@ -113,3 +113,19 @@ class VolumeGlanceMetadataTestCase(test.TestCase):
|
||||
for meta in db.volume_snapshot_glance_metadata_get(ctxt, 100):
|
||||
for (key, value) in expected_meta.items():
|
||||
self.assertEquals(meta[key], value)
|
||||
|
||||
def test_vol_glance_metadata_copy_to_volume(self):
|
||||
ctxt = context.get_admin_context()
|
||||
db.volume_create(ctxt, {'id': 1})
|
||||
db.volume_create(ctxt, {'id': 100, 'source_volid': 1})
|
||||
vol_meta = db.volume_glance_metadata_create(ctxt, 1, 'key1',
|
||||
'value1')
|
||||
db.volume_glance_metadata_copy_from_volume_to_volume(ctxt, 100, 1)
|
||||
|
||||
expected_meta = {'id': '100',
|
||||
'key': 'key1',
|
||||
'value': 'value1'}
|
||||
|
||||
for meta in db.volume_glance_metadata_get(ctxt, 100):
|
||||
for (key, value) in expected_meta.items():
|
||||
self.assertEquals(meta[key], value)
|
||||
|
@ -176,12 +176,12 @@ class VolumeManager(manager.SchedulerDependentManager):
|
||||
snapshot_ref)
|
||||
elif source_volid is not None:
|
||||
src_vref = self.db.volume_get(context, source_volid)
|
||||
self.db.volume_update(context, src_vref['id'],
|
||||
{'status': 'in use'})
|
||||
model_update = self.driver.create_cloned_volume(volume_ref,
|
||||
src_vref)
|
||||
self.db.volume_update(context, src_vref['id'],
|
||||
{'status': src_vref['status']})
|
||||
self.db.volume_glance_metadata_copy_from_volume_to_volume(
|
||||
context,
|
||||
source_volid,
|
||||
volume_id)
|
||||
else:
|
||||
# create the volume from an image
|
||||
image_service, image_id = \
|
||||
@ -221,10 +221,6 @@ class VolumeManager(manager.SchedulerDependentManager):
|
||||
self._reset_stats()
|
||||
|
||||
if image_id and not cloned:
|
||||
# NOTE(jdg): Our current ref hasn't been updated since
|
||||
# the create, need to update ref to get provider_location
|
||||
# before trying to perform the copy operation
|
||||
volume_ref = self.db.volume_get(context, volume_id)
|
||||
if image_meta:
|
||||
# Copy all of the Glance image properties to the
|
||||
# volume_glance_metadata table for future reference.
|
||||
|
Loading…
x
Reference in New Issue
Block a user