Image script cleanups

This commit is contained in:
Dean Troyer 2011-09-16 16:16:34 -05:00
parent 8cceaa20b1
commit 4dd420e333
3 changed files with 100 additions and 86 deletions

2
README
View File

@ -9,7 +9,6 @@ Tool to build (nfs export) openstack dev environments
* check openstack-puppet recipes to see if anything else is missing * check openstack-puppet recipes to see if anything else is missing
* allow rabbit connection to be specified via environment variables with sensible defaults * allow rabbit connection to be specified via environment variables with sensible defaults
* Add volume support * Add volume support
* extract image upload to a seperate script that supports generating images via debootstrap (ubuntu-vm-builder?)
* allow changing of git locations (specify different tag/branch or repos) * allow changing of git locations (specify different tag/branch or repos)
* change method of invoking stack.sh to ./stack.sh all _or_ ./stack.sh nova-compute,nova-network,nova-api,nova-volume * change method of invoking stack.sh to ./stack.sh all _or_ ./stack.sh nova-compute,nova-network,nova-api,nova-volume
* Add quantum support * Add quantum support
@ -19,6 +18,7 @@ Tool to build (nfs export) openstack dev environments
* sqlconn can be set via env * sqlconn can be set via env
* move back to using sudo * move back to using sudo
* move nova to mysql * move nova to mysql
* create images via vmbuilder and upload images via glance
# Future # Future

View File

@ -19,14 +19,14 @@ usage() {
while getopts hm:r:s: c; do while getopts hm:r:s: c; do
case $c in case $c in
h) usage h) usage
;; ;;
m) MIRROR=$OPTARG m) MIRROR=$OPTARG
;; ;;
r) ROOTSIZE=$OPTARG r) ROOTSIZE=$OPTARG
;; ;;
s) SWAPSIZE=$OPTARG s) SWAPSIZE=$OPTARG
;; ;;
esac esac
done done
shift `expr $OPTIND - 1` shift `expr $OPTIND - 1`
@ -34,38 +34,43 @@ shift `expr $OPTIND - 1`
RELEASE=$1 RELEASE=$1
FORMAT=$2 FORMAT=$2
case $RELEASE in case $FORMAT in
natty) ;; kvm|qcow2) FORMAT=qcow2
maverick) ;; TARGET=kvm
lucid) ;; ;;
karmic) ;; vmserver|vmdk)
jaunty) ;; FORMAT=vmdk
*) echo "Unknown release: $RELEASE" TARGET=vmserver
usage ;;
vbox|vdi) FORMAT=qcow2
TARGET=kvm
FINAL_FORMAT=vdi
;;
vhd|vpc) FORMAT=qcow2
TARGET=kvm
FINAL_FORMAT=vhd
;;
xen) FORMAT=raw
TARGET=xen
;;
*) echo "Unknown format: $FORMAT"
usage
esac esac
case $FORMAT in case $RELEASE in
kvm|qcow2) FORMAT=qcow2 natty) ;;
TARGET=kvm maverick) ;;
;; lucid) ;;
vmserver|vmdk) FORMAT=vmdk karmic) ;;
TARGET=vmserver jaunty) ;;
;; *) echo "Unknown release: $RELEASE"
vbox|vdi) FORMAT=qcow2 usage
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
if [ -z `which vmbuilder` ]; then if [ -z `which vmbuilder` ]; then
sudo apt-get install ubuntu-vm-builder sudo apt-get install ubuntu-vm-builder
fi fi
# Build the image # Build the image
@ -83,6 +88,10 @@ if [ -z "$FINAL_FORMAT" ]; then
mv ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FORMAT mv ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FORMAT
else else
# Convert image # Convert image
qemu-img convert -O $FINAL_FORMAT ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FINAL_FORMAT tgt=$FINAL_FORMAT
if [ "$tgt" = "vhd" ]; then
tgt=vpc
fi
qemu-img convert -O $tgt ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FINAL_FORMAT
fi fi
rm -rf ubuntu-$TARGET rm -rf ubuntu-$TARGET

View File

@ -1,30 +1,24 @@
#!/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
;; ;;
p) PORT=$OPTARG p) PORT=$OPTARG
;; ;;
esac esac
done done
shift `expr $OPTIND - 1` shift `expr $OPTIND - 1`
@ -32,50 +26,61 @@ shift `expr $OPTIND - 1`
RELEASE=$1 RELEASE=$1
FORMAT=$2 FORMAT=$2
case $RELEASE in case $FORMAT in
natty) ;; kvm|qcow2) FORMAT=qcow2
maverick) ;; TARGET=kvm
lucid) ;; ;;
karmic) ;; vmserver|vmdk)
jaunty) ;; FORMAT=vmdk
*) echo "Unknown release: $RELEASE" TARGET=vmserver
usage ;;
vbox|vdi) TARGET=kvm
FORMAT=vdi
;;
vhd|vpc) TARGET=kvm
FORMAT=vhd
;;
*) echo "Unknown format: $FORMAT"
usage
esac esac
case $FORMAT in case $RELEASE in
kvm|qcow2) FORMAT=qcow2 natty) ;;
TARGET=kvm maverick) ;;
;; lucid) ;;
vmserver|vmdk) FORMAT=vmdk karmic) ;;
TARGET=vmserver jaunty) ;;
;; *) if [ ! -r $RELEASE.$FORMAT ]; then
vbox|vdi) TARGET=kvm echo "Unknown release: $RELEASE"
FORMAT=vdi usage
;; fi
vhd|vpc) TARGET=kvm ;;
FORMAT=vpc
;;
*) echo "Unknown format: $FORMAT"
usage
esac esac
GLANCE=`which glance` GLANCE=`which glance`
if [ -z "$GLANCE" ]; then if [ -z "$GLANCE" ]; then
echo "Glance not found, must install client" if [ -x "/opt/glance/bin/glance" ]; then
sudo apt-get install python-pip python-eventlet python-routes python-greenlet python-argparse python-sqlalchemy python-wsgiref python-pastedeploy python-xattr # Look for stack.sh's install
sudo pip install kombu GLANCE="/opt/glance/bin/glance"
git clone https://github.com/cloudbuilders/glance.git else
cd glance echo "Glance not found, must install client"
sudo python setup.py develop OWD=`pwd`
cd .. cd /opt
GLANCE=`which glance` 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
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...must be root to do this:"
$DIR/make_image.sh $RELEASE $FORMAT $DIR/make_image.sh $RELEASE $FORMAT
fi fi
# Upload the image # Upload the image