OpenStack Glance: import images and convert them directly in Ceph
Ceph, to work in optimal circumstances requires the usage of RAW images. However, it is painful to upload RAW images in Glance because it takes a while. Let see how we can make our life easier.
First let’s upload our image, for the purpose of this example I used a tiny CirrOS image:
$ sudo rbd -p imajeez --image-format 2 import cirros-0.3.0-x86-64-disk.img.1 $(uuidgen)
Now this is where it becomes interesting!
The good thing here is that we can trigger the conversion directly from Ceph and this using the
Prior to run the convertion make sure that your
ceph.conf is configured to force the creation of images 2 format (
rbd default format = 2).
All the RBD images will be created using format 2 which supports layering (snapshot, clones etc…)/
Simply call a conversion and generate a new name based on a new UUID.
$ sudo qemu-img convert -O raw rbd:imajeez/33fc77e2-df0e-4f71-a966-b8df2b245f42 rbd:imajeez/$(uuidgen)
We now have two images in our pool:
$ sudo rbd -p imajeez ls
And the image has a RAW format:
$ sudo qemu-img info rbd:imajeez/4f460d8c-2af3-4041-a28d-12c3631a305f
We can now delete our original QCOW2 image:
$ sudo rbd -p imajeez rm 33fc77e2-df0e-4f71-a966-b8df2b245f42
In order for this image to be compliant with Glance, we need to snapshot and protect it:
$ sudo rbd --pool imajeez snap create --snap snap 4f460d8c-2af3-4041-a28d-12c3631a305f
Eventually add this image into Glance, note that using the
--location flag will not upload anything since we directly register the location in Ceph.
$ glance image-create --id 4f460d8c-2af3-4041-a28d-12c3631a305f --name CirrosImport --store rbd --disk-format raw --container-format bare --location rbd://$(sudo ceph fsid)/imajeez/4f460d8c-2af3-4041-a28d-12c3631a305f/snap
This procedure will probably be reproduced as soon as the Glance conversion blueprint gets implemented. As always, it’s easier with Ceph since we don’t need to store the image in a temporary location, convert it and then upload it. This is unfortunately the problem with backend such as Swift.