From 4dd420e333e7bd4b46b317a245c3f1ad6eb9fbed Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Fri, 16 Sep 2011 16:16:34 -0500 Subject: [PATCH 1/2] Image script cleanups --- README | 2 +- make_image.sh | 79 ++++++++++++++++++++---------------- upload_image.sh | 105 +++++++++++++++++++++++++----------------------- 3 files changed, 100 insertions(+), 86 deletions(-) diff --git a/README b/README index c30f61c..299bd6c 100644 --- a/README +++ b/README @@ -9,7 +9,6 @@ Tool to build (nfs export) openstack dev environments * check openstack-puppet recipes to see if anything else is missing * allow rabbit connection to be specified via environment variables with sensible defaults * 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) * change method of invoking stack.sh to ./stack.sh all _or_ ./stack.sh nova-compute,nova-network,nova-api,nova-volume * Add quantum support @@ -19,6 +18,7 @@ Tool to build (nfs export) openstack dev environments * sqlconn can be set via env * move back to using sudo * move nova to mysql +* create images via vmbuilder and upload images via glance # Future diff --git a/make_image.sh b/make_image.sh index 9b5c10c..28b2eac 100755 --- a/make_image.sh +++ b/make_image.sh @@ -19,14 +19,14 @@ usage() { while getopts hm:r:s: c; do case $c in - h) usage - ;; - m) MIRROR=$OPTARG - ;; - r) ROOTSIZE=$OPTARG - ;; - s) SWAPSIZE=$OPTARG - ;; + h) usage + ;; + m) MIRROR=$OPTARG + ;; + r) ROOTSIZE=$OPTARG + ;; + s) SWAPSIZE=$OPTARG + ;; esac done shift `expr $OPTIND - 1` @@ -34,38 +34,43 @@ shift `expr $OPTIND - 1` RELEASE=$1 FORMAT=$2 -case $RELEASE in - natty) ;; - maverick) ;; - lucid) ;; - karmic) ;; - jaunty) ;; - *) echo "Unknown release: $RELEASE" - usage +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=vhd + ;; + xen) FORMAT=raw + TARGET=xen + ;; + *) echo "Unknown format: $FORMAT" + 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 +case $RELEASE in + natty) ;; + maverick) ;; + lucid) ;; + karmic) ;; + jaunty) ;; + *) echo "Unknown release: $RELEASE" + usage + ;; esac # Install stuff if necessary if [ -z `which vmbuilder` ]; then - sudo apt-get install ubuntu-vm-builder + sudo apt-get install ubuntu-vm-builder fi # Build the image @@ -83,6 +88,10 @@ if [ -z "$FINAL_FORMAT" ]; then mv ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FORMAT else # 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 rm -rf ubuntu-$TARGET diff --git a/upload_image.sh b/upload_image.sh index 8436b76..39a2fba 100755 --- a/upload_image.sh +++ b/upload_image.sh @@ -1,30 +1,24 @@ #!/bin/bash # upload_image.sh - Upload Ubuntu images (create if necessary) in various formats -# -# upload_image.sh release format -# -# format target -# qcow2 kvm,qemu -# vmdk vmw6 -# vbox vdi -# vhd vpc - -HOST=${HOST:-demo.rcb.me} -PORT=${PORT:-9292} +# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc) +# Requires sudo to root usage() { - echo "$0 - Upload Ubuntu images" + echo "$0 - Upload images to OpenStack" echo "" echo "$0 [-h host] [-p port] release format" exit 1 } +HOST=${HOST:-localhost} +PORT=${PORT:-9292} + while getopts h:p: c; do case $c in - h) HOST=$OPTARG - ;; - p) PORT=$OPTARG - ;; + h) HOST=$OPTARG + ;; + p) PORT=$OPTARG + ;; esac done shift `expr $OPTIND - 1` @@ -32,50 +26,61 @@ shift `expr $OPTIND - 1` RELEASE=$1 FORMAT=$2 -case $RELEASE in - natty) ;; - maverick) ;; - lucid) ;; - karmic) ;; - jaunty) ;; - *) echo "Unknown release: $RELEASE" - usage +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 esac -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=vpc - ;; - *) echo "Unknown format: $FORMAT" - usage +case $RELEASE in + natty) ;; + maverick) ;; + lucid) ;; + karmic) ;; + jaunty) ;; + *) if [ ! -r $RELEASE.$FORMAT ]; then + echo "Unknown release: $RELEASE" + usage + fi + ;; esac GLANCE=`which glance` if [ -z "$GLANCE" ]; then - echo "Glance not found, must install client" - 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 - git clone https://github.com/cloudbuilders/glance.git - cd glance - sudo python setup.py develop - cd .. - GLANCE=`which glance` + if [ -x "/opt/glance/bin/glance" ]; then + # Look for stack.sh's install + GLANCE="/opt/glance/bin/glance" + else + 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 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 # Create image if it doesn't exist if [ ! -r $RELEASE.$FORMAT ]; then - DIR=`dirname $0` - echo "$RELEASE.$FORMAT not found, creating...must be root to do this:" - $DIR/make_image.sh $RELEASE $FORMAT + DIR=`dirname $0` + echo "$RELEASE.$FORMAT not found, creating...must be root to do this:" + $DIR/make_image.sh $RELEASE $FORMAT fi # Upload the image From 57794d4842fdbcb29fe2e1f2a25957b6d567fbf5 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Fri, 16 Sep 2011 17:22:23 -0500 Subject: [PATCH 2/2] Add raw image support --- make_image.sh | 48 +++++++++++++++++++++++++++--------------------- upload_image.sh | 4 +++- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/make_image.sh b/make_image.sh index 28b2eac..3bfa683 100755 --- a/make_image.sh +++ b/make_image.sh @@ -3,7 +3,7 @@ # # 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 @@ -36,22 +36,29 @@ FORMAT=$2 case $FORMAT in kvm|qcow2) FORMAT=qcow2 - TARGET=kvm + QFORMAT=qcow2 + HYPER=kvm ;; vmserver|vmdk) FORMAT=vmdk - TARGET=vmserver + QFORMAT=vmdk + HYPER=vmserver ;; - vbox|vdi) FORMAT=qcow2 - TARGET=kvm - FINAL_FORMAT=vdi + vbox|vdi) FORMAT=vdi + QFORMAT=vdi + HYPER=kvm ;; - vhd|vpc) FORMAT=qcow2 - TARGET=kvm - FINAL_FORMAT=vhd + vhd|vpc) FORMAT=vhd + QFORMAT=vpc + HYPER=kvm ;; xen) FORMAT=raw - TARGET=xen + QFORMAT=raw + HYPER=xen + ;; + raw) FORMAT=raw + QFORMAT=raw + HYPER=kvm ;; *) echo "Unknown format: $FORMAT" usage @@ -74,24 +81,23 @@ if [ -z `which vmbuilder` ]; then fi # 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 \ --rootsize=$ROOTSIZE \ --swapsize=$SWAPSIZE \ --tmpfs - \ --addpkg=openssh-server \ + --raw=$TMPDISK \ -# --mirror=$MIRROR \ - -if [ -z "$FINAL_FORMAT" ]; then +if [ "$FORMAT" = "raw" ]; then # Get image - mv ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FORMAT + mv $TMPDISK $RELEASE.$FORMAT else # Convert image - tgt=$FINAL_FORMAT - if [ "$tgt" = "vhd" ]; then - tgt=vpc - fi - qemu-img convert -O $tgt ubuntu-$TARGET/tmp*.$FORMAT $RELEASE.$FINAL_FORMAT + qemu-img convert -O $QFORMAT $TMPDISK $RELEASE.$FORMAT + rm $TMPDISK fi -rm -rf ubuntu-$TARGET +rm -rf ubuntu-$HYPER diff --git a/upload_image.sh b/upload_image.sh index 39a2fba..cf913b8 100755 --- a/upload_image.sh +++ b/upload_image.sh @@ -63,6 +63,7 @@ if [ -z "$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" OWD=`pwd` cd /opt @@ -79,9 +80,10 @@ fi # Create image if it doesn't exist if [ ! -r $RELEASE.$FORMAT ]; then 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 fi # 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