Upload A Disk Volume Directly to Openstack Image
When we upload an image using openstack image create --file
, the image file will be transferred to image storage backend through glance api servers. If the image size is huge, the upload process might take time sometimes ends in failure. Glance API might become the bottleneck if multiple huge images are uploaded at the same time. To overcome glance api servers bottleneck, we could instead directly upload the image to ceph following the below procedure.
Step 1: Convert the current image to qcow2
In Openstack cinder prior to version 17.2.0, new instance will not launch if image format is not qcow2 due to the bug https://bugs.launchpad.net/cinder/+bug/1931004.
qemu-img convert -f raw -O qcow2 ${IMAGE} ${IMAGE}.qcow2
Step 2: Create a new image
The disk-format
should be set to qcow2
. Note the ${IMAGE_ID}
of this image. The image will be in queued status as there is no file.
openstack image create --disk-format qcow2 ${IMAGE_NAME}
Step 3: Upload the qcow2 image directly to Ceph.
Run the command in ceph client. Here ${IMAGE_ID}
is the image id of the newly created image in step 2.
rbd import ${IMAGE}.qcow2 glance/${IMAGE_ID}
Step 4: Create a snapshot for this image
Glance will refer to the snapshot of rbd volume uploaded. In order to compliance with this requirement, we create a snapshot of the upload image.
rbd snap create glance/${IMAGE_ID}@snap
rbd info glance/${IMAGE_ID}
Step 5. Update the image data in openstack side
The ${CEPH_CLUSTER_ID}
can be referred from other image. After this step, the image should be in “active” status with minimum metadata.
$ glance location-add --url rbd://${CEPH_CLUSTER_ID}/glance/${IMAGE_ID}/snap ${IMAGE_ID}
After 5 steps above, users can launch a new openstack instance from this image.
This article is an update to: https://ceph.io/en/news/blog/2014/openstack-glance-import-images-and-convert-them-directly-in-ceph/ due to changes in glance command line interface.