-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathbuild_uec_ramdisk.sh
executable file
·180 lines (138 loc) · 4.46 KB
/
build_uec_ramdisk.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/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)
# Import common functions
. $TOP_DIR/functions
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_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 $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 $TEMPEST_REPO $DEST/tempest $TEMPEST_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