Last active
September 30, 2016 12:44
-
-
Save kamilziajka/76b4f95ce56c3e55e8454c8b1981b87a to your computer and use it in GitHub Desktop.
OpenStack CoreOS image upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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