Fix the generalized copy_image_to_volume operation.

The Generis iSCSI copy volume<->image patch
(change: Iff097629bcce9154829a7eb5aee0ea6302338b26) did
not account for the fact that the existing volume reference
passed in to the copy method would not have the updated
provider_location and iSCSI info available.

To address this, we simply just get a new ref from the DB
after creation if a copy image is requested.

Also, the list of acceptable formats was not fully inclusive,
not only that, but there's no reason to not let the qemu-convert
handle any errors here.

Change-Id: I7b1910080d285562c7f2d8afa7f65768b1089b73
This commit is contained in:
john-griffith 2013-01-31 22:38:51 -07:00
parent 03f759c4ad
commit 31e481667d
2 changed files with 4 additions and 18 deletions

View File

@ -144,14 +144,6 @@ class API(base.Base):
if image_size_in_gb > size:
msg = _('Size of specified image is larger than volume size.')
raise exception.InvalidInput(reason=msg)
#We use qemu-img to convert images to raw and so we can only
#support the intersection of what qemu-img and glance support
if (image_meta['container_format'] != 'bare' or
image_meta['disk_format'] not in ['raw', 'qcow2',
'vmdk', 'vdi']):
msg = (_("Image format must be one of raw, qcow2, "
"vmdk, or vdi."))
raise exception.InvalidInput(reason=msg)
try:
reservations = QUOTAS.reserve(context, volumes=1, gigabytes=size)
@ -600,16 +592,6 @@ class API(base.Base):
"""Create a new image from the specified volume."""
self._check_volume_availability(context, volume, force)
#We use qemu-img to convert raw images to the requested type
#and so we can only support the intersection of what qemu-img and
#glance support
if (metadata['container_format'] != 'bare' or
metadata['disk_format'] not in ['raw', 'qcow2',
'vmdk', 'vdi']):
msg = (_("Image format must be one of raw, qcow2, "
"vmdk, or vdi."))
raise exception.InvalidInput(reason=msg)
recv_metadata = self.image_service.create(context, metadata)
self.update(context, volume, {'status': 'uploading'})
self.volume_rpcapi.copy_volume_to_image(context,

View File

@ -221,6 +221,10 @@ 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.