Skip to content

Instantly share code, notes, and snippets.

@kamilziajka
Last active September 30, 2016 12:44
Show Gist options
  • Save kamilziajka/76b4f95ce56c3e55e8454c8b1981b87a to your computer and use it in GitHub Desktop.
Save kamilziajka/76b4f95ce56c3e55e8454c8b1981b87a to your computer and use it in GitHub Desktop.
OpenStack CoreOS image upload
#!/usr/bin/env bash
REPOSITORY_URL="https://stable.release.core-os.net/amd64-usr/current";
IMAGE_FILE="coreos_production_openstack_image.img";
IMAGE_BZIP_FILE="${IMAGE_FILE}.bz2"
VERSION_FILE="version.txt";
TEMP_DIR=`mktemp -d` && cd ${TEMP_DIR}
# checking what is the latest CoreOS release version
echo Checking for the latest CoreOS release version...
wget ${REPOSITORY_URL}/${VERSION_FILE} -q
COREOS_VERSION=$(awk -F "=" '/COREOS_VERSION_ID/ {print $2}' ${VERSION_FILE})
COREOS_NAME="CoreOS ${COREOS_VERSION}"
# check if that image is currently available in OpenStack
IMAGE_TEST=`openstack image list | grep "${COREOS_NAME}" | wc -l`
if (( IMAGE_TEST > 0 )); then
echo The latest ${COREOS_NAME} image has already been uploaded to OpenStack
else
echo Downloading ${COREOS_NAME} image...
wget ${REPOSITORY_URL}/${IMAGE_BZIP_FILE} -q --show-progress
echo Unpacking ${COREOS_NAME} image...
bzip2 -d ${IMAGE_BZIP_FILE}
echo Uploading ${COREOS_NAME} image to OpenStack...
openstack image create "${COREOS_NAME}" \
--container-format bare \
--disk-format qcow2 \
--file ${IMAGE_FILE}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment