2011-09-28 09:30:57 +00:00
|
|
|
#!/bin/bash
|
2011-10-12 00:39:34 +00:00
|
|
|
# build_ramdisk.sh - Build RAM disk images
|
2011-09-28 09:30:57 +00:00
|
|
|
|
|
|
|
if [ ! "$#" -eq "1" ]; then
|
|
|
|
echo "$0 builds a gziped natty openstack install"
|
|
|
|
echo "usage: $0 dest"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-09-29 21:38:59 +00:00
|
|
|
PROGDIR=`dirname $0`
|
2011-10-04 02:16:27 +00:00
|
|
|
CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
|
2011-09-29 21:38:59 +00:00
|
|
|
|
2011-09-28 09:30:57 +00:00
|
|
|
# Source params
|
|
|
|
source ./stackrc
|
|
|
|
|
2011-10-03 14:56:41 +00:00
|
|
|
# Store cwd
|
|
|
|
CWD=`pwd`
|
|
|
|
|
2011-10-03 14:40:32 +00:00
|
|
|
DEST=${DEST:-/opt/stack}
|
|
|
|
|
2011-10-12 01:22:23 +00:00
|
|
|
# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
|
|
|
|
STACKSH_PARAMS=${STACKSH_PARAMS:-}
|
|
|
|
|
2011-10-03 16:14:13 +00:00
|
|
|
# Option to use the version of devstack on which we are currently working
|
|
|
|
USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
|
|
|
|
|
2011-09-28 09:30:57 +00:00
|
|
|
# clean install of natty
|
2011-10-03 14:14:36 +00:00
|
|
|
if [ ! -d $CHROOTCACHE/natty-base ]; then
|
|
|
|
$PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base
|
2011-09-28 09:30:57 +00:00
|
|
|
# copy kernel modules...
|
|
|
|
# NOTE(ja): is there a better way to do this?
|
2011-10-03 14:14:36 +00:00
|
|
|
cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
|
2011-09-29 21:38:59 +00:00
|
|
|
# a simple password - pass
|
2011-10-03 14:14:36 +00:00
|
|
|
echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
|
2011-09-28 09:30:57 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# prime natty with as many apt/pips as we can
|
2011-10-03 14:14:36 +00:00
|
|
|
if [ ! -d $CHROOTCACHE/natty-dev ]; then
|
|
|
|
rsync -azH $CHROOTCACHE/natty-base/ $CHROOTCACHE/natty-dev/
|
|
|
|
chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
|
|
|
|
chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*`
|
2011-09-28 09:30:57 +00:00
|
|
|
|
|
|
|
# Create a stack user that is a member of the libvirtd group so that stack
|
|
|
|
# is able to interact with libvirt.
|
2011-10-03 14:14:36 +00:00
|
|
|
chroot $CHROOTCACHE/natty-dev groupadd libvirtd
|
2011-10-03 14:40:32 +00:00
|
|
|
chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d $DEST -G libvirtd
|
|
|
|
mkdir -p $CHROOTCACHE/natty-dev/$DEST
|
|
|
|
chown stack $CHROOTCACHE/natty-dev/$DEST
|
2011-09-28 09:30:57 +00:00
|
|
|
|
|
|
|
# a simple password - pass
|
2011-10-03 14:14:36 +00:00
|
|
|
echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd
|
2011-09-28 09:30:57 +00:00
|
|
|
|
|
|
|
# and has sudo ability (in the future this should be limited to only what
|
|
|
|
# stack requires)
|
2011-10-03 14:14:36 +00:00
|
|
|
echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers
|
2011-09-28 09:30:57 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# clone git repositories onto the system
|
|
|
|
# ======================================
|
|
|
|
|
2011-10-03 14:14:36 +00:00
|
|
|
if [ ! -d $CHROOTCACHE/natty-stack ]; then
|
|
|
|
rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/
|
2011-09-28 09:30:57 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# git clone only if directory doesn't exist already. Since ``DEST`` might not
|
|
|
|
# be owned by the installation user, we create the directory and change the
|
|
|
|
# ownership to the proper user.
|
|
|
|
function git_clone {
|
|
|
|
|
|
|
|
# clone new copy or fetch latest changes
|
2011-10-03 14:14:36 +00:00
|
|
|
CHECKOUT=$CHROOTCACHE/natty-stack$2
|
2011-09-28 09:30:57 +00:00
|
|
|
if [ ! -d $CHECKOUT ]; then
|
|
|
|
mkdir -p $CHECKOUT
|
|
|
|
git clone $1 $CHECKOUT
|
|
|
|
else
|
|
|
|
pushd $CHECKOUT
|
|
|
|
git fetch
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
|
|
|
# FIXME(ja): checkout specified version (should works for branches and tags)
|
|
|
|
|
|
|
|
pushd $CHECKOUT
|
|
|
|
# checkout the proper branch/tag
|
|
|
|
git checkout $3
|
|
|
|
# force our local version to be the same as the remote version
|
|
|
|
git reset --hard origin/$3
|
|
|
|
popd
|
|
|
|
|
|
|
|
# give ownership to the stack user
|
2011-10-03 14:14:36 +00:00
|
|
|
chroot $CHROOTCACHE/natty-stack/ chown -R stack $2
|
2011-09-28 09:30:57 +00:00
|
|
|
}
|
|
|
|
|
2011-10-03 14:40:32 +00:00
|
|
|
git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
|
|
|
|
git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
|
|
|
|
git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
|
|
|
|
git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
|
|
|
|
git_clone $DASH_REPO $DEST/dash $DASH_BRANCH
|
|
|
|
git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
|
|
|
|
git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
|
2011-09-28 09:30:57 +00:00
|
|
|
|
2011-10-03 14:56:41 +00:00
|
|
|
# Use this version of devstack?
|
|
|
|
if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then
|
2011-10-03 16:16:32 +00:00
|
|
|
rm -rf $CHROOTCACHE/natty-stack/$DEST/devstack
|
2011-10-03 16:03:27 +00:00
|
|
|
cp -pr $CWD $CHROOTCACHE/natty-stack/$DEST/devstack
|
2011-10-03 14:56:41 +00:00
|
|
|
fi
|
|
|
|
|
2011-10-03 18:42:16 +00:00
|
|
|
# Configure host network for DHCP
|
|
|
|
mkdir -p $CHROOTCACHE/natty-stack/etc/network
|
2011-10-04 02:16:27 +00:00
|
|
|
cat > $CHROOTCACHE/natty-stack/etc/network/interfaces <<EOF
|
2011-10-03 18:42:16 +00:00
|
|
|
auto lo
|
|
|
|
iface lo inet loopback
|
|
|
|
|
|
|
|
auto eth0
|
|
|
|
iface eth0 inet dhcp
|
|
|
|
EOF
|
|
|
|
|
2011-10-12 01:22:23 +00:00
|
|
|
# Configure the runner
|
|
|
|
RUN_SH=$CHROOTCACHE/natty-stack/$DEST/run.sh
|
|
|
|
cat > $RUN_SH <<EOF
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2011-10-13 18:20:13 +00:00
|
|
|
# Get IP range
|
|
|
|
set \`ip addr show dev eth0 | grep inet\`
|
|
|
|
PREFIX=\`echo \$2 | cut -d. -f1,2,3\`
|
|
|
|
export FLOATING_RANGE="\$PREFIX.224/27"
|
|
|
|
|
2011-10-12 01:22:23 +00:00
|
|
|
# Pre-empt download of natty image
|
|
|
|
tar czf $DEST/devstack/files/natty.tgz /etc/hosts
|
2011-10-13 18:20:13 +00:00
|
|
|
mkdir -p $DEST/devstack/files/images
|
2011-10-12 01:22:23 +00:00
|
|
|
touch $DEST/devstack/files/images/natty-server-cloudimg-amd64-vmlinuz-virtual
|
|
|
|
touch $DEST/devstack/files/images/natty-server-cloudimg-amd64.img
|
|
|
|
|
|
|
|
# Kill any existing screens
|
|
|
|
killall screen
|
|
|
|
|
|
|
|
# Run stack.sh
|
|
|
|
cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log
|
|
|
|
echo >> $DEST/run.sh.log
|
|
|
|
echo >> $DEST/run.sh.log
|
|
|
|
echo "All done! Time to start clicking." >> $DEST/run.sh.log
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Make the run.sh executable
|
|
|
|
chmod 755 $RUN_SH
|
2011-10-13 18:20:13 +00:00
|
|
|
chroot $CHROOTCACHE/natty-stack chown stack $DEST/run.sh
|
2011-10-12 01:22:23 +00:00
|
|
|
|
2011-09-28 09:30:57 +00:00
|
|
|
# build a new image
|
2011-10-03 16:16:32 +00:00
|
|
|
BASE=$CHROOTCACHE/build.$$
|
2011-09-28 09:30:57 +00:00
|
|
|
IMG=$BASE.img
|
|
|
|
MNT=$BASE/
|
|
|
|
|
2011-09-29 01:38:10 +00:00
|
|
|
# (quickly) create a 2GB blank filesystem
|
|
|
|
dd bs=1 count=1 seek=$((2*1024*1024*1024)) if=/dev/zero of=$IMG
|
2011-09-28 09:30:57 +00:00
|
|
|
# force it to be initialized as ext2
|
|
|
|
mkfs.ext2 -F $IMG
|
|
|
|
|
|
|
|
# mount blank image loopback and load it
|
|
|
|
mkdir -p $MNT
|
|
|
|
mount -o loop $IMG $MNT
|
2011-10-03 14:14:36 +00:00
|
|
|
rsync -azH $CHROOTCACHE/natty-stack/ $MNT
|
2011-09-28 09:30:57 +00:00
|
|
|
|
|
|
|
# umount and cleanup
|
|
|
|
umount $MNT
|
|
|
|
rmdir $MNT
|
|
|
|
|
|
|
|
# gzip into final location
|
|
|
|
gzip -1 $IMG -c > $1
|
|
|
|
|