remove old build scripts and clean for those that work
Change-Id: I5c156879f3c85f1555a1411695ac43cefbbf3b99main
parent
38df1228de
commit
d7326d2ea9
@ -1,489 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# exit on error to stop unexpected errors
|
||||
set -o errexit
|
||||
|
||||
# Make sure that we have the proper version of ubuntu
|
||||
UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'`
|
||||
if [ ! "oneiric" = "$UBUNTU_VERSION" ]; then
|
||||
if [ ! "natty" = "$UBUNTU_VERSION" ]; then
|
||||
echo "This script only works with oneiric and natty"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Clean up any resources that may be in use
|
||||
cleanup() {
|
||||
set +o errexit
|
||||
unmount_images
|
||||
|
||||
if [ -n "$COPY_DIR" ]; then
|
||||
umount $COPY_DIR/dev
|
||||
umount $COPY_DIR
|
||||
fi
|
||||
|
||||
if [ -n "$ROOTFS" ]; then
|
||||
umount $ROOTFS/dev
|
||||
umount $ROOTFS
|
||||
fi
|
||||
|
||||
# Release NBD devices
|
||||
if [ -n "$NBD" ]; then
|
||||
qemu-nbd -d $NBD
|
||||
fi
|
||||
|
||||
# Kill ourselves to signal any calling process
|
||||
trap 2; kill -2 $$
|
||||
}
|
||||
|
||||
trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT
|
||||
|
||||
# Echo commands
|
||||
set -o xtrace
|
||||
|
||||
# Keep track of the current directory
|
||||
TOOLS_DIR=$(cd $(dirname "$0") && pwd)
|
||||
TOP_DIR=`cd $TOOLS_DIR/..; pwd`
|
||||
|
||||
# Where to store files and instances
|
||||
WORK_DIR=${WORK_DIR:-/opt/kvmstack}
|
||||
|
||||
# Where to store images
|
||||
IMAGES_DIR=$WORK_DIR/images
|
||||
|
||||
# Create images dir
|
||||
mkdir -p $IMAGES_DIR
|
||||
|
||||
# Abort if localrc is not set
|
||||
if [ ! -e $TOP_DIR/localrc ]; then
|
||||
echo "You must have a localrc with ALL necessary passwords defined before proceeding."
|
||||
echo "See stack.sh for required passwords."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd $TOP_DIR
|
||||
|
||||
# Source params
|
||||
source ./stackrc
|
||||
|
||||
# Configure the root password of the vm to be the same as ``ADMIN_PASSWORD``
|
||||
ROOT_PASSWORD=${ADMIN_PASSWORD:-password}
|
||||
|
||||
# Base image (natty by default)
|
||||
DIST_NAME=${DIST_NAME:-natty}
|
||||
IMAGE_FNAME=$DIST_NAME.raw
|
||||
|
||||
# Name of our instance, used by libvirt
|
||||
GUEST_NAME=${GUEST_NAME:-devstack}
|
||||
|
||||
# Original version of built image
|
||||
BASE_IMAGE=$IMAGES_DIR/$DIST_NAME.raw
|
||||
|
||||
# Copy of base image, which we pre-install with tasty treats
|
||||
VM_IMAGE=$IMAGES_DIR/$DIST_NAME.$GUEST_NAME.raw
|
||||
|
||||
# Mop up after previous runs
|
||||
virsh destroy $GUEST_NAME || true
|
||||
|
||||
# Where this vm is stored
|
||||
VM_DIR=$WORK_DIR/instances/$GUEST_NAME
|
||||
|
||||
# Create vm dir
|
||||
mkdir -p $VM_DIR
|
||||
|
||||
# Mount point into copied base image
|
||||
COPY_DIR=$VM_DIR/copy
|
||||
mkdir -p $COPY_DIR
|
||||
|
||||
# Get the base image if it does not yet exist
|
||||
if [ ! -e $BASE_IMAGE ]; then
|
||||
$TOOLS_DIR/get_uec_image.sh -f raw -r 5000 $DIST_NAME $BASE_IMAGE
|
||||
fi
|
||||
|
||||
# Create a copy of the base image
|
||||
if [ ! -e $VM_IMAGE ]; then
|
||||
cp -p $BASE_IMAGE $VM_IMAGE
|
||||
fi
|
||||
|
||||
# Unmount the copied base image
|
||||
function unmount_images() {
|
||||
# unmount the filesystem
|
||||
while df | grep -q $COPY_DIR; do
|
||||
umount $COPY_DIR || echo 'ok'
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
# Unmount from failed runs
|
||||
unmount_images
|
||||
|
||||
# Ctrl-c catcher
|
||||
function kill_unmount() {
|
||||
unmount_images
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Install deps if needed
|
||||
dpkg -l kvm libvirt-bin kpartx || apt-get install -y --force-yes kvm libvirt-bin kpartx
|
||||
|
||||
# Where Openstack code will live in image
|
||||
DEST=${DEST:-/opt/stack}
|
||||
|
||||
# Mount the file system
|
||||
# For some reason, UEC-based images want 255 heads * 63 sectors * 512 byte sectors = 8225280
|
||||
mount -t ext4 -o loop,offset=8225280 $VM_IMAGE $COPY_DIR
|
||||
mount -o bind /dev $COPY_DIR/dev
|
||||
|
||||
# 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 {
|
||||
if [ ! -d $2 ]; then
|
||||
sudo mkdir $2
|
||||
sudo chown `whoami` $2
|
||||
git clone $1 $2
|
||||
cd $2
|
||||
# This checkout syntax works for both branches and tags
|
||||
git checkout $3
|
||||
fi
|
||||
}
|
||||
|
||||
# Make sure that base requirements are installed
|
||||
cp /etc/resolv.conf $COPY_DIR/etc/resolv.conf
|
||||
chroot $COPY_DIR apt-get update
|
||||
chroot $COPY_DIR apt-get install -y --download-only `cat files/apts/* | grep NOPRIME | cut -d\# -f1`
|
||||
chroot $COPY_DIR apt-get install -y --force-yes `cat files/apts/* | grep -v NOPRIME | cut -d\# -f1`
|
||||
chroot $COPY_DIR pip install `cat files/pips/*`
|
||||
|
||||
umount $COPY_DIR/dev
|
||||
|
||||
# Clean out code repos if directed to do so
|
||||
if [ "$CLEAN" = "1" ]; then
|
||||
rm -rf $COPY_DIR/$DEST
|
||||
fi
|
||||
|
||||
# Cache openstack code
|
||||
mkdir -p $COPY_DIR/$DEST
|
||||
git_clone $NOVA_REPO $COPY_DIR/$DEST/nova $NOVA_BRANCH
|
||||
git_clone $GLANCE_REPO $COPY_DIR/$DEST/glance $GLANCE_BRANCH
|
||||
git_clone $KEYSTONE_REPO $COPY_DIR/$DESTkeystone $KEYSTONE_BRANCH
|
||||
git_clone $NOVNC_REPO $COPY_DIR/$DEST/noVNC $NOVNC_BRANCH
|
||||
git_clone $HORIZON_REPO $COPY_DIR/$DEST/horizon $HORIZON_BRANCH $HORIZON_TAG
|
||||
git_clone $NOVACLIENT_REPO $COPY_DIR/$DEST/python-novaclient $NOVACLIENT_BRANCH
|
||||
git_clone $OPENSTACKX_REPO $COPY_DIR/$DEST/openstackx $OPENSTACKX_BRANCH
|
||||
git_clone $KEYSTONE_REPO $COPY_DIR/$DEST/keystone $KEYSTONE_BRANCH
|
||||
git_clone $NOVNC_REPO $COPY_DIR/$DEST/noVNC $NOVNC_BRANCH
|
||||
git_clone $CITEST_REPO $COPY_DIR/$DEST/openstack-integration-tests $CITEST_BRANCH
|
||||
|
||||
if [ -z "$UPLOAD_LEGACY_TTY" =; then
|
||||
# Pre-load an image for testing
|
||||
UEC_NAME=$DIST_NAME-server-cloudimg-amd64
|
||||
CIVMDIR=${COPY_DIR}${DEST}/openstack-integration-tests/include/sample_vm
|
||||
if [ ! -e $CIVMDIR/$UEC_NAME.tar.gz ]; then
|
||||
mkdir -p $CIVMDIR
|
||||
(cd $CIVMDIR && wget -N http://uec-images.ubuntu.com/$DIST_NAME/current/$UEC_NAME.tar.gz;
|
||||
tar xzf $UEC_NAME.tar.gz;)
|
||||
fi
|
||||
fi
|
||||
|
||||
# Back to devstack
|
||||
cd $TOP_DIR
|
||||
|
||||
# Unmount the filesystems
|
||||
unmount_images
|
||||
|
||||
# Network configuration variables
|
||||
GUEST_NETWORK=${GUEST_NETWORK:-1}
|
||||
GUEST_RECREATE_NET=${GUEST_RECREATE_NET:-yes}
|
||||
|
||||
GUEST_IP=${GUEST_IP:-192.168.$GUEST_NETWORK.50}
|
||||
GUEST_CIDR=${GUEST_CIDR:-$GUEST_IP/24}
|
||||
GUEST_NETMASK=${GUEST_NETMASK:-255.255.255.0}
|
||||
GUEST_GATEWAY=${GUEST_GATEWAY:-192.168.$GUEST_NETWORK.1}
|
||||
GUEST_MAC=${GUEST_MAC:-"02:16:3e:07:69:`printf '%02X' $GUEST_NETWORK`"}
|
||||
GUEST_RAM=${GUEST_RAM:-1524288}
|
||||
GUEST_CORES=${GUEST_CORES:-1}
|
||||
|
||||
# libvirt.xml configuration
|
||||
NET_XML=$VM_DIR/net.xml
|
||||
cat > $NET_XML <<EOF
|
||||
<network>
|
||||
<name>devstack-$GUEST_NETWORK</name>
|
||||
<bridge name="stackbr%d" />
|
||||
<forward/>
|
||||
<ip address="$GUEST_GATEWAY" netmask="$GUEST_NETMASK" />
|
||||
</network>
|
||||
EOF
|
||||
|
||||
if [[ "$GUEST_RECREATE_NET" == "yes" ]]; then
|
||||
virsh net-destroy devstack-$GUEST_NETWORK || true
|
||||
virsh net-create $VM_DIR/net.xml
|
||||
fi
|
||||
|
||||
# libvirt.xml configuration
|
||||
LIBVIRT_XML=$VM_DIR/libvirt.xml
|
||||
cat > $LIBVIRT_XML <<EOF
|
||||
<domain type='kvm'>
|
||||
<name>$GUEST_NAME</name>
|
||||
<memory>$GUEST_RAM</memory>
|
||||
<os>
|
||||
<type>hvm</type>
|
||||
<bootmenu enable='yes'/>
|
||||
</os>
|
||||
<features>
|
||||
<acpi/>
|
||||
</features>
|
||||
<vcpu>$GUEST_CORES</vcpu>
|
||||
<devices>
|
||||
<disk type='file'>
|
||||
<driver type='qcow2'/>
|
||||
<source file='$VM_DIR/disk'/>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
</disk>
|
||||
|
||||
<interface type='network'>
|
||||
<source network='devstack-$GUEST_NETWORK'/>
|
||||
</interface>
|
||||
|
||||
<!-- The order is significant here. File must be defined first -->
|
||||
<serial type="file">
|
||||
<source path='$VM_DIR/console.log'/>
|
||||
<target port='1'/>
|
||||
</serial>
|
||||
|
||||
<console type='pty' tty='/dev/pts/2'>
|
||||
<source path='/dev/pts/2'/>
|
||||
<target port='0'/>
|
||||
</console>
|
||||
|
||||
<serial type='pty'>
|
||||
<source path='/dev/pts/2'/>
|
||||
<target port='0'/>
|
||||
</serial>
|
||||
|
||||
<graphics type='vnc' port='-1' autoport='yes' keymap='en-us' listen='0.0.0.0'/>
|
||||
</devices>
|
||||
</domain>
|
||||
EOF
|
||||
|
||||
# Mount point for instance fs
|
||||
ROOTFS=$VM_DIR/root
|
||||
mkdir -p $ROOTFS
|
||||
|
||||
# Clean up from previous runs
|
||||
umount $ROOTFS || echo 'ok'
|
||||
|
||||
# Clean up old runs
|
||||
cd $VM_DIR
|
||||
rm -f $VM_DIR/disk
|
||||
|
||||
# Create our instance fs
|
||||
qemu-img create -f qcow2 -b $VM_IMAGE disk
|
||||
|
||||
# Finds the next available NBD device
|
||||
# Exits script if error connecting or none free
|
||||
# map_nbd image
|
||||
# returns full nbd device path
|
||||
function map_nbd {
|
||||
for i in `seq 0 15`; do
|
||||
if [ ! -e /sys/block/nbd$i/pid ]; then
|
||||
NBD=/dev/nbd$i
|
||||
# Connect to nbd and wait till it is ready
|
||||
qemu-nbd -c $NBD $1
|
||||
if ! timeout 60 sh -c "while ! [ -e ${NBD}p1 ]; do sleep 1; done"; then
|
||||
echo "Couldn't connect $NBD"
|
||||
exit 1
|
||||
fi
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$NBD" ]; then
|
||||
echo "No free NBD slots"
|
||||
exit 1
|
||||
fi
|
||||
echo $NBD
|
||||
}
|
||||
|
||||
# Make sure we have nbd-ness
|
||||
modprobe nbd max_part=63
|
||||
|
||||
# Set up nbd
|
||||
NBD=`map_nbd disk`
|
||||
NBD_DEV=`basename $NBD`
|
||||
|
||||
# Mount the instance
|
||||
mount ${NBD}p1 $ROOTFS
|
||||
|
||||
# Configure instance network
|
||||
INTERFACES=$ROOTFS/etc/network/interfaces
|
||||
cat > $INTERFACES <<EOF
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
auto eth0
|
||||
iface eth0 inet static
|
||||
address $GUEST_IP
|
||||
netmask $GUEST_NETMASK
|
||||
gateway $GUEST_GATEWAY
|
||||
EOF
|
||||
|
||||
# User configuration for the instance
|
||||
chroot $ROOTFS groupadd libvirtd || true
|
||||
chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd
|
||||
cp -pr $TOP_DIR $ROOTFS/$DEST/devstack
|
||||
echo "root:$ROOT_PASSWORD" | chroot $ROOTFS chpasswd
|
||||
echo "stack:pass" | chroot $ROOTFS chpasswd
|
||||
echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers
|
||||
|
||||
# Gracefully cp only if source file/dir exists
|
||||
function cp_it {
|
||||
if [ -e $1 ] || [ -d $1 ]; then
|
||||
cp -pRL $1 $2
|
||||
fi
|
||||
}
|
||||
|
||||
# Copy over your ssh keys and env if desired
|
||||
COPYENV=${COPYENV:-1}
|
||||
if [ "$COPYENV" = "1" ]; then
|
||||
cp_it ~/.ssh $ROOTFS/$DEST/.ssh
|
||||
cp_it ~/.ssh/id_rsa.pub $ROOTFS/$DEST/.ssh/authorized_keys
|
||||
cp_it ~/.gitconfig $ROOTFS/$DEST/.gitconfig
|
||||
cp_it ~/.vimrc $ROOTFS/$DEST/.vimrc
|
||||
cp_it ~/.bashrc $ROOTFS/$DEST/.bashrc
|
||||
fi
|
||||
|
||||
# pre-cache uec images
|
||||
for image_url in ${IMAGE_URLS//,/ }; do
|
||||
IMAGE_FNAME=`basename "$image_url"`
|
||||
if [ ! -f $IMAGES_DIR/$IMAGE_FNAME ]; then
|
||||
wget -c $image_url -O $IMAGES_DIR/$IMAGE_FNAME
|
||||
fi
|
||||
cp $IMAGES_DIR/$IMAGE_FNAME $ROOTFS/$DEST/devstack/files
|
||||
done
|
||||
|
||||
# Configure the runner
|
||||
RUN_SH=$ROOTFS/$DEST/run.sh
|
||||
cat > $RUN_SH <<EOF
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Kill any existing screens
|
||||
killall screen
|
||||
|
||||
# Install and run stack.sh
|
||||
sudo apt-get update
|
||||
sudo apt-get -y --force-yes install git-core vim-nox sudo
|
||||
if [ ! -d "$DEST/devstack" ]; then
|
||||
git clone git://github.com/cloudbuilders/devstack.git $DEST/devstack
|
||||
fi
|
||||
cd $DEST/devstack && $STACKSH_PARAMS FORCE=yes ./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
|
||||
cat $DEST/run.sh.log
|
||||
EOF
|
||||
chmod 755 $RUN_SH
|
||||
|
||||
# Make runner launch on boot
|
||||
RC_LOCAL=$ROOTFS/etc/init.d/zlocal
|
||||
cat > $RC_LOCAL <<EOF
|
||||
#!/bin/sh -e
|
||||
# cloud-init overwrites the hostname with ubuntuhost
|
||||
echo $GUEST_NAME > /etc/hostname
|
||||
hostname $GUEST_NAME
|
||||
su -c "$DEST/run.sh" stack
|
||||
EOF
|
||||
chmod +x $RC_LOCAL
|
||||
chroot $ROOTFS sudo update-rc.d zlocal defaults 99
|
||||
|
||||
# Make our ip address hostnames look nice at the command prompt
|
||||
echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/$DEST/.bashrc
|
||||
echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile
|
||||
|
||||
# Give stack ownership over $DEST so it may do the work needed
|
||||
chroot $ROOTFS chown -R stack $DEST
|
||||
|
||||
# Set the hostname
|
||||
echo $GUEST_NAME > $ROOTFS/etc/hostname
|
||||
|
||||
# We need the hostname to resolve for rabbit to launch
|
||||
if ! grep -q $GUEST_NAME $ROOTFS/etc/hosts; then
|
||||
echo "$GUEST_IP $GUEST_NAME" >> $ROOTFS/etc/hosts
|
||||
fi
|
||||
|
||||
# GRUB 2 wants to see /dev
|
||||
mount -o bind /dev $ROOTFS/dev
|
||||
|
||||
# Change boot params so that we get a console log
|
||||
G_DEV_UUID=`blkid -t LABEL=cloudimg-rootfs -s UUID -o value | head -1`
|
||||
sed -e "s/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=3/" -i $ROOTFS/etc/default/grub
|
||||
sed -e "s,GRUB_CMDLINE_LINUX_DEFAULT=.*$,GRUB_CMDLINE_LINUX_DEFAULT=\"console=ttyS0 console=tty0 ds=nocloud ubuntu-pass=pass\",g" -i $ROOTFS/etc/default/grub
|
||||
sed -e 's/[#]*GRUB_TERMINAL=.*$/GRUB_TERMINAL="serial console"/' -i $ROOTFS/etc/default/grub
|
||||
echo 'GRUB_SERIAL_COMMAND="serial --unit=0"' >>$ROOTFS/etc/default/grub
|
||||
echo 'GRUB_DISABLE_OS_PROBER=true' >>$ROOTFS/etc/default/grub
|
||||
echo "GRUB_DEVICE_UUID=$G_DEV_UUID" >>$ROOTFS/etc/default/grub
|
||||
|
||||
chroot $ROOTFS update-grub
|
||||
|
||||
# Pre-generate ssh host keys and allow password login
|
||||
chroot $ROOTFS dpkg-reconfigure openssh-server
|
||||
sed -e 's/^PasswordAuthentication.*$/PasswordAuthentication yes/' -i $ROOTFS/etc/ssh/sshd_config
|
||||
|
||||
# Unmount
|
||||
umount $ROOTFS/dev
|
||||
umount $ROOTFS || echo 'ok'
|
||||
ROOTFS=""
|
||||
qemu-nbd -d $NBD
|
||||
NBD=""
|
||||
|
||||
trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT
|
||||
|
||||
# Create the instance
|
||||
cd $VM_DIR && virsh create libvirt.xml
|
||||
|
||||
# Tail the console log till we are done
|
||||
WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
|
||||
if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
|
||||
# Done creating the container, let's tail the log
|
||||
echo
|
||||
echo "============================================================="
|
||||
echo " -- YAY! --"
|
||||
echo "============================================================="
|
||||
echo
|
||||
echo "We're done launching the vm, about to start tailing the"
|
||||
echo "stack.sh log. It will take a second or two to start."
|
||||
echo
|
||||
echo "Just CTRL-C at any time to stop tailing."
|
||||
|
||||
while [ ! -e "$VM_DIR/console.log" ]; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
tail -F $VM_DIR/console.log &
|
||||
|
||||
TAIL_PID=$!
|
||||
|
||||
function kill_tail() {
|
||||
kill $TAIL_PID
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Let Ctrl-c kill tail and exit
|
||||
trap kill_tail SIGINT
|
||||
|
||||
set +o xtrace
|
||||
|
||||
echo "Waiting stack.sh to finish..."
|
||||
while ! cat $VM_DIR/console.log | grep -q 'All done' ; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
set -o xtrace
|
||||
|
||||
kill $TAIL_PID
|
||||
|
||||
if ! grep -q "^stack.sh completed in" $VM_DIR/console.log; then
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
echo "Finished - Zip-a-dee Doo-dah!"
|
||||
fi
|
@ -1,324 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Debug stuff
|
||||
set -o errexit
|
||||
set -o xtrace
|
||||
|
||||
# Sanity check
|
||||
if [ "$EUID" -ne "0" ]; then
|
||||
echo "This script must be run with root privileges."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Keep track of ubuntu version
|
||||
UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'`
|
||||
|
||||
# Move to top devstack dir
|
||||
cd ..
|
||||
|
||||
# Abort if localrc is not set
|
||||
if [ ! -e ./localrc ]; then
|
||||
echo "You must have a localrc with ALL necessary passwords defined before proceeding."
|
||||
echo "See stack.sh for required passwords."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Source params
|
||||
source ./stackrc
|
||||
|
||||
# Store cwd
|
||||
CWD=`pwd`
|
||||
|
||||
# Configurable params
|
||||
BRIDGE=${BRIDGE:-br0}
|
||||
GUEST_NAME=${GUEST_NAME:-STACK}
|
||||
GUEST_IP=${GUEST_IP:-192.168.1.50}
|
||||
GUEST_CIDR=${GUEST_CIDR:-$GUEST_IP/24}
|
||||
GUEST_NETMASK=${GUEST_NETMASK:-255.255.255.0}
|
||||
GUEST_GATEWAY=${GUEST_GATEWAY:-192.168.1.1}
|
||||
NAMESERVER=${NAMESERVER:-`cat /etc/resolv.conf | grep nameserver | head -1 | cut -d " " -f2`}
|
||||
COPYENV=${COPYENV:-1}
|
||||
DEST=${DEST:-/opt/stack}
|
||||
WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
|
||||
|
||||
# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
|
||||
# By default, n-vol is disabled for lxc, as iscsitarget doesn't work properly in lxc
|
||||
STACKSH_PARAMS=${STACKSH_PARAMS:-"ENABLED_SERVICES=g-api,g-reg,key,n-api,n-cpu,n-net,n-sch,n-vnc,horizon,mysql,rabbit"}
|
||||
|
||||
# Option to use the version of devstack on which we are currently working
|
||||
USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
|
||||
|
||||
|
||||
# Install deps
|
||||
apt-get install -y lxc debootstrap
|
||||
|
||||
# Install cgroup-bin from source, since the packaging is buggy and possibly incompatible with our setup
|
||||
if ! which cgdelete | grep -q cgdelete; then
|
||||
apt-get install -y g++ bison flex libpam0g-dev make
|
||||
wget http://sourceforge.net/projects/libcg/files/libcgroup/v0.37.1/libcgroup-0.37.1.tar.bz2/download -O /tmp/libcgroup-0.37.1.tar.bz2
|
||||
cd /tmp && bunzip2 libcgroup-0.37.1.tar.bz2 && tar xfv libcgroup-0.37.1.tar
|
||||
cd libcgroup-0.37.1
|
||||
./configure
|
||||
make install
|
||||
ldconfig
|
||||
fi
|
||||
|
||||
# Create lxc configuration
|
||||
LXC_CONF=/tmp/$GUEST_NAME.conf
|
||||
cat > $LXC_CONF <<EOF
|
||||
lxc.network.type = veth
|
||||
lxc.network.link = $BRIDGE
|
||||
lxc.network.flags = up
|
||||
lxc.network.ipv4 = $GUEST_CIDR
|
||||
# allow tap/tun devices
|
||||
lxc.cgroup.devices.allow = c 10:200 rwm
|
||||
EOF
|
||||
|
||||
# Shutdown any existing container
|
||||
lxc-stop -n $GUEST_NAME
|
||||
|
||||
# This kills zombie containers
|
||||
if [ -d /cgroup/$GUEST_NAME ]; then
|
||||
cgdelete -r cpu,net_cls:$GUEST_NAME
|
||||
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 {
|
||||
if [ ! -d $2 ]; then
|
||||
sudo mkdir $2
|
||||
sudo chown `whoami` $2
|
||||
git clone $1 $2
|
||||
cd $2
|
||||
# This checkout syntax works for both branches and tags
|
||||
git checkout $3
|
||||
fi
|
||||
}
|
||||
|
||||
# Helper to create the container
|
||||
function create_lxc {
|
||||
if [ "natty" = "$UBUNTU_VERSION" ]; then
|
||||
lxc-create -n $GUEST_NAME -t natty -f $LXC_CONF
|
||||
else
|
||||
lxc-create -n $GUEST_NAME -t ubuntu -f $LXC_CONF
|
||||
fi
|
||||
}
|
||||
|
||||
# Location of the base image directory
|
||||
if [ "natty" = "$UBUNTU_VERSION" ]; then
|
||||
CACHEDIR=/var/cache/lxc/natty/rootfs-amd64
|
||||
else
|
||||
CACHEDIR=/var/cache/lxc/oneiric/rootfs-amd64
|
||||
fi
|
||||
|
||||
# Provide option to do totally clean install
|
||||
if [ "$CLEAR_LXC_CACHE" = "1" ]; then
|
||||
rm -rf $CACHEDIR
|
||||
fi
|
||||
|
||||
# Warm the base image on first install
|
||||
if [ ! -f $CACHEDIR/bootstrapped ]; then
|
||||
# by deleting the container, we force lxc-create to re-bootstrap (lxc is
|
||||
# lazy and doesn't do anything if a container already exists)
|
||||
lxc-destroy -n $GUEST_NAME
|
||||
# trigger the initial debootstrap
|
||||
create_lxc
|
||||
touch $CACHEDIR/bootstrapped
|
||||
fi
|
||||
|
||||
# Make sure that base requirements are installed
|
||||
chroot $CACHEDIR apt-get update
|
||||
chroot $CACHEDIR apt-get install -y --download-only `cat files/apts/* | grep NOPRIME | cut -d\# -f1`
|
||||
chroot $CACHEDIR apt-get install -y --force-yes `cat files/apts/* | grep -v NOPRIME | cut -d\# -f1` || true
|
||||
chroot $CACHEDIR pip install `cat files/pips/*`
|
||||
|
||||
# Clean out code repos if directed to do so
|
||||
if [ "$CLEAN" = "1" ]; then
|
||||
rm -rf $CACHEDIR/$DEST
|
||||
fi
|
||||
|
||||
# Cache openstack code
|
||||
mkdir -p $CACHEDIR/$DEST
|
||||
git_clone $NOVA_REPO $CACHEDIR/$DEST/nova $NOVA_BRANCH
|
||||
git_clone $GLANCE_REPO $CACHEDIR/$DEST/glance $GLANCE_BRANCH
|
||||
git_clone $KEYSTONE_REPO $CACHEDIR/$DESTkeystone $KEYSTONE_BRANCH
|
||||
git_clone $NOVNC_REPO $CACHEDIR/$DEST/noVNC $NOVNC_BRANCH
|
||||
git_clone $HORIZON_REPO $CACHEDIR/$DEST/horizon $HORIZON_BRANCH $HORIZON_TAG
|
||||
git_clone $NOVACLIENT_REPO $CACHEDIR/$DEST/python-novaclient $NOVACLIENT_BRANCH
|
||||
git_clone $OPENSTACKX_REPO $CACHEDIR/$DEST/openstackx $OPENSTACKX_BRANCH
|
||||
git_clone $KEYSTONE_REPO $CACHEDIR/$DEST/keystone $KEYSTONE_BRANCH
|
||||
git_clone $NOVNC_REPO $CACHEDIR/$DEST/novnc $NOVNC_BRANCH
|
||||
|
||||
# Use this version of devstack?
|
||||
if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then
|
||||
rm -rf $CACHEDIR/$DEST/devstack
|
||||
cp -pr $CWD $CACHEDIR/$DEST/devstack
|
||||
fi
|
||||
|
||||
# pre-cache uec images
|
||||
for image_url in ${IMAGE_URLS//,/ }; do
|
||||
IMAGE_FNAME=`basename "$image_url"`
|
||||
if [ ! -f $CACHEDIR/$IMAGE_FNAME ]; then
|
||||
wget -c $image_url -O $CACHEDIR/$IMAGE_FNAME
|
||||
fi
|
||||
cp $CACHEDIR/$IMAGE_FNAME $CACHEDIR/$DEST/devstack/files
|
||||
done
|
||||
|
||||
# Destroy the old container
|
||||
lxc-destroy -n $GUEST_NAME
|
||||
|
||||
# If this call is to TERMINATE the container then exit
|
||||
if [ "$TERMINATE" = "1" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
# Create the container
|
||||
create_lxc
|
||||
|
||||
# Specify where our container rootfs lives
|
||||
ROOTFS=/var/lib/lxc/$GUEST_NAME/rootfs/
|
||||
|
||||
# Create a stack user that is a member of the libvirtd group so that stack
|
||||
# is able to interact with libvirt.
|
||||
chroot $ROOTFS groupadd libvirtd
|
||||
chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd
|
||||
|
||||
# a simple password - pass
|
||||
echo stack:pass | chroot $ROOTFS chpasswd
|
||||
|
||||
# and has sudo ability (in the future this should be limited to only what
|
||||
# stack requires)
|
||||
echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers
|
||||
|
||||
# Copy kernel modules
|
||||
mkdir -p $ROOTFS/lib/modules/`uname -r`/kernel
|
||||
cp -p /lib/modules/`uname -r`/modules.dep $ROOTFS/lib/modules/`uname -r`/
|
||||
cp -pR /lib/modules/`uname -r`/kernel/net $ROOTFS/lib/modules/`uname -r`/kernel/
|
||||
|
||||
# Gracefully cp only if source file/dir exists
|
||||
function cp_it {
|
||||
if [ -e $1 ] || [ -d $1 ]; then
|
||||
cp -pRL $1 $2
|
||||
fi
|
||||
}
|
||||
|
||||
# Copy over your ssh keys and env if desired
|
||||
if [ "$COPYENV" = "1" ]; then
|
||||
cp_it ~/.ssh $ROOTFS/$DEST/.ssh
|
||||
cp_it ~/.ssh/id_rsa.pub $ROOTFS/$DEST/.ssh/authorized_keys
|
||||
cp_it ~/.gitconfig $ROOTFS/$DEST/.gitconfig
|
||||
cp_it ~/.vimrc $ROOTFS/$DEST/.vimrc
|
||||
cp_it ~/.bashrc $ROOTFS/$DEST/.bashrc
|
||||
fi
|
||||
|
||||
# Make our ip address hostnames look nice at the command prompt
|
||||
echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/$DEST/.bashrc
|
||||
echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile
|
||||
|
||||
# Give stack ownership over $DEST so it may do the work needed
|
||||
chroot $ROOTFS chown -R stack $DEST
|
||||
|
||||
# Configure instance network
|
||||
INTERFACES=$ROOTFS/etc/network/interfaces
|
||||
cat > $INTERFACES <<EOF
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
auto eth0
|
||||
iface eth0 inet static
|
||||
address $GUEST_IP
|
||||
netmask $GUEST_NETMASK
|
||||
gateway $GUEST_GATEWAY
|
||||
EOF
|
||||
|
||||
# Configure the runner
|
||||
RUN_SH=$ROOTFS/$DEST/run.sh
|
||||
cat > $RUN_SH <<EOF
|
||||
#!/usr/bin/env bash
|
||||
# Make sure dns is set up
|
||||
echo "nameserver $NAMESERVER" | sudo resolvconf -a eth0
|
||||
# Make there is a default route - needed for natty
|
||||
if ! route | grep -q default; then
|
||||
sudo ip route add default via $GUEST_GATEWAY
|
||||
fi
|
||||
sleep 1
|
||||
|
||||
# Kill any existing screens
|
||||
killall screen
|
||||
|
||||
# Install and run stack.sh
|
||||
sudo apt-get update
|
||||
sudo apt-get -y --force-yes install git-core vim-nox sudo
|
||||
if [ ! -d "$DEST/devstack" ]; then
|
||||
git clone git://github.com/cloudbuilders/devstack.git $DEST/devstack
|
||||
fi
|
||||
cd $DEST/devstack && $STACKSH_PARAMS FORCE=yes ./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
|
||||
|
||||
# Make runner launch on boot
|
||||
RC_LOCAL=$ROOTFS/etc/init.d/local
|
||||
cat > $RC_LOCAL <<EOF
|
||||
#!/bin/sh -e
|
||||
su -c "$DEST/run.sh" stack
|
||||
EOF
|
||||
chmod +x $RC_LOCAL
|
||||
chroot $ROOTFS sudo update-rc.d local defaults 80
|
||||
|
||||
# Configure cgroup directory
|
||||
if ! mount | grep -q cgroup; then
|
||||
mkdir -p /cgroup
|
||||
mount none -t cgroup /cgroup
|
||||
fi
|
||||
|
||||
# Start our container
|
||||
lxc-start -d -n $GUEST_NAME
|
||||
|
||||
if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
|
||||
# Done creating the container, let's tail the log
|
||||
echo
|
||||
echo "============================================================="
|
||||
echo " -- YAY! --"
|
||||
echo "============================================================="
|
||||
echo
|
||||
echo "We're done creating the container, about to start tailing the"
|
||||
echo "stack.sh log. It will take a second or two to start."
|
||||
echo
|
||||
echo "Just CTRL-C at any time to stop tailing."
|
||||
|
||||
while [ ! -e "$ROOTFS/$DEST/run.sh.log" ]; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
tail -F $ROOTFS/$DEST/run.sh.log &
|
||||
|
||||
TAIL_PID=$!
|
||||
|
||||
function kill_tail() {
|
||||
kill $TAIL_PID
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Let Ctrl-c kill tail and exit
|
||||
trap kill_tail SIGINT
|
||||
|
||||
echo "Waiting stack.sh to finish..."
|
||||
while ! cat $ROOTFS/$DEST/run.sh.log | grep -q 'All done' ; do
|
||||
sleep 5
|
||||
done
|
||||
|
||||
kill $TAIL_PID
|
||||
|
||||
if grep -q "stack.sh failed" $ROOTFS/$DEST/run.sh.log; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Finished - Zip-a-dee Doo-dah!"
|
||||
fi
|
@ -1,39 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Head node host, which runs glance, api, keystone
|
||||
HEAD_HOST=${HEAD_HOST:-192.168.1.52}
|
||||
COMPUTE_HOSTS=${COMPUTE_HOSTS:-192.168.1.53,192.168.1.54}
|
||||
|
||||
# Networking params
|
||||
NAMESERVER=${NAMESERVER:-192.168.1.1}
|
||||
GATEWAY=${GATEWAY:-192.168.1.1}
|
||||
NETMASK=${NETMASK:-255.255.255.0}
|
||||
FLOATING_RANGE=${FLOATING_RANGE:-192.168.1.196/30}
|
||||
|
||||
# Setting this to 1 shuts down and destroys our containers without relaunching.
|
||||
TERMINATE=${TERMINATE:-0}
|
||||
|
||||
# Variables common amongst all hosts in the cluster
|
||||
COMMON_VARS="MYSQL_HOST=$HEAD_HOST RABBIT_HOST=$HEAD_HOST GLANCE_HOSTPORT=$HEAD_HOST:9292 NET_MAN=FlatDHCPManager FLAT_INTERFACE=eth0 FLOATING_RANGE=$FLOATING_RANGE MULTI_HOST=1"
|
||||
|
||||
# Helper to launch containers
|
||||
function run_lxc {
|
||||
# For some reason container names with periods can cause issues :/
|
||||
GUEST_NAME=$1 GUEST_IP=$2 GUEST_NETMASK=$NETMASK GUEST_GATEWAY=$GATEWAY NAMESERVER=$NAMESERVER TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $3" ./build_lxc.sh
|
||||
}
|
||||
|
||||
# Launch the head node - headnode uses a non-ip domain name,
|
||||
# because rabbit won't launch with an ip addr hostname :(
|
||||
run_lxc STACKMASTER $HEAD_HOST "ENABLED_SERVICES=g-api,g-reg,key,n-api,n-sch,n-vnc,horizon,mysql,rabbit"
|
||||
|
||||
# Wait till the head node is up
|
||||
if [ ! "$TERMINATE" = "1" ]; then
|
||||
while ! wget -q -O- http://$HEAD_HOST | grep -q username; do
|
||||
echo "Waiting for head node ($HEAD_HOST) to start..."
|
||||
sleep 5
|
||||
done
|
||||
fi
|
||||
|
||||
# Launch the compute hosts
|
||||
for compute_host in ${COMPUTE_HOSTS//,/ }; do
|
||||
run_lxc $compute_host $compute_host "ENABLED_SERVICES=n-cpu,n-net,n-api"
|
||||
done
|
@ -1,118 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
PROGDIR=`dirname $0`
|
||||
CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
|
||||
|
||||
# Source params
|
||||
source ./stackrc
|
||||
|
||||
# Store cwd
|
||||
CWD=`pwd`
|
||||
|
||||
NAME=$1
|
||||
NFSDIR="/nfs/$NAME"
|
||||
DEST=${DEST:-/opt/stack}
|
||||
|
||||
# Option to use the version of devstack on which we are currently working
|
||||
USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
|
||||
|
||||
# remove old nfs filesystem if one exists
|
||||
rm -rf $DEST
|
||||
|
||||
# clean install of natty
|
||||
if [ ! -d $CHROOTCACHE/natty-base ]; then
|
||||
$PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base
|
||||
# copy kernel modules...
|
||||
# NOTE(ja): is there a better way to do this?
|
||||
cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
|
||||
# a simple password - pass
|
||||
echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
|
||||
fi
|
||||
|
||||
# prime natty with as many apt/pips as we can
|
||||
if [ ! -d $CHROOTCACHE/natty-dev ]; then
|
||||
rsync -azH $CHROOTCACHE/natty-base/ $CHROOTCACHE/natty-dev/
|
||||
chroot $CHROOTCACHE apt-get install -y --download-only `cat files/apts/* | grep NOPRIME | cut -d\# -f1`
|
||||
chroot $CHROOTCACHE apt-get install -y --force-yes `cat files/apts/* | grep -v NOPRIME | cut -d\# -f1`
|
||||
chroot $CHROOTCACHE pip install `cat files/pips/*`
|
||||
|
||||
# Create a stack user that is a member of the libvirtd group so that stack
|
||||
# is able to interact with libvirt.
|
||||
chroot $CHROOTCACHE/natty-dev groupadd libvirtd
|
||||
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
|
||||
|
||||
# a simple password - pass
|
||||
echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd
|
||||
|
||||
# and has sudo ability (in the future this should be limited to only what
|
||||
# stack requires)
|
||||
echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers
|
||||
fi
|
||||
|
||||
# clone git repositories onto the system
|
||||
# ======================================
|
||||
|
||||
if [ ! -d $CHROOTCACHE/natty-stack ]; then
|
||||
rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/
|
||||
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
|
||||
CHECKOUT=$CHROOTCACHE/natty-stack$2
|
||||
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
|
||||
chroot $CHROOTCACHE/natty-stack/ chown -R stack $2
|
||||
}
|
||||
|
||||
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 $HORIZON_REPO $DEST/horizon $HORIZON_BRANCH $HORIZON_TAG
|
||||
git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
|
||||
git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
|
||||
|
||||
chroot $CHROOTCACHE/natty-stack mkdir -p $DEST/files
|
||||
wget -c http://images.ansolabs.com/tty.tgz -O $CHROOTCACHE/natty-stack$DEST/files/tty.tgz
|
||||
|
||||
# Use this version of devstack?
|
||||
if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then
|
||||
rm -rf $CHROOTCACHE/natty-stack/$DEST/devstack
|
||||
cp -pr $CWD $CHROOTCACHE/natty-stack/$DEST/devstack
|
||||
fi
|
||||
|
||||
cp -pr $CHROOTCACHE/natty-stack $NFSDIR
|
||||
|
||||
# set hostname
|
||||
echo $NAME > $NFSDIR/etc/hostname
|
||||
echo "127.0.0.1 localhost $NAME" > $NFSDIR/etc/hosts
|
||||
|
||||
# injecting root's public ssh key if it exists
|
||||
if [ -f /root/.ssh/id_rsa.pub ]; then
|
||||
mkdir $NFSDIR/root/.ssh
|
||||
chmod 700 $NFSDIR/root/.ssh
|
||||
cp /root/.ssh/id_rsa.pub $NFSDIR/root/.ssh/authorized_keys
|
||||
fi
|
@ -0,0 +1,203 @@
|
||||
#!/usr/bin/env bash
|
||||
# build_uec_ramdisk.sh - Build RAM disk images based on UEC image
|
||||
|
||||
# exit on error to stop unexpected errors
|
||||
set -o errexit
|
||||
|
||||
if [ ! "$#" -eq "1" ]; then
|
||||
echo "$0 builds a gziped Ubuntu OpenStack install"
|
||||
echo "usage: $0 dest"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make sure that we have the proper version of ubuntu (only works on oneiric)
|
||||
if ! egrep -q "oneiric" /etc/lsb-release; then
|
||||
echo "This script only works with ubuntu oneiric."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clean up resources that may be in use
|
||||
cleanup() {
|
||||
set +o errexit
|
||||
|
||||
if [ -n "$MNT_DIR" ]; then
|
||||
umount $MNT_DIR/dev
|
||||
umount $MNT_DIR
|
||||
fi
|
||||
|
||||
if [ -n "$DEST_FILE_TMP" ]; then
|
||||
rm $DEST_FILE_TMP
|
||||
fi
|
||||
|
||||
# Kill ourselves to signal parents
|
||||
trap 2; kill -2 $$
|
||||
}
|
||||
|
||||
trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT
|
||||
|
||||
# Output dest image
|
||||
DEST_FILE=$1
|
||||
|
||||
# Keep track of the current directory
|
||||
TOOLS_DIR=$(cd $(dirname "$0") && pwd)
|
||||
TOP_DIR=`cd $TOOLS_DIR/..; pwd`
|
||||
|
||||
cd $TOP_DIR
|
||||
|
||||
# Source params
|
||||
source ./stackrc
|
||||
|
||||
DEST=${DEST:-/opt/stack}
|
||||
|
||||
# Ubuntu distro to install
|
||||
DIST_NAME=${DIST_NAME:-oneiric}
|
||||
|
||||
# Configure how large the VM should be
|
||||
GUEST_SIZE=${GUEST_SIZE:-2G}
|
||||
|
||||
# exit on error to stop unexpected errors
|
||||
set -o errexit
|
||||
set -o xtrace
|
||||
|
||||
# Abort if localrc is not set
|
||||
if [ ! -e $TOP_DIR/localrc ]; then
|
||||
echo "You must have a localrc with ALL necessary passwords defined before proceeding."
|
||||
echo "See stack.sh for required passwords."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install deps if needed
|
||||
DEPS="kvm libvirt-bin kpartx cloud-utils curl"
|
||||
apt-get install -y --force-yes $DEPS
|
||||
|
||||
# Where to store files and instances
|
||||
CACHEDIR=${CACHEDIR:-/opt/stack/cache}
|
||||
WORK_DIR=${WORK_DIR:-/opt/ramstack}
|
||||
|
||||
# Where to store images
|
||||
image_dir=$WORK_DIR/images/$DIST_NAME
|
||||
mkdir -p $image_dir
|
||||
|
||||
# Get the base image if it does not yet exist
|
||||
if [ ! -e $image_dir/disk ]; then
|
||||
$TOOLS_DIR/get_uec_image.sh -r 2000M $DIST_NAME $image_dir/disk
|
||||
fi
|
||||
|
||||
# Configure the root password of the vm to be the same as ``ADMIN_PASSWORD``
|
||||
ROOT_PASSWORD=${ADMIN_PASSWORD:-password}
|
||||
|
||||
# Name of our instance, used by libvirt
|
||||
GUEST_NAME=${GUEST_NAME:-devstack}
|
||||
|
||||
# Pre-load the image with basic environment
|
||||
if [ ! -e $image_dir/disk-primed ]; then
|
||||
cp $image_dir/disk $image_dir/disk-primed
|
||||
$TOOLS_DIR/warm_apts_and_pips_for_uec.sh $image_dir/disk-primed
|
||||
$TOOLS_DIR/copy_dev_environment_to_uec.sh $image_dir/disk-primed
|
||||
fi
|
||||
|
||||
# Back to devstack
|
||||
cd $TOP_DIR
|
||||
|
||||
DEST_FILE_TMP=`mktemp $DEST_FILE.XXXXXX`
|
||||
MNT_DIR=`mktemp -d --tmpdir mntXXXXXXXX`
|
||||
cp $image_dir/disk-primed $DEST_FILE_TMP
|
||||
mount -t ext4 -o loop $DEST_FILE_TMP $MNT_DIR
|
||||
mount -o bind /dev /$MNT_DIR/dev
|
||||
cp -p /etc/resolv.conf $MNT_DIR/etc/resolv.conf
|
||||
echo root:$ROOT_PASSWORD | chroot $MNT_DIR chpasswd
|
||||
touch $MNT_DIR/$DEST/.ramdisk
|
||||
|
||||
# We need to install a non-virtual kernel and modules to boot from
|
||||
if [ ! -r "`ls $MNT_DIR/boot/vmlinuz-*-generic | head -1`" ]; then
|
||||
chroot $MNT_DIR apt-get install -y linux-generic
|
||||
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
|
||||
CHECKOUT=${MNT_DIR}$2
|
||||
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
|
||||
chroot $MNT_DIR chown -R stack $2
|
||||
}
|
||||
|
||||
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 $HORIZON_REPO $DEST/horizon $HORIZON_BRANCH
|
||||
git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
|
||||
git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
|
||||
git_clone $CITEST_REPO $DEST/openstack-integration-tests $CITEST_BRANCH
|
||||
|
||||
# Use this version of devstack
|
||||
rm -rf $MNT_DIR/$DEST/devstack
|
||||
cp -pr $TOP_DIR $MNT_DIR/$DEST/devstack
|
||||
chroot $MNT_DIR chown -R stack $DEST/devstack
|
||||
|
||||
# Configure host network for DHCP
|
||||
mkdir -p $MNT_DIR/etc/network
|
||||
cat > $MNT_DIR/etc/network/interfaces <<EOF
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
|
||||
auto eth0
|
||||
iface eth0 inet dhcp
|
||||
EOF
|
||||
|
||||
# Set hostname
|
||||
echo "ramstack" >$MNT_DIR/etc/hostname
|
||||
echo "127.0.0.1 localhost ramstack" >$MNT_DIR/etc/hosts
|
||||
|
||||
# Configure the runner
|
||||
RUN_SH=$MNT_DIR/$DEST/run.sh
|
||||
cat > $RUN_SH <<EOF
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# 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"
|
||||
|
||||
# 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
|
||||
chroot $MNT_DIR chown stack $DEST/run.sh
|
||||
|
||||
umount $MNT_DIR/dev
|
||||
umount $MNT_DIR
|
||||
rmdir $MNT_DIR
|
||||
mv $DEST_FILE_TMP $DEST_FILE
|
||||
rm -f $DEST_FILE_TMP
|
||||
|
||||
trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT
|
@ -1,93 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Print some usage info
|
||||
function usage {
|
||||
echo "Usage: $0 [OPTION] [host_ip]"
|
||||
echo "Set up temporary networking for LXC"
|
||||
echo ""
|
||||
echo " -n, --dry-run Just print the commands that would execute."
|
||||
echo " -h, --help Print this usage message."
|
||||
echo ""
|
||||
exit
|
||||
}
|
||||
|
||||
# Allow passing the ip address on the command line.
|
||||
function process_option {
|
||||
case "$1" in
|
||||
-h|--help) usage;;
|
||||
-n|--dry-run) dry_run=1;;
|
||||
*) host_ip="$1"
|
||||
esac
|
||||
}
|
||||
|
||||
# Set up some defaults
|
||||
host_ip=
|
||||
dry_run=0
|
||||
bridge=br0
|
||||
DRIER=
|
||||
|
||||
# Process the args
|
||||
for arg in "$@"; do
|
||||
process_option $arg
|
||||
done
|
||||
|
||||
if [ $dry_run ]; then
|
||||
DRIER=echo
|
||||
fi
|
||||
|
||||
if [ "$UID" -ne "0" ]; then
|
||||
echo "This script must be run with root privileges."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for bridge-utils.
|
||||
BRCTL=`which brctl`
|
||||
if [ ! -x "$BRCTL" ]; then
|
||||
echo "This script requires you to install bridge-utils."
|
||||
echo "Try: sudo apt-get install bridge-utils."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Scare off the nubs.
|
||||
echo "====================================================="
|
||||
echo
|
||||
echo "WARNING"
|
||||
echo
|
||||
echo "This script will modify your current network setup,"
|
||||
echo "this can be a scary thing and it is recommended that"
|
||||
echo "you have something equivalent to physical access to"
|
||||
echo "this machine before continuing in case your network"
|
||||
echo "gets all funky."
|
||||
echo
|
||||
echo "If you don't want to continue, hit CTRL-C now."
|
||||
|
||||
if [ -z "$host_ip" ];
|
||||
then
|
||||
echo "Otherwise, please type in your host's ip address and"
|
||||
echo "hit enter."
|
||||
echo
|
||||
echo "====================================================="
|
||||
read host_ip
|
||||
else
|
||||
echo "Otherwise hit enter."
|
||||
echo
|
||||
echo "====================================================="
|
||||
read accept
|
||||
fi
|
||||
|
||||
|
||||
# Add a bridge interface, this will choke if there is already
|
||||
# a bridge named $bridge
|
||||
$DRIER $BRCTL addbr $bridge
|
||||
$DRIER ip addr add 192.168.1.1/24 dev $bridge
|
||||
if [ $dry_run ]; then
|
||||
echo "echo 1 > /proc/sys/net/ipv4/ip_forward"
|
||||
else
|
||||
echo 1 > /proc/sys/net/ipv4/ip_forward
|
||||
fi
|
||||
$DRIER ifconfig $bridge up
|
||||
|
||||
# Set up the NAT for the instances
|
||||
$DRIER iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source $host_ip
|
||||
$DRIER iptables -I FORWARD -s 192.168.1.0/24 -j ACCEPT
|
||||
|
@ -1,187 +0,0 @@
|
||||
#!/bin/bash
|
||||
# make_image.sh - Create Ubuntu images in various formats
|
||||
#
|
||||
# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc), raw
|
||||
#
|
||||
# Requires sudo to root
|
||||
|
||||
ROOTSIZE=${ROOTSIZE:-8192}
|
||||
SWAPSIZE=${SWAPSIZE:-1024}
|
||||
MIN_PKGS=${MIN_PKGS:-"apt-utils gpgv openssh-server"}
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 - Create Ubuntu images"
|
||||
echo ""
|
||||
echo "$0 [-m] [-r rootsize] [-s swapsize] release format"
|
||||
echo "$0 -C [-m] release chrootdir"
|
||||
echo "$0 -I [-r rootsize] [-s swapsize] chrootdir format"
|
||||
echo ""
|
||||
echo "-C - Create the initial chroot dir"
|
||||
echo "-I - Create the final image from a chroot"
|
||||
echo "-m - minimal installation"
|
||||
echo "-r size - root fs size in MB"
|
||||
echo "-s size - swap fs size in MB"
|
||||
echo "release - Ubuntu release: jaunty - oneric"
|
||||
echo "format - image format: qcow2, vmdk, vdi, vhd, xen, raw, fs"
|
||||
exit 1
|
||||
}
|
||||
|
||||
while getopts CIhmr:s: c; do
|
||||
case $c in
|
||||
C) CHROOTONLY=1
|
||||
;;
|
||||
I) IMAGEONLY=1
|
||||
;;
|
||||
h) usage
|
||||
;;
|
||||
m) MINIMAL=1
|
||||
;;
|
||||
r) ROOTSIZE=$OPTARG
|
||||
;;
|
||||
s) SWAPSIZE=$OPTARG
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift `expr $OPTIND - 1`
|
||||
|
||||
if [ ! "$#" -eq "2" -o -n "$CHROOTONLY" -a -n "$IMAGEONLY" ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
# Default args
|
||||
RELEASE=$1
|
||||
FORMAT=$2
|
||||
CHROOTDIR=""
|
||||
|
||||
if [ -n "$CHROOTONLY" ]; then
|
||||
RELEASE=$1
|
||||
CHROOTDIR=$2
|
||||
FORMAT="pass"
|
||||
fi
|
||||
|
||||
if [ -n "$IMAGEONLY" ]; then
|
||||
CHROOTDIR=$1
|
||||
FORMAT=$2
|
||||
RELEASE="pass"
|
||||
fi
|
||||
|
||||
# Make sure that we have the proper version of ubuntu
|
||||
UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'`
|
||||
if [ "$UBUNTU_VERSION" = "natty" -a "$RELEASE" = "oneiric" ]; then
|
||||
echo "natty installs can't build oneiric images"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case $FORMAT in
|
||||
kvm|qcow2) FORMAT=qcow2
|
||||
QFORMAT=qcow2
|
||||
HYPER=kvm
|
||||
;;
|
||||
vmserver|vmdk)
|
||||
FORMAT=vmdk
|
||||
QFORMAT=vmdk
|
||||
HYPER=vmserver
|
||||
;;
|
||||
vbox|vdi) FORMAT=vdi
|
||||
QFORMAT=vdi
|
||||
HYPER=kvm
|
||||
;;
|
||||
vhd|vpc) FORMAT=vhd
|
||||
QFORMAT=vpc
|
||||
HYPER=kvm
|
||||
;;
|
||||
xen) FORMAT=raw
|
||||
QFORMAT=raw
|
||||
HYPER=xen
|
||||
;;
|
||||
raw) FORMAT=raw
|
||||
QFORMAT=raw
|
||||
HYPER=kvm
|
||||
;;
|
||||
pass) ;;
|
||||
*) echo "Unknown format: $FORMAT"
|
||||
usage
|
||||
esac
|
||||
|
||||
case $RELEASE in
|
||||
oneiric) ;;
|
||||
natty) ;;
|
||||
maverick) ;;
|
||||
lucid) ;;
|
||||
karmic) ;;
|
||||
jaunty) ;;
|
||||
pass) ;;
|
||||
*) echo "Unknown release: $RELEASE"
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
|
||||
# Install stuff if necessary
|
||||
if [ -z `which vmbuilder` ]; then
|
||||
sudo apt-get install -y ubuntu-vm-builder
|
||||
fi
|
||||
|
||||
if [ -n "$CHROOTONLY" ]; then
|
||||
# Build a chroot directory
|
||||
HYPER=kvm
|
||||
if [ "$MINIMAL" = 1 ]; then
|
||||
ARGS="--variant=minbase"
|
||||
for i in $MIN_PKGS; do
|
||||
ARGS="$ARGS --addpkg=$i"
|
||||
done
|
||||
fi
|
||||
sudo vmbuilder $HYPER ubuntu $ARGS \
|
||||
--suite $RELEASE \
|
||||
--only-chroot \
|
||||
--chroot-dir=$CHROOTDIR \
|
||||
--overwrite \
|
||||
--addpkg=$MIN_PKGS \
|
||||
|
||||
sudo cp -p files/sources.list $CHROOTDIR/etc/apt/sources.list
|
||||
sed -e "s,%DIST%,$RELEASE,g" -i $CHROOTDIR/etc/apt/sources.list
|
||||
sudo chroot $CHROOTDIR apt-get update
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Build the image
|
||||
TMPDIR=tmp
|
||||
TMPDISK=`mktemp imgXXXXXXXX`
|
||||
SIZE=$[$ROOTSIZE+$SWAPSIZE+1]
|
||||
dd if=/dev/null of=$TMPDISK bs=1M seek=$SIZE count=1
|
||||
|
||||
if [ -n "$IMAGEONLY" ]; then
|
||||
# Build image from chroot
|
||||
sudo vmbuilder $HYPER ubuntu $ARGS \
|
||||
--existing-chroot=$CHROOTDIR \
|
||||
--overwrite \
|
||||
--rootsize=$ROOTSIZE \
|
||||
--swapsize=$SWAPSIZE \
|
||||
--tmpfs - \
|
||||
--raw=$TMPDISK \
|
||||
|
||||
else
|
||||
# Do the whole shebang in one pass
|
||||
ARGS="--variant=minbase"
|
||||
for i in $MIN_PKGS; do
|
||||
ARGS="$ARGS --addpkg=$i"
|
||||
done
|
||||
sudo vmbuilder $HYPER ubuntu $ARGS \
|
||||
--suite $RELEASE \
|
||||
--overwrite \
|
||||
--rootsize=$ROOTSIZE \
|
||||
--swapsize=$SWAPSIZE \
|
||||
--tmpfs - \
|
||||
--raw=$TMPDISK \
|
||||
|
||||
fi
|
||||
|
||||
if [ "$FORMAT" = "raw" ]; then
|
||||
# Get image
|
||||
mv $TMPDISK $RELEASE.$FORMAT
|
||||
else
|
||||
# Convert image
|
||||
qemu-img convert -O $QFORMAT $TMPDISK $RELEASE.$FORMAT
|
||||
rm $TMPDISK
|
||||
fi
|
||||
rm -rf ubuntu-$HYPER
|
@ -1,90 +0,0 @@
|
||||
#!/bin/bash
|
||||
# upload_image.sh - Upload Ubuntu images (create if necessary) in various formats
|
||||
# Supported formats: qcow (kvm), vmdk (vmserver), vdi (vbox), vhd (vpc)
|
||||
# Requires sudo to root
|
||||
|
||||
usage() {
|
||||
echo "$0 - Upload images to OpenStack"
|
||||
echo ""
|
||||
echo "$0 [-h host] [-p port] release format"
|
||||
exit 1
|
||||
}
|
||||
|
||||
HOST=${HOST:-localhost}
|
||||
PORT=${PORT:-9292}
|
||||
DEST=${DEST:-/opt/stack}
|
||||
|
||||
while getopts h:p: c; do
|
||||
case $c in
|
||||
h) HOST=$OPTARG
|
||||
;;
|
||||
p) PORT=$OPTARG
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift `expr $OPTIND - 1`
|
||||
|
||||
RELEASE=$1
|
||||
FORMAT=$2
|
||||
|
||||
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 $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
|
||||
if [ -x "$DEST/glance/bin/glance" ]; then
|
||||
# Look for stack.sh's install
|
||||
GLANCE="$DEST/glance/bin/glance"
|
||||
else
|
||||
# Install Glance client in $DEST
|
||||
echo "Glance not found, must install client"
|
||||
OWD=`pwd`
|
||||
cd $DEST
|
||||
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..."
|
||||
$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
|
Loading…
Reference in New Issue