devstack_custom/upload_image.sh

91 lines
2.3 KiB
Bash
Raw Normal View History

2011-09-16 17:22:21 +00:00
#!/bin/bash
# upload_image.sh - Upload Ubuntu images (create if necessary) in various formats
2011-09-16 21:16:34 +00:00
# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc)
# Requires sudo to root
2011-09-16 17:22:21 +00:00
usage() {
2011-09-16 21:16:34 +00:00
echo "$0 - Upload images to OpenStack"
2011-09-16 17:22:21 +00:00
echo ""
echo "$0 [-h host] [-p port] release format"
exit 1
}
2011-09-16 21:16:34 +00:00
HOST=${HOST:-localhost}
PORT=${PORT:-9292}
2011-09-27 02:50:43 +00:00
DEST=${DEST:-/opt/stack}
2011-09-16 21:16:34 +00:00
2011-09-16 17:22:21 +00:00
while getopts h:p: c; do
case $c in
2011-09-16 21:16:34 +00:00
h) HOST=$OPTARG
;;
p) PORT=$OPTARG
;;
2011-09-16 17:22:21 +00:00
esac
done
shift `expr $OPTIND - 1`
RELEASE=$1
FORMAT=$2
2011-09-16 21:16:34 +00:00
case $FORMAT in
kvm|qcow2) FORMAT=qcow2
TARGET=kvm
;;
vmserver|vmdk)
FORMAT=vmdk
TARGET=vmserver
;;
vbox|vdi) TARGET=kvm
FORMAT=vdi
;;
vhd|vpc) TARGET=kvm
FORMAT=vhd
;;
*) echo "Unknown format: $FORMAT"
usage
2011-09-16 17:22:21 +00:00
esac
2011-09-16 21:16:34 +00:00
case $RELEASE in
natty) ;;
maverick) ;;
lucid) ;;
karmic) ;;
jaunty) ;;
*) if [ ! -r $RELEASE.$FORMAT ]; then
echo "Unknown release: $RELEASE"
usage
fi
;;
2011-09-16 17:22:21 +00:00
esac
GLANCE=`which glance`
if [ -z "$GLANCE" ]; then
2011-09-27 02:50:43 +00:00
if [ -x "$DEST/glance/bin/glance" ]; then
2011-09-16 21:16:34 +00:00
# Look for stack.sh's install
2011-09-27 02:50:43 +00:00
GLANCE="$DEST/glance/bin/glance"
2011-09-16 21:16:34 +00:00
else
2011-09-27 02:50:43 +00:00
# Install Glance client in $DEST
2011-09-16 21:16:34 +00:00
echo "Glance not found, must install client"
OWD=`pwd`
2011-09-27 02:50:43 +00:00
cd $DEST
2011-09-16 21:16:34 +00:00
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 git clone https://github.com/cloudbuilders/glance.git
cd glance
sudo python setup.py develop
cd $OWD
GLANCE=`which glance`
fi
2011-09-16 17:22:21 +00:00
fi
# Create image if it doesn't exist
if [ ! -r $RELEASE.$FORMAT ]; then
2011-09-16 21:16:34 +00:00
DIR=`dirname $0`
2011-09-16 22:22:23 +00:00
echo "$RELEASE.$FORMAT not found, creating..."
2011-09-16 21:16:34 +00:00
$DIR/make_image.sh $RELEASE $FORMAT
2011-09-16 17:22:21 +00:00
fi
# Upload the image
2011-09-16 22:22:23 +00:00
echo "Uploading image $RELEASE.$FORMAT to $HOST"
2011-09-16 17:22:21 +00:00
$GLANCE add name=$RELEASE.$FORMAT is_public=true disk_format=$FORMAT --host $HOST --port $PORT <$RELEASE.$FORMAT