blob: da73f16af6ae7d57d5808249a9c0c2b3be7ca499 [file] [log] [blame]
Dean Troyer65cf6082011-09-16 12:22:21 -05001#!/bin/bash
2# upload_image.sh - Upload Ubuntu images (create if necessary) in various formats
Dean Troyer4dd420e2011-09-16 16:16:34 -05003# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc)
4# Requires sudo to root
Dean Troyer65cf6082011-09-16 12:22:21 -05005
6usage() {
Dean Troyer4dd420e2011-09-16 16:16:34 -05007 echo "$0 - Upload images to OpenStack"
Dean Troyer65cf6082011-09-16 12:22:21 -05008 echo ""
9 echo "$0 [-h host] [-p port] release format"
10 exit 1
11}
12
Dean Troyer4dd420e2011-09-16 16:16:34 -050013HOST=${HOST:-localhost}
14PORT=${PORT:-9292}
Anthony Younge8fed482011-09-26 19:50:43 -070015DEST=${DEST:-/opt/stack}
Dean Troyer4dd420e2011-09-16 16:16:34 -050016
Dean Troyer65cf6082011-09-16 12:22:21 -050017while getopts h:p: c; do
18 case $c in
Dean Troyer4dd420e2011-09-16 16:16:34 -050019 h) HOST=$OPTARG
20 ;;
21 p) PORT=$OPTARG
22 ;;
Dean Troyer65cf6082011-09-16 12:22:21 -050023 esac
24done
25shift `expr $OPTIND - 1`
26
27RELEASE=$1
28FORMAT=$2
29
Dean Troyer4dd420e2011-09-16 16:16:34 -050030case $FORMAT in
31 kvm|qcow2) FORMAT=qcow2
32 TARGET=kvm
33 ;;
34 vmserver|vmdk)
35 FORMAT=vmdk
36 TARGET=vmserver
37 ;;
38 vbox|vdi) TARGET=kvm
39 FORMAT=vdi
40 ;;
41 vhd|vpc) TARGET=kvm
42 FORMAT=vhd
43 ;;
44 *) echo "Unknown format: $FORMAT"
45 usage
Dean Troyer65cf6082011-09-16 12:22:21 -050046esac
47
Dean Troyer4dd420e2011-09-16 16:16:34 -050048case $RELEASE in
49 natty) ;;
50 maverick) ;;
51 lucid) ;;
52 karmic) ;;
53 jaunty) ;;
54 *) if [ ! -r $RELEASE.$FORMAT ]; then
55 echo "Unknown release: $RELEASE"
56 usage
57 fi
58 ;;
Dean Troyer65cf6082011-09-16 12:22:21 -050059esac
60
61GLANCE=`which glance`
62if [ -z "$GLANCE" ]; then
Anthony Younge8fed482011-09-26 19:50:43 -070063 if [ -x "$DEST/glance/bin/glance" ]; then
Dean Troyer4dd420e2011-09-16 16:16:34 -050064 # Look for stack.sh's install
Anthony Younge8fed482011-09-26 19:50:43 -070065 GLANCE="$DEST/glance/bin/glance"
Dean Troyer4dd420e2011-09-16 16:16:34 -050066 else
Anthony Younge8fed482011-09-26 19:50:43 -070067 # Install Glance client in $DEST
Dean Troyer4dd420e2011-09-16 16:16:34 -050068 echo "Glance not found, must install client"
69 OWD=`pwd`
Anthony Younge8fed482011-09-26 19:50:43 -070070 cd $DEST
Dean Troyer4dd420e2011-09-16 16:16:34 -050071 sudo apt-get install python-pip python-eventlet python-routes python-greenlet python-argparse python-sqlalchemy python-wsgiref python-pastedeploy python-xattr
72 sudo pip install kombu
73 sudo git clone https://github.com/cloudbuilders/glance.git
74 cd glance
75 sudo python setup.py develop
76 cd $OWD
77 GLANCE=`which glance`
78 fi
Dean Troyer65cf6082011-09-16 12:22:21 -050079fi
80
81# Create image if it doesn't exist
82if [ ! -r $RELEASE.$FORMAT ]; then
Dean Troyer4dd420e2011-09-16 16:16:34 -050083 DIR=`dirname $0`
Dean Troyer57794d42011-09-16 17:22:23 -050084 echo "$RELEASE.$FORMAT not found, creating..."
Dean Troyer4dd420e2011-09-16 16:16:34 -050085 $DIR/make_image.sh $RELEASE $FORMAT
Dean Troyer65cf6082011-09-16 12:22:21 -050086fi
87
88# Upload the image
Dean Troyer57794d42011-09-16 17:22:23 -050089echo "Uploading image $RELEASE.$FORMAT to $HOST"
Dean Troyer65cf6082011-09-16 12:22:21 -050090$GLANCE add name=$RELEASE.$FORMAT is_public=true disk_format=$FORMAT --host $HOST --port $PORT <$RELEASE.$FORMAT