blob: c8721aa9d114f881116bcdf72ed979ca0e59f9b3 [file] [log] [blame]
Anthony Young11889042012-01-12 17:11:56 -08001#!/bin/bash
2
3# Abort if localrc is not set
4if [ ! -e ../../localrc ]; then
5 echo "You must have a localrc with ALL necessary passwords defined before proceeding."
6 echo "See the xen README for required passwords."
7 exit 1
8fi
9
10# This directory
11TOP_DIR=$(cd $(dirname "$0") && pwd)
12
13# Source params - override xenrc params in your localrc to suite your taste
14source xenrc
15
16# Echo commands
17set -o xtrace
18
19# Directory where we stage the build
20STAGING_DIR=$TOP_DIR/stage
21
22# Option to clean out old stuff
23CLEAN=${CLEAN:-0}
24if [ "$CLEAN" = "1" ]; then
25 rm -rf $STAGING_DIR
26fi
27
28# Download our base image. This image is made using prepare_guest.sh
29BASE_IMAGE_URL=${BASE_IMAGE_URL:-http://images.ansolabs.com/xen/stage.tgz}
30if [ ! -e $STAGING_DIR ]; then
31 if [ ! -e /tmp/stage.tgz ]; then
32 wget $BASE_IMAGE_URL -O /tmp/stage.tgz
33 fi
34 tar xfz /tmp/stage.tgz
35 cd $TOP_DIR
36fi
37
38# Free up precious disk space
39rm -f /tmp/stage.tgz
40
41# Make sure we have a stage
42if [ ! -d $STAGING_DIR/etc ]; then
43 echo "Stage is not properly set up!"
44 exit 1
45fi
46
47# Directory where our conf files are stored
48FILES_DIR=$TOP_DIR/files
49TEMPLATES_DIR=$TOP_DIR/templates
50
51# Directory for supporting script files
52SCRIPT_DIR=$TOP_DIR/scripts
53
54# Version of ubuntu with which we are working
55UBUNTU_VERSION=`cat $STAGING_DIR/etc/lsb-release | grep "DISTRIB_CODENAME=" | sed "s/DISTRIB_CODENAME=//"`
56KERNEL_VERSION=`ls $STAGING_DIR/boot/vmlinuz* | head -1 | sed "s/.*vmlinuz-//"`
57
58# Directory for xvas
59XVA_DIR=$TOP_DIR/xvas
60
61# Create xva dir
62mkdir -p $XVA_DIR
63
64# Path to xva
rootb1153412012-01-19 13:28:21 -080065XVA=$XVA_DIR/$GUEST_NAME.xva
Anthony Young11889042012-01-12 17:11:56 -080066
67# Setup fake grub
68rm -rf $STAGING_DIR/boot/grub/
69mkdir -p $STAGING_DIR/boot/grub/
70cp $TEMPLATES_DIR/menu.lst.in $STAGING_DIR/boot/grub/menu.lst
71sed -e "s,@KERNEL_VERSION@,$KERNEL_VERSION,g" -i $STAGING_DIR/boot/grub/menu.lst
72
73# Setup fstab, tty, and other system stuff
74cp $FILES_DIR/fstab $STAGING_DIR/etc/fstab
75cp $FILES_DIR/hvc0.conf $STAGING_DIR/etc/init/
76
77# Put the VPX into UTC.
78rm -f $STAGING_DIR/etc/localtime
79
80# Configure dns (use same dns as dom0)
81cp /etc/resolv.conf $STAGING_DIR/etc/resolv.conf
82
83# Copy over devstack
84rm -f /tmp/devstack.tar
85tar --exclude='stage' --exclude='xen/xvas' --exclude='xen/nova' -cvf /tmp/devstack.tar $TOP_DIR/../../../devstack
86cd $STAGING_DIR/opt/stack/
87tar xf /tmp/devstack.tar
88cd $TOP_DIR
89
90# Configure OVA
91VDI_SIZE=$(($VDI_MB*1024*1024))
92PRODUCT_BRAND=${PRODUCT_BRAND:-openstack}
93PRODUCT_VERSION=${PRODUCT_VERSION:-001}
94BUILD_NUMBER=${BUILD_NUMBER:-001}
95LABEL="$PRODUCT_BRAND $PRODUCT_VERSION-$BUILD_NUMBER"
96OVA=$STAGING_DIR/tmp/ova.xml
97cp $TEMPLATES_DIR/ova.xml.in $OVA
98sed -e "s,@VDI_SIZE@,$VDI_SIZE,g" -i $OVA
99sed -e "s,@PRODUCT_BRAND@,$PRODUCT_BRAND,g" -i $OVA
100sed -e "s,@PRODUCT_VERSION@,$PRODUCT_VERSION,g" -i $OVA
101sed -e "s,@BUILD_NUMBER@,$BUILD_NUMBER,g" -i $OVA
102
103# Run devstack on launch
104cat <<EOF >$STAGING_DIR/etc/rc.local
rootb1153412012-01-19 13:28:21 -0800105# network restart required for getting the right gateway
106/etc/init.d/networking restart
Anthony Young11889042012-01-12 17:11:56 -0800107GUEST_PASSWORD=$GUEST_PASSWORD STAGING_DIR=/ DO_TGZ=0 bash /opt/stack/devstack/tools/xen/prepare_guest.sh
108su -c "/opt/stack/run.sh > /opt/stack/run.sh.log" stack
109exit 0
110EOF
111
112# Clean old xva. In the future may not do this every time.
113rm -f $XVA
114
115# Configure the hostname
116echo $GUEST_NAME > $STAGING_DIR/etc/hostname
117
118# Hostname must resolve for rabbit
119cat <<EOF >$STAGING_DIR/etc/hosts
120$MGT_IP $GUEST_NAME
121127.0.0.1 localhost localhost.localdomain
122EOF
123
124# Configure the network
125INTERFACES=$STAGING_DIR/etc/network/interfaces
126cp $TEMPLATES_DIR/interfaces.in $INTERFACES
rootb1153412012-01-19 13:28:21 -0800127if [ $VM_IP == "dhcp" ]; then
128 echo 'eth1 on dhcp'
129 sed -e "s,iface eth1 inet static,iface eth1 inet dhcp,g" -i $INTERFACES
130 sed -e '/@ETH1_/d' -i $INTERFACES
131else
132 sed -e "s,@ETH1_IP@,$VM_IP,g" -i $INTERFACES
133 sed -e "s,@ETH1_NETMASK@,$VM_NETMASK,g" -i $INTERFACES
134fi
135
136if [ $MGT_IP == "dhcp" ]; then
137 echo 'eth2 on dhcp'
138 sed -e "s,iface eth2 inet static,iface eth2 inet dhcp,g" -i $INTERFACES
139 sed -e '/@ETH2_/d' -i $INTERFACES
140else
141 sed -e "s,@ETH2_IP@,$MGT_IP,g" -i $INTERFACES
142 sed -e "s,@ETH2_NETMASK@,$MGT_NETMASK,g" -i $INTERFACES
143fi
144
145if [ $PUB_IP == "dhcp" ]; then
146 echo 'eth3 on dhcp'
147 sed -e "s,iface eth3 inet static,iface eth3 inet dhcp,g" -i $INTERFACES
148 sed -e '/@ETH3_/d' -i $INTERFACES
149else
150 sed -e "s,@ETH3_IP@,$PUB_IP,g" -i $INTERFACES
151 sed -e "s,@ETH3_NETMASK@,$PUB_NETMASK,g" -i $INTERFACES
152fi
153
154if [ -h $STAGING_DIR/sbin/dhclient3 ]; then
155 rm -f $STAGING_DIR/sbin/dhclient3
156fi
Anthony Young11889042012-01-12 17:11:56 -0800157
158# Gracefully cp only if source file/dir exists
159function cp_it {
160 if [ -e $1 ] || [ -d $1 ]; then
161 cp -pRL $1 $2
162 fi
163}
164
165# Copy over your ssh keys and env if desired
166COPYENV=${COPYENV:-1}
167if [ "$COPYENV" = "1" ]; then
168 cp_it ~/.ssh $STAGING_DIR/opt/stack/.ssh
169 cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/opt/stack/.ssh/authorized_keys
170 cp_it ~/.gitconfig $STAGING_DIR/opt/stack/.gitconfig
171 cp_it ~/.vimrc $STAGING_DIR/opt/stack/.vimrc
172 cp_it ~/.bashrc $STAGING_DIR/opt/stack/.bashrc
173fi
174
175# Configure run.sh
176cat <<EOF >$STAGING_DIR/opt/stack/run.sh
177#!/bin/bash
178cd /opt/stack/devstack
179killall screen
rootb1153412012-01-19 13:28:21 -0800180UPLOAD_LEGACY_TTY=yes HOST_IP=$PUB_IP VIRT_DRIVER=xenserver FORCE=yes MULTI_HOST=1 HOST_IP_IFACE=$HOST_IP_IFACE $STACKSH_PARAMS ./stack.sh
Anthony Young11889042012-01-12 17:11:56 -0800181EOF
182chmod 755 $STAGING_DIR/opt/stack/run.sh
183
184# Create xva
185if [ ! -e $XVA ]; then
186 rm -rf /tmp/mkxva*
187 UID=0 $SCRIPT_DIR/mkxva -o $XVA -t xva -x $OVA $STAGING_DIR $VDI_MB /tmp/
188fi
189
190echo "Built $XVA. If your dom0 is on a different machine, copy this to [devstackdir]/tools/xen/$XVA"