Merge pull request #8 from dtroyer/master
More updates to image scripts
This commit is contained in:
commit
3400bf8bc9
3 changed files with 115 additions and 93 deletions
2
README
2
README
|
@ -18,7 +18,7 @@ Tool to quickly deploy openstack dev environments
|
||||||
* move back to using sudo
|
* move back to using sudo
|
||||||
* move nova to mysql
|
* move nova to mysql
|
||||||
* munin
|
* munin
|
||||||
* extract image upload to a seperate script that supports generating images via debootstrap (ubuntu-vm-builder?)
|
* image upload with a script that supports generating images via debootstrap (ubuntu-vm-builder)
|
||||||
|
|
||||||
# Future
|
# Future
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#
|
#
|
||||||
# make_image.sh release format
|
# make_image.sh release format
|
||||||
#
|
#
|
||||||
# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc)
|
# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc), raw
|
||||||
#
|
#
|
||||||
# Requires sudo to root
|
# Requires sudo to root
|
||||||
|
|
||||||
|
@ -34,6 +34,36 @@ shift `expr $OPTIND - 1`
|
||||||
RELEASE=$1
|
RELEASE=$1
|
||||||
FORMAT=$2
|
FORMAT=$2
|
||||||
|
|
||||||
|
case $FORMAT in
|
||||||
|
kvm|qcow2) FORMAT=qcow2
|
||||||
|
QFORMAT=qcow2
|
||||||
|
HYPER=kvm
|
||||||
|
;;
|
||||||
|
vmserver|vmdk)
|
||||||
|
FORMAT=vmdk
|
||||||
|
QFORMAT=vmdk
|
||||||
|
HYPER=vmserver
|
||||||
|
;;
|
||||||
|
vbox|vdi) FORMAT=vdi
|
||||||
|
QFORMAT=vdi
|
||||||
|
HYPER=kvm
|
||||||
|
;;
|
||||||
|
vhd|vpc) FORMAT=vhd
|
||||||
|
QFORMAT=vpc
|
||||||
|
HYPER=kvm
|
||||||
|
;;
|
||||||
|
xen) FORMAT=raw
|
||||||
|
QFORMAT=raw
|
||||||
|
HYPER=xen
|
||||||
|
;;
|
||||||
|
raw) FORMAT=raw
|
||||||
|
QFORMAT=raw
|
||||||
|
HYPER=kvm
|
||||||
|
;;
|
||||||
|
*) echo "Unknown format: $FORMAT"
|
||||||
|
usage
|
||||||
|
esac
|
||||||
|
|
||||||
case $RELEASE in
|
case $RELEASE in
|
||||||
natty) ;;
|
natty) ;;
|
||||||
maverick) ;;
|
maverick) ;;
|
||||||
|
@ -42,25 +72,7 @@ case $RELEASE in
|
||||||
jaunty) ;;
|
jaunty) ;;
|
||||||
*) echo "Unknown release: $RELEASE"
|
*) echo "Unknown release: $RELEASE"
|
||||||
usage
|
usage
|
||||||
esac
|
|
||||||
|
|
||||||
case $FORMAT in
|
|
||||||
kvm|qcow2) FORMAT=qcow2
|
|
||||||
TARGET=kvm
|
|
||||||
;;
|
;;
|
||||||
vmserver|vmdk) FORMAT=vmdk
|
|
||||||
TARGET=vmserver
|
|
||||||
;;
|
|
||||||
vbox|vdi) FORMAT=qcow2
|
|
||||||
TARGET=kvm
|
|
||||||
FINAL_FORMAT=vdi
|
|
||||||
;;
|
|
||||||
vhd|vpc) FORMAT=qcow2
|
|
||||||
TARGET=kvm
|
|
||||||
FINAL_FORMAT=vpc
|
|
||||||
;;
|
|
||||||
*) echo "Unknown format: $FORMAT"
|
|
||||||
usage
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Install stuff if necessary
|
# Install stuff if necessary
|
||||||
|
@ -69,20 +81,23 @@ if [ -z `which vmbuilder` ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build the image
|
# Build the image
|
||||||
sudo vmbuilder $TARGET ubuntu --suite $RELEASE \
|
TMPDISK=`mktemp imgXXXXXXXX`
|
||||||
|
SIZE=$[$ROOTSIZE+$SWAPSIZE+1]
|
||||||
|
dd if=/dev/null of=$TMPDISK bs=1M seek=$SIZE
|
||||||
|
sudo vmbuilder $HYPER ubuntu --suite $RELEASE \
|
||||||
-o \
|
-o \
|
||||||
--rootsize=$ROOTSIZE \
|
--rootsize=$ROOTSIZE \
|
||||||
--swapsize=$SWAPSIZE \
|
--swapsize=$SWAPSIZE \
|
||||||
--tmpfs - \
|
--tmpfs - \
|
||||||
--addpkg=openssh-server \
|
--addpkg=openssh-server \
|
||||||
|
--raw=$TMPDISK \
|
||||||
|
|
||||||
# --mirror=$MIRROR \
|
if [ "$FORMAT" = "raw" ]; then
|
||||||
|
|
||||||
if [ -z "$FINAL_FORMAT" ]; then
|
|
||||||
# Get image
|
# Get image
|
||||||
mv ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FORMAT
|
mv $TMPDISK $RELEASE.$FORMAT
|
||||||
else
|
else
|
||||||
# Convert image
|
# Convert image
|
||||||
qemu-img convert -O $FINAL_FORMAT ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FINAL_FORMAT
|
qemu-img convert -O $QFORMAT $TMPDISK $RELEASE.$FORMAT
|
||||||
|
rm $TMPDISK
|
||||||
fi
|
fi
|
||||||
rm -rf ubuntu-$TARGET
|
rm -rf ubuntu-$HYPER
|
||||||
|
|
|
@ -1,24 +1,18 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# upload_image.sh - Upload Ubuntu images (create if necessary) in various formats
|
# upload_image.sh - Upload Ubuntu images (create if necessary) in various formats
|
||||||
#
|
# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc)
|
||||||
# upload_image.sh release format
|
# Requires sudo to root
|
||||||
#
|
|
||||||
# format target
|
|
||||||
# qcow2 kvm,qemu
|
|
||||||
# vmdk vmw6
|
|
||||||
# vbox vdi
|
|
||||||
# vhd vpc
|
|
||||||
|
|
||||||
HOST=${HOST:-demo.rcb.me}
|
|
||||||
PORT=${PORT:-9292}
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "$0 - Upload Ubuntu images"
|
echo "$0 - Upload images to OpenStack"
|
||||||
echo ""
|
echo ""
|
||||||
echo "$0 [-h host] [-p port] release format"
|
echo "$0 [-h host] [-p port] release format"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HOST=${HOST:-localhost}
|
||||||
|
PORT=${PORT:-9292}
|
||||||
|
|
||||||
while getopts h:p: c; do
|
while getopts h:p: c; do
|
||||||
case $c in
|
case $c in
|
||||||
h) HOST=$OPTARG
|
h) HOST=$OPTARG
|
||||||
|
@ -32,51 +26,64 @@ shift `expr $OPTIND - 1`
|
||||||
RELEASE=$1
|
RELEASE=$1
|
||||||
FORMAT=$2
|
FORMAT=$2
|
||||||
|
|
||||||
case $RELEASE in
|
|
||||||
natty) ;;
|
|
||||||
maverick) ;;
|
|
||||||
lucid) ;;
|
|
||||||
karmic) ;;
|
|
||||||
jaunty) ;;
|
|
||||||
*) echo "Unknown release: $RELEASE"
|
|
||||||
usage
|
|
||||||
esac
|
|
||||||
|
|
||||||
case $FORMAT in
|
case $FORMAT in
|
||||||
kvm|qcow2) FORMAT=qcow2
|
kvm|qcow2) FORMAT=qcow2
|
||||||
TARGET=kvm
|
TARGET=kvm
|
||||||
;;
|
;;
|
||||||
vmserver|vmdk) FORMAT=vmdk
|
vmserver|vmdk)
|
||||||
|
FORMAT=vmdk
|
||||||
TARGET=vmserver
|
TARGET=vmserver
|
||||||
;;
|
;;
|
||||||
vbox|vdi) TARGET=kvm
|
vbox|vdi) TARGET=kvm
|
||||||
FORMAT=vdi
|
FORMAT=vdi
|
||||||
;;
|
;;
|
||||||
vhd|vpc) TARGET=kvm
|
vhd|vpc) TARGET=kvm
|
||||||
FORMAT=vpc
|
FORMAT=vhd
|
||||||
;;
|
;;
|
||||||
*) echo "Unknown format: $FORMAT"
|
*) echo "Unknown format: $FORMAT"
|
||||||
usage
|
usage
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
case $RELEASE in
|
||||||
|
natty) ;;
|
||||||
|
maverick) ;;
|
||||||
|
lucid) ;;
|
||||||
|
karmic) ;;
|
||||||
|
jaunty) ;;
|
||||||
|
*) if [ ! -r $RELEASE.$FORMAT ]; then
|
||||||
|
echo "Unknown release: $RELEASE"
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
GLANCE=`which glance`
|
GLANCE=`which glance`
|
||||||
if [ -z "$GLANCE" ]; then
|
if [ -z "$GLANCE" ]; then
|
||||||
|
if [ -x "/opt/glance/bin/glance" ]; then
|
||||||
|
# Look for stack.sh's install
|
||||||
|
GLANCE="/opt/glance/bin/glance"
|
||||||
|
else
|
||||||
|
# Install Glance client in /opt
|
||||||
echo "Glance not found, must install client"
|
echo "Glance not found, must install client"
|
||||||
|
OWD=`pwd`
|
||||||
|
cd /opt
|
||||||
sudo apt-get install python-pip python-eventlet python-routes python-greenlet python-argparse python-sqlalchemy python-wsgiref python-pastedeploy python-xattr
|
sudo apt-get install python-pip python-eventlet python-routes python-greenlet python-argparse python-sqlalchemy python-wsgiref python-pastedeploy python-xattr
|
||||||
sudo pip install kombu
|
sudo pip install kombu
|
||||||
git clone https://github.com/cloudbuilders/glance.git
|
sudo git clone https://github.com/cloudbuilders/glance.git
|
||||||
cd glance
|
cd glance
|
||||||
sudo python setup.py develop
|
sudo python setup.py develop
|
||||||
cd ..
|
cd $OWD
|
||||||
GLANCE=`which glance`
|
GLANCE=`which glance`
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Create image if it doesn't exist
|
# Create image if it doesn't exist
|
||||||
if [ ! -r $RELEASE.$FORMAT ]; then
|
if [ ! -r $RELEASE.$FORMAT ]; then
|
||||||
DIR=`dirname $0`
|
DIR=`dirname $0`
|
||||||
echo "$RELEASE.$FORMAT not found, creating...must be root to do this:"
|
echo "$RELEASE.$FORMAT not found, creating..."
|
||||||
$DIR/make_image.sh $RELEASE $FORMAT
|
$DIR/make_image.sh $RELEASE $FORMAT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Upload the image
|
# Upload the image
|
||||||
|
echo "Uploading image $RELEASE.$FORMAT to $HOST"
|
||||||
$GLANCE add name=$RELEASE.$FORMAT is_public=true disk_format=$FORMAT --host $HOST --port $PORT <$RELEASE.$FORMAT
|
$GLANCE add name=$RELEASE.$FORMAT is_public=true disk_format=$FORMAT --host $HOST --port $PORT <$RELEASE.$FORMAT
|
||||||
|
|
Loading…
Reference in a new issue