Browse Source

added function to check whether working dir can be safely unmounted, added the possibility to delete existing image, improved check for existing default flavor

master
Sebastian Rieger 9 years ago
parent
commit
c607fa84dc
  1. 47
      create-cumulusvx-image/create-cumulus-vx-image.sh

47
create-cumulusvx-image/create-cumulus-vx-image.sh

@ -27,12 +27,37 @@ GLANCE_IMAGE_RELEASE=$CUMULUS_QCOW2_BASENAME
TMP_NAME="CumulusVX-$GLANCE_IMAGE_RELEASE" TMP_NAME="CumulusVX-$GLANCE_IMAGE_RELEASE"
TIMESTAMP=$(date +%Y%m%d%H%M%S) TIMESTAMP=$(date +%Y%m%d%H%M%S)
CHECK_FOR_EXISTING_IMAGE=$(glance image-show CumulusVX | grep name | grep CumulusVX)
if [ $? == 0 ]; then
echo "Deleting existing image $2..."
echo "==========================================================="
glance image-delete $2
function safe_unmount() {
echo -n "Unmounting $1..."
RETRY=0
until umount $1 &>/dev/null
do
echo -n "."
sleep 1
RETRY=$((RETRY+1))
if [ "$RETRY" -ge "5" ] ; then
echo
echo "ERROR: unable to unmount working directory $1"
exit 1
fi
done
echo
return 0
}
# check for an existing image with the same name and offer to delete it prior to creating a new one
CHECK_FOR_EXISTING_IMAGE=$(glance image-show CumulusVX 2>&1)
if [ $? == 0 ] ; then
read -r -p "There is already an image with the same name in glance. Do you want to overwrite it? [y/N] " RESPONSE
if [[ $RESPONSE =~ ^([yY][eE][sS]|[yY])$ ]] ; then
echo "Deleting existing image $2..."
echo "==========================================================="
glance image-delete $2
else
echo "An image with the same name already exists. Either delete this image or choose another name."
exit 1
fi
fi fi
echo echo
@ -57,6 +82,7 @@ mount /dev/mapper/$LOOPDEV_PART2 cumulusvx-root-$TIMESTAMP
sed -i.bak -e s/"linux \/bzImage root=\/dev\/sda2"/"linux \/bzImage root=\/dev\/sda2 console=ttyS0 console=tty0"/g cumulusvx-root-$TIMESTAMP/vbox_grub.cfg sed -i.bak -e s/"linux \/bzImage root=\/dev\/sda2"/"linux \/bzImage root=\/dev\/sda2 console=ttyS0 console=tty0"/g cumulusvx-root-$TIMESTAMP/vbox_grub.cfg
sed -i.bak -e s/"linux \/bzImage root=\/dev\/sda2"/"linux \/bzImage root=\/dev\/sda2 console=ttyS0 console=tty0"/g cumulusvx-boot-$TIMESTAMP/grub/grub.cfg sed -i.bak -e s/"linux \/bzImage root=\/dev\/sda2"/"linux \/bzImage root=\/dev\/sda2 console=ttyS0 console=tty0"/g cumulusvx-boot-$TIMESTAMP/grub/grub.cfg
sed -i.bak -e s/"# S0:3:respawn:\/sbin\/getty -L \$(get-cmdline-console) vt100"/"S0:3:respawn:\/sbin\/getty -L \$(get-cmdline-console) vt100"/g cumulusvx-root-$TIMESTAMP/etc/inittab sed -i.bak -e s/"# S0:3:respawn:\/sbin\/getty -L \$(get-cmdline-console) vt100"/"S0:3:respawn:\/sbin\/getty -L \$(get-cmdline-console) vt100"/g cumulusvx-root-$TIMESTAMP/etc/inittab
# append a script to import the configuration defined in VM Maestro to rc.local
sed -i.bak -e s/"^exit 0$"/""/g cumulusvx-root-$TIMESTAMP/etc/rc.local sed -i.bak -e s/"^exit 0$"/""/g cumulusvx-root-$TIMESTAMP/etc/rc.local
cat << EOF >> cumulusvx-root-$TIMESTAMP/etc/rc.local cat << EOF >> cumulusvx-root-$TIMESTAMP/etc/rc.local
mkdir /virl-config mkdir /virl-config
@ -70,10 +96,9 @@ EOF
# #
#bash #bash
# inject script to handle dhcp for eth0 and import of config defined in VM Maestro (config-drive)
safe_unmount cumulusvx-boot-$TIMESTAMP
safe_unmount cumulusvx-root-$TIMESTAMP
umount cumulusvx-boot-$TIMESTAMP
umount cumulusvx-root-$TIMESTAMP
rm -rf cumulusvx-boot-$TIMESTAMP rm -rf cumulusvx-boot-$TIMESTAMP
rm -rf cumulusvx-root-$TIMESTAMP rm -rf cumulusvx-root-$TIMESTAMP
kpartx -d $CUMULUS_QCOW2_BASENAME.raw kpartx -d $CUMULUS_QCOW2_BASENAME.raw
@ -89,8 +114,8 @@ glance image-create --container-format bare --disk-format qcow2 --is-public true
--file $CUMULUS_PATCHED_QCOW2 --property hw_disk_bus=ide --property serial=1 \ --file $CUMULUS_PATCHED_QCOW2 --property hw_disk_bus=ide --property serial=1 \
--property hw_vif_model=e1000 --property hw_cdrom_type=ide --property release="$GLANCE_IMAGE_RELEASE" --property subtype=CumulusVX --property config_disk_type=disk --property hw_vif_model=e1000 --property hw_cdrom_type=ide --property release="$GLANCE_IMAGE_RELEASE" --property subtype=CumulusVX --property config_disk_type=disk
# create flavor
CHECKING_FOR_EXISTING_FLAVOR=$(nova flavor-show CumulusVX.small | grep name | grep CumulusVX.small)
# create default flavor
CHECKING_FOR_EXISTING_FLAVOR=$(nova flavor-show CumulusVX.small 2>&1)
if [ $? == 1 ]; then if [ $? == 1 ]; then
echo "Creating default flavor CumulusVX.small..." echo "Creating default flavor CumulusVX.small..."
echo "===========================================================" echo "==========================================================="

Loading…
Cancel
Save