Skip to content

Instantly share code, notes, and snippets.

@ljjjustin
Last active May 5, 2019 06:22
Show Gist options
  • Save ljjjustin/b51dd9f3d39faa174c864c1ede6d673f to your computer and use it in GitHub Desktop.
Save ljjjustin/b51dd9f3d39faa174c864c1ede6d673f to your computer and use it in GitHub Desktop.
upload image to ceph
#!/bin/bash
set -x
if [ $# -ne 1 ]; then
echo "usage: $0 <image file path>"
exit
fi
image_path=$1
if [ ! -r "${image_path}" ]; then
echo "ERROR: Can't read ${image_path}, exiting.."
exit
fi
image_name=$(basename $1 | awk -F. '{print $1}')
image_uuid=$(uuidgen)
## convert image format
image_format=$(qemu-img info "${image_path}" | grep 'file format' | awk '{print $NF}')
if [ "raw" != "${image_format}" ]; then
qemu-img convert -O raw "${image_path}" rbd:images/${image_uuid}
fi
## check if image exists
if ! rbd -p images info ${image_uuid} &> /dev/null; then
echo "ERROR: image ${image_uuid} don't exists"
exit
fi
## make and protect snapshot
rbd -p images snap create --snap snap ${image_uuid}
rbd -p images snap protect --image ${image_uuid} --snap snap
## create image
source /root/keystonerc_admin
glance --os-image-api-version 1 image-create --id ${image_uuid} --name ${image_name} \
--store rbd --disk-format raw --container-format bare \
--location rbd://$(ceph fsid)/images/${image_uuid}/snap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment