Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Glance load - a utility to monitor an ETag and load the corresponding file into glance.
#!/usr/bin/env bash
# Brian "Redbeard" Harrington <>
# This code is in the public domain.
# A tool for monitoring remote files and loading them into a glance image
# store. This tool has been optimized for use on CoreOS but should work
# for most files where an ETag is exposed.
# by default we retrieve the alpha image, set to a different value to retrieve
# that release
# use the following location as our local work space
mkdir -p ${tmplocation}
pushd ${tmplocation} > /dev/null 2>&1
#retrieve the remote "ETag" header and set it to a variable
remote_etag=$(curl -I -k -s | gawk '/ETag/ {print gensub("\"", "", "g", $2)}')
# source in the previously saved etag
source ${release}_version > /dev/null 2>&1
if [ "$remote_etag" == "$local_etag" ]; then
echo "Everything is current"
exit 0
curl -s -L -O$release/version.txt
. version.txt
#load openstack credentials
. $HOME/.openstack || echo "No glance credentials available" && exit 1
# if we already have the image don't waste time
glance image-show CoreOS-${release}-v${COREOS_VERSION} || skip="false"
if [ "$skip" == "false" ]; then
# change the following line to reflect the image to be chosen, openstack
# is used by default
curl -s -L -O$release/coreos_production_openstack_image.img.bz2
bunzip2 -d coreos_production_openstack_image.img.bz2
# things can get confusing if you're constantly working with the same filename
# then again, this leaves you needing to clean up old images
mv coreos_production_openstack_image.img coreos_${COREOS_VERSION}_openstack_image.img
# perform actual image creation
# here we set the os_release, os_verison, os_family, and os_distro variables
# for intelligent consumption of images by scripts
glance image-create --name CoreOS-${release}-v${COREOS_VERSION} --progress --is-public true \
--property os_distro=coreos --property os_family=coreos --property os_version=${COREOS_VERSION} --property os_release=${release} \
--disk-format qcow2 --container-format bare --min-disk 6 --file $coreosimg
# grab UUID of newly created image
new_glance_uuid=$(glance image-show CoreOS-${release}-v${COREOS_VERSION} | awk '/ id / {print $4}')
# purge os_release tag from all previous versions of said release
glance image-list --property "os_release=$release" \
| gawk '$4 ~ /CoreOS/ && !/'"$new_glance_uuid"'/ {printf \
"glance image-update --property os_distro=coreos --property \
os_family=coreos --property os_version=%s --purge-props %s \n",\
gensub(/CoreOS_v/, "", "g", $4), $2}' | sh
echo "local_etag=$remote_etag" > ${release}_version
popd > /dev/null 2>&1
# vim: set ts=2 sw=2 expandtab:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment