blob: 39a2fba1e940e302eca96e5df6f1640d067ef77b [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}
15
Dean Troyer65cf6082011-09-16 12:22:21 -050016while getopts h:p: c; do
17 case $c in
Dean Troyer4dd420e2011-09-16 16:16:34 -050018 h) HOST=$OPTARG
19 ;;
20 p) PORT=$OPTARG
21 ;;
Dean Troyer65cf6082011-09-16 12:22:21 -050022 esac
23done
24shift `expr $OPTIND - 1`
25
26RELEASE=$1
27FORMAT=$2
28
Dean Troyer4dd420e2011-09-16 16:16:34 -050029case $FORMAT in
30 kvm|qcow2) FORMAT=qcow2
31 TARGET=kvm
32 ;;
33 vmserver|vmdk)
34 FORMAT=vmdk
35 TARGET=vmserver
36 ;;
37 vbox|vdi) TARGET=kvm
38 FORMAT=vdi
39 ;;
40 vhd|vpc) TARGET=kvm
41 FORMAT=vhd
42 ;;
43 *) echo "Unknown format: $FORMAT"
44 usage
Dean Troyer65cf6082011-09-16 12:22:21 -050045esac
46
Dean Troyer4dd420e2011-09-16 16:16:34 -050047case $RELEASE in
48 natty) ;;
49 maverick) ;;
50 lucid) ;;
51 karmic) ;;
52 jaunty) ;;
53 *) if [ ! -r $RELEASE.$FORMAT ]; then
54 echo "Unknown release: $RELEASE"
55 usage
56 fi
57 ;;
Dean Troyer65cf6082011-09-16 12:22:21 -050058esac
59
60GLANCE=`which glance`
61if [ -z "$GLANCE" ]; then
Dean Troyer4dd420e2011-09-16 16:16:34 -050062 if [ -x "/opt/glance/bin/glance" ]; then
63 # Look for stack.sh's install
64 GLANCE="/opt/glance/bin/glance"
65 else
66 echo "Glance not found, must install client"
67 OWD=`pwd`
68 cd /opt
69 sudo apt-get install python-pip python-eventlet python-routes python-greenlet python-argparse python-sqlalchemy python-wsgiref python-pastedeploy python-xattr
70 sudo pip install kombu
71 sudo git clone https://github.com/cloudbuilders/glance.git
72 cd glance
73 sudo python setup.py develop
74 cd $OWD
75 GLANCE=`which glance`
76 fi
Dean Troyer65cf6082011-09-16 12:22:21 -050077fi
78
79# Create image if it doesn't exist
80if [ ! -r $RELEASE.$FORMAT ]; then
Dean Troyer4dd420e2011-09-16 16:16:34 -050081 DIR=`dirname $0`
82 echo "$RELEASE.$FORMAT not found, creating...must be root to do this:"
83 $DIR/make_image.sh $RELEASE $FORMAT
Dean Troyer65cf6082011-09-16 12:22:21 -050084fi
85
86# Upload the image
87$GLANCE add name=$RELEASE.$FORMAT is_public=true disk_format=$FORMAT --host $HOST --port $PORT <$RELEASE.$FORMAT