Merge pull request #47 from dtroyer/master
Updates to build_nfs.sh and build_pxe_ramdisk.sh for common functions
This commit is contained in:
commit
647de9d3e3
4 changed files with 162 additions and 87 deletions
149
build_nfs.sh
149
build_nfs.sh
|
@ -1,70 +1,117 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
PROGDIR=`dirname $0`
|
||||||
|
CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
|
||||||
|
|
||||||
# Source params
|
# Source params
|
||||||
source ./stackrc
|
source ./stackrc
|
||||||
|
|
||||||
# TODO: make dest not hardcoded
|
# Store cwd
|
||||||
|
CWD=`pwd`
|
||||||
|
|
||||||
NAME=$1
|
NAME=$1
|
||||||
DEST="/nfs/$NAME"
|
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
|
# remove old nfs filesystem if one exists
|
||||||
rm -rf $DEST
|
rm -rf $DEST
|
||||||
|
|
||||||
# build a proto image - natty + packages that will install (optimization)
|
# clean install of natty
|
||||||
if [ ! -d proto ]; then
|
if [ ! -d $CHROOTCACHE/natty-base ]; then
|
||||||
debootstrap natty proto
|
$PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base
|
||||||
cp files/sources.list proto/etc/apt/sources.list
|
# copy kernel modules...
|
||||||
chroot proto apt-get update
|
# NOTE(ja): is there a better way to do this?
|
||||||
chroot proto apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
|
cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
|
||||||
chroot proto pip install `cat files/pips/*`
|
# a simple password - pass
|
||||||
git_clone $NOVA_REPO proto/opt/nova $NOVA_BRANCH
|
echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
|
||||||
git_clone $GLANCE_REPO proto/opt/glance $GLANCE_BRANCH
|
|
||||||
git_clone $KEYSTONE_REPO proto/opt/keystone $KEYSTONE_BRANCH
|
|
||||||
git_clone $NOVNC_REPO proto/opt/novnc $NOVNC_BRANCH
|
|
||||||
git_clone $DASH_REPO proto/opt/dash $DASH_BRANCH $DASH_TAG
|
|
||||||
git_clone $NOVACLIENT_REPO proto/opt/python-novaclient $NOVACLIENT_BRANCH
|
|
||||||
git_clone $OPENSTACKX_REPO proto/opt/openstackx $OPENSTACKX_BRANCH
|
|
||||||
chroot proto mkdir -p /opt/files
|
|
||||||
wget -c http://images.ansolabs.com/tty.tgz -O proto/opt/files/tty.tgz
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cp -pr proto $DEST
|
# 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/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/*`
|
||||||
|
|
||||||
|
# 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 $DASH_REPO $DEST/dash $DASH_BRANCH $DASH_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
|
# set hostname
|
||||||
echo $NAME > $DEST/etc/hostname
|
echo $NAME > $NFSDIR/etc/hostname
|
||||||
echo "127.0.0.1 localhost $NAME" > $DEST/etc/hosts
|
echo "127.0.0.1 localhost $NAME" > $NFSDIR/etc/hosts
|
||||||
|
|
||||||
# copy kernel modules
|
|
||||||
cp -pr /lib/modules/`uname -r` $DEST/lib/modules
|
|
||||||
|
|
||||||
|
|
||||||
# copy openstack installer and requirement lists to a new directory.
|
|
||||||
mkdir -p $DEST/opt
|
|
||||||
|
|
||||||
# inject stack.sh and dependant files
|
|
||||||
cp -r files $DEST/opt/files
|
|
||||||
cp stack.sh $DEST/opt/stack.sh
|
|
||||||
|
|
||||||
# injecting root's public ssh key if it exists
|
# injecting root's public ssh key if it exists
|
||||||
if [ -f /root/.ssh/id_rsa.pub ]; then
|
if [ -f /root/.ssh/id_rsa.pub ]; then
|
||||||
mkdir $DEST/root/.ssh
|
mkdir $NFSDIR/root/.ssh
|
||||||
chmod 700 $DEST/root/.ssh
|
chmod 700 $NFSDIR/root/.ssh
|
||||||
cp /root/.ssh/id_rsa.pub $DEST/root/.ssh/authorized_keys
|
cp /root/.ssh/id_rsa.pub $NFSDIR/root/.ssh/authorized_keys
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set root password to password
|
|
||||||
echo root:pass | chroot $DEST chpasswd
|
|
||||||
|
|
||||||
# Create a stack user that is a member of the libvirtd group so that stack
|
|
||||||
# is able to interact with libvirt.
|
|
||||||
chroot $DEST groupadd libvirtd
|
|
||||||
chroot $DEST useradd stack -s /bin/bash -d /opt -G libvirtd
|
|
||||||
# a simple password - pass
|
|
||||||
echo stack:pass | chroot $DEST chpasswd
|
|
||||||
# give stack ownership over /opt so it may do the work needed
|
|
||||||
chroot $DEST chown -R stack /opt
|
|
||||||
|
|
||||||
# and has sudo ability (in the future this should be limited to only what
|
|
||||||
# stack requires)
|
|
||||||
echo "stack ALL=(ALL) NOPASSWD: ALL" >> $DEST/etc/sudoers
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ if [ "$1" = "-k" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DEST_DIR=${1:-/tmp}/tftpboot
|
DEST_DIR=${1:-/tmp}/tftpboot
|
||||||
|
PXEDIR=${PXEDIR:-/var/cache/devstack/pxe}
|
||||||
OPWD=`pwd`
|
OPWD=`pwd`
|
||||||
PROGDIR=`dirname $0`
|
PROGDIR=`dirname $0`
|
||||||
|
|
||||||
|
@ -41,23 +42,23 @@ EOF
|
||||||
|
|
||||||
# Setup devstack boot
|
# Setup devstack boot
|
||||||
mkdir -p $DEST_DIR/ubuntu
|
mkdir -p $DEST_DIR/ubuntu
|
||||||
if [ ! -d $OPWD/pxe ]; then
|
if [ ! -d $PXEDIR ]; then
|
||||||
mkdir -p $OPWD/pxe
|
mkdir -p $PXEDIR
|
||||||
fi
|
fi
|
||||||
if [ ! -r $OPWD/pxe/vmlinuz-${KVER} ]; then
|
if [ ! -r $PXEDIR/vmlinuz-${KVER} ]; then
|
||||||
sudo chmod 644 /boot/vmlinuz-${KVER}
|
sudo chmod 644 /boot/vmlinuz-${KVER}
|
||||||
if [ ! -r /boot/vmlinuz-${KVER} ]; then
|
if [ ! -r /boot/vmlinuz-${KVER} ]; then
|
||||||
echo "No kernel found"
|
echo "No kernel found"
|
||||||
else
|
else
|
||||||
cp -p /boot/vmlinuz-${KVER} $OPWD/pxe
|
cp -p /boot/vmlinuz-${KVER} $PXEDIR
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
cp -p $OPWD/pxe/vmlinuz-${KVER} $DEST_DIR/ubuntu
|
cp -p $PXEDIR/vmlinuz-${KVER} $DEST_DIR/ubuntu
|
||||||
if [ ! -r $OPWD/pxe/stack-initrd.gz ]; then
|
if [ ! -r $PXEDIR/stack-initrd.gz ]; then
|
||||||
cd $OPWD
|
cd $OPWD
|
||||||
sudo $PROGDIR/build_pxe_ramdisk.sh $OPWD/pxe/stack-initrd.gz
|
sudo $PROGDIR/build_pxe_ramdisk.sh $PXEDIR/stack-initrd.gz
|
||||||
fi
|
fi
|
||||||
cp -p $OPWD/pxe/stack-initrd.gz $DEST_DIR/ubuntu
|
cp -p $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
|
||||||
cat >>$DEFAULT <<EOF
|
cat >>$DEFAULT <<EOF
|
||||||
|
|
||||||
LABEL devstack
|
LABEL devstack
|
||||||
|
@ -68,8 +69,8 @@ LABEL devstack
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Get Ubuntu
|
# Get Ubuntu
|
||||||
if [ -d $OPWD/pxe ]; then
|
if [ -d $PXEDIR ]; then
|
||||||
cp -p $OPWD/pxe/natty-base-initrd.gz $DEST_DIR/ubuntu
|
cp -p $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
|
||||||
fi
|
fi
|
||||||
cat >>$DEFAULT <<EOF
|
cat >>$DEFAULT <<EOF
|
||||||
|
|
||||||
|
|
|
@ -7,44 +7,55 @@ if [ ! "$#" -eq "1" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PROGDIR=`dirname $0`
|
PROGDIR=`dirname $0`
|
||||||
|
CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
|
||||||
|
|
||||||
# Source params
|
# Source params
|
||||||
source ./stackrc
|
source ./stackrc
|
||||||
|
|
||||||
|
# Store cwd
|
||||||
|
CWD=`pwd`
|
||||||
|
|
||||||
|
DEST=${DEST:-/opt/stack}
|
||||||
|
|
||||||
|
# Option to use the version of devstack on which we are currently working
|
||||||
|
USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
|
||||||
|
|
||||||
# clean install of natty
|
# clean install of natty
|
||||||
if [ ! -d natty-base ]; then
|
if [ ! -d $CHROOTCACHE/natty-base ]; then
|
||||||
$PROGDIR/make_image.sh -C natty natty-base
|
$PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base
|
||||||
# copy kernel modules...
|
# copy kernel modules...
|
||||||
# NOTE(ja): is there a better way to do this?
|
# NOTE(ja): is there a better way to do this?
|
||||||
cp -pr /lib/modules/`uname -r` natty-base/lib/modules
|
cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
|
||||||
# a simple password - pass
|
# a simple password - pass
|
||||||
echo root:pass | chroot natty-base chpasswd
|
echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# prime natty with as many apt/pips as we can
|
# prime natty with as many apt/pips as we can
|
||||||
if [ ! -d primed ]; then
|
if [ ! -d $CHROOTCACHE/natty-dev ]; then
|
||||||
rsync -azH natty-base/ primed/
|
rsync -azH $CHROOTCACHE/natty-base/ $CHROOTCACHE/natty-dev/
|
||||||
chroot primed apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
|
chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
|
||||||
chroot primed pip install `cat files/pips/*`
|
chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*`
|
||||||
|
|
||||||
# Create a stack user that is a member of the libvirtd group so that stack
|
# Create a stack user that is a member of the libvirtd group so that stack
|
||||||
# is able to interact with libvirt.
|
# is able to interact with libvirt.
|
||||||
chroot primed groupadd libvirtd
|
chroot $CHROOTCACHE/natty-dev groupadd libvirtd
|
||||||
chroot primed useradd stack -s /bin/bash -d /opt -G 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
|
# a simple password - pass
|
||||||
echo stack:pass | chroot primed chpasswd
|
echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd
|
||||||
|
|
||||||
# and has sudo ability (in the future this should be limited to only what
|
# and has sudo ability (in the future this should be limited to only what
|
||||||
# stack requires)
|
# stack requires)
|
||||||
echo "stack ALL=(ALL) NOPASSWD: ALL" >> primed/etc/sudoers
|
echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# clone git repositories onto the system
|
# clone git repositories onto the system
|
||||||
# ======================================
|
# ======================================
|
||||||
|
|
||||||
if [ ! -d cloned ]; then
|
if [ ! -d $CHROOTCACHE/natty-stack ]; then
|
||||||
rsync -azH primed/ cloned/
|
rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# git clone only if directory doesn't exist already. Since ``DEST`` might not
|
# git clone only if directory doesn't exist already. Since ``DEST`` might not
|
||||||
|
@ -53,7 +64,7 @@ fi
|
||||||
function git_clone {
|
function git_clone {
|
||||||
|
|
||||||
# clone new copy or fetch latest changes
|
# clone new copy or fetch latest changes
|
||||||
CHECKOUT=cloned$2
|
CHECKOUT=$CHROOTCACHE/natty-stack$2
|
||||||
if [ ! -d $CHECKOUT ]; then
|
if [ ! -d $CHECKOUT ]; then
|
||||||
mkdir -p $CHECKOUT
|
mkdir -p $CHECKOUT
|
||||||
git clone $1 $CHECKOUT
|
git clone $1 $CHECKOUT
|
||||||
|
@ -73,19 +84,35 @@ function git_clone {
|
||||||
popd
|
popd
|
||||||
|
|
||||||
# give ownership to the stack user
|
# give ownership to the stack user
|
||||||
chroot cloned/ chown -R stack $2
|
chroot $CHROOTCACHE/natty-stack/ chown -R stack $2
|
||||||
}
|
}
|
||||||
|
|
||||||
git_clone $NOVA_REPO /opt/stack/nova $NOVA_BRANCH
|
git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
|
||||||
git_clone $GLANCE_REPO /opt/stack/glance $GLANCE_BRANCH
|
git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
|
||||||
git_clone $KEYSTONE_REPO /opt/stack/keystone $KEYSTONE_BRANCH
|
git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
|
||||||
git_clone $NOVNC_REPO /opt/stack/novnc $NOVNC_BRANCH
|
git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
|
||||||
git_clone $DASH_REPO /opt/stack/dash $DASH_BRANCH
|
git_clone $DASH_REPO $DEST/dash $DASH_BRANCH
|
||||||
git_clone $NOVACLIENT_REPO /opt/stack/python-novaclient $NOVACLIENT_BRANCH
|
git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
|
||||||
git_clone $OPENSTACKX_REPO /opt/stack/openstackx $OPENSTACKX_BRANCH
|
git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Configure host network for DHCP
|
||||||
|
mkdir -p $CHROOTCACHE/natty-stack/etc/network
|
||||||
|
cat > $CHROOTCACHE/natty-stack/etc/network/interfaces <<EOF
|
||||||
|
auto lo
|
||||||
|
iface lo inet loopback
|
||||||
|
|
||||||
|
auto eth0
|
||||||
|
iface eth0 inet dhcp
|
||||||
|
EOF
|
||||||
|
|
||||||
# build a new image
|
# build a new image
|
||||||
BASE=build.$$
|
BASE=$CHROOTCACHE/build.$$
|
||||||
IMG=$BASE.img
|
IMG=$BASE.img
|
||||||
MNT=$BASE/
|
MNT=$BASE/
|
||||||
|
|
||||||
|
@ -97,7 +124,7 @@ mkfs.ext2 -F $IMG
|
||||||
# mount blank image loopback and load it
|
# mount blank image loopback and load it
|
||||||
mkdir -p $MNT
|
mkdir -p $MNT
|
||||||
mount -o loop $IMG $MNT
|
mount -o loop $IMG $MNT
|
||||||
rsync -azH cloned/ $MNT
|
rsync -azH $CHROOTCACHE/natty-stack/ $MNT
|
||||||
|
|
||||||
# umount and cleanup
|
# umount and cleanup
|
||||||
umount $MNT
|
umount $MNT
|
||||||
|
|
|
@ -144,7 +144,7 @@ dd if=/dev/null of=$TMPDISK bs=1M seek=$SIZE count=1
|
||||||
if [ -n "$IMAGEONLY" ]; then
|
if [ -n "$IMAGEONLY" ]; then
|
||||||
# Build image from chroot
|
# Build image from chroot
|
||||||
sudo vmbuilder $HYPER ubuntu $ARGS \
|
sudo vmbuilder $HYPER ubuntu $ARGS \
|
||||||
--existing-chroot=$CHR \
|
--existing-chroot=$CHROOTDIR \
|
||||||
--overwrite \
|
--overwrite \
|
||||||
--rootsize=$ROOTSIZE \
|
--rootsize=$ROOTSIZE \
|
||||||
--swapsize=$SWAPSIZE \
|
--swapsize=$SWAPSIZE \
|
||||||
|
|
Loading…
Reference in a new issue