Skip to content

Commit 0af143b

Browse files
Renuka ApteDean Troyer
authored andcommitted
XenServer: new build and install scripts
Change-Id: Ia13a9c8073e59edf98415ba5b9f3a9cbd1453d32
1 parent 836955f commit 0af143b

File tree

6 files changed

+116
-142
lines changed

6 files changed

+116
-142
lines changed

stack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ function read_password {
313313
if [ "$VIRT_DRIVER" = 'xenserver' ]; then
314314
PUBLIC_INTERFACE_DEFAULT=eth3
315315
# allow build_domU.sh to specify the flat network bridge via kernel args
316-
FLAT_NETWORK_BRIDGE_DEFAULT=$(grep -o 'flat_network_bridge=[^.]*' /proc/cmdline | cut -d= -f 2)
316+
FLAT_NETWORK_BRIDGE_DEFAULT=$(grep -o 'flat_network_bridge=[[:alnum:]]*' /proc/cmdline | cut -d= -f 2 | sort -u)
317317
GUEST_INTERFACE_DEFAULT=eth1
318318
else
319319
PUBLIC_INTERFACE_DEFAULT=br100

tools/xen/build_xva.sh

Lines changed: 32 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
#!/bin/bash
22

3+
set -e
4+
5+
declare -a on_exit_hooks
6+
7+
on_exit()
8+
{
9+
for i in $(seq $((${#on_exit_hooks[*]} - 1)) -1 0)
10+
do
11+
eval "${on_exit_hooks[$i]}"
12+
done
13+
}
14+
15+
add_on_exit()
16+
{
17+
local n=${#on_exit_hooks[*]}
18+
on_exit_hooks[$n]="$*"
19+
if [[ $n -eq 0 ]]
20+
then
21+
trap on_exit EXIT
22+
fi
23+
}
24+
325
# Abort if localrc is not set
426
if [ ! -e ../../localrc ]; then
527
echo "You must have a localrc with ALL necessary passwords defined before proceeding."
@@ -16,27 +38,11 @@ source xenrc
1638
# Echo commands
1739
set -o xtrace
1840

19-
# Directory where we stage the build
20-
STAGING_DIR=$TOP_DIR/stage
21-
22-
# Option to clean out old stuff
23-
CLEAN=${CLEAN:-0}
24-
if [ "$CLEAN" = "1" ]; then
25-
rm -rf $STAGING_DIR
26-
fi
27-
28-
# Download our base image. This image is made using prepare_guest.sh
29-
BASE_IMAGE_URL=${BASE_IMAGE_URL:-http://images.ansolabs.com/xen/stage.tgz}
30-
if [ ! -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
36-
fi
41+
GUEST_NAME="$1"
3742

38-
# Free up precious disk space
39-
rm -f /tmp/stage.tgz
43+
# Directory where we stage the build
44+
STAGING_DIR=$($TOP_DIR/scripts/manage-vdi open $GUEST_NAME 0 1 | grep -o "/tmp/tmp.[[:alnum:]]*")
45+
add_on_exit "$TOP_DIR/scripts/manage-vdi close $GUEST_NAME 0 1"
4046

4147
# Make sure we have a stage
4248
if [ ! -d $STAGING_DIR/etc ]; then
@@ -55,63 +61,26 @@ SCRIPT_DIR=$TOP_DIR/scripts
5561
UBUNTU_VERSION=`cat $STAGING_DIR/etc/lsb-release | grep "DISTRIB_CODENAME=" | sed "s/DISTRIB_CODENAME=//"`
5662
KERNEL_VERSION=`ls $STAGING_DIR/boot/vmlinuz* | head -1 | sed "s/.*vmlinuz-//"`
5763

58-
# Directory for xvas
59-
XVA_DIR=$TOP_DIR/xvas
60-
61-
# Create xva dir
62-
mkdir -p $XVA_DIR
63-
64-
# Path to xva
65-
XVA=$XVA_DIR/$GUEST_NAME.xva
66-
67-
# Setup fake grub
68-
rm -rf $STAGING_DIR/boot/grub/
69-
mkdir -p $STAGING_DIR/boot/grub/
70-
cp $TEMPLATES_DIR/menu.lst.in $STAGING_DIR/boot/grub/menu.lst
71-
sed -e "s,@KERNEL_VERSION@,$KERNEL_VERSION,g" -i $STAGING_DIR/boot/grub/menu.lst
72-
73-
# Setup fstab, tty, and other system stuff
74-
cp $FILES_DIR/fstab $STAGING_DIR/etc/fstab
75-
cp $FILES_DIR/hvc0.conf $STAGING_DIR/etc/init/
76-
77-
# Put the VPX into UTC.
78-
rm -f $STAGING_DIR/etc/localtime
79-
8064
# Configure dns (use same dns as dom0)
8165
cp /etc/resolv.conf $STAGING_DIR/etc/resolv.conf
8266

8367
# Copy over devstack
8468
rm -f /tmp/devstack.tar
85-
tar --exclude='stage' --exclude='xen/xvas' --exclude='xen/nova' -cvf /tmp/devstack.tar $TOP_DIR/../../../devstack
86-
cd $STAGING_DIR/opt/stack/
87-
tar xf /tmp/devstack.tar
69+
cd $TOP_DIR/../../
70+
tar --exclude='stage' --exclude='xen/xvas' --exclude='xen/nova' -cvf /tmp/devstack.tar .
71+
mkdir -p $STAGING_DIR/opt/stack/devstack
72+
tar xf /tmp/devstack.tar -C $STAGING_DIR/opt/stack/devstack
8873
cd $TOP_DIR
8974

90-
# Configure OVA
91-
VDI_SIZE=$(($VDI_MB*1024*1024))
92-
PRODUCT_BRAND=${PRODUCT_BRAND:-openstack}
93-
PRODUCT_VERSION=${PRODUCT_VERSION:-001}
94-
BUILD_NUMBER=${BUILD_NUMBER:-001}
95-
LABEL="$PRODUCT_BRAND $PRODUCT_VERSION-$BUILD_NUMBER"
96-
OVA=$STAGING_DIR/tmp/ova.xml
97-
cp $TEMPLATES_DIR/ova.xml.in $OVA
98-
sed -e "s,@VDI_SIZE@,$VDI_SIZE,g" -i $OVA
99-
sed -e "s,@PRODUCT_BRAND@,$PRODUCT_BRAND,g" -i $OVA
100-
sed -e "s,@PRODUCT_VERSION@,$PRODUCT_VERSION,g" -i $OVA
101-
sed -e "s,@BUILD_NUMBER@,$BUILD_NUMBER,g" -i $OVA
102-
10375
# Run devstack on launch
10476
cat <<EOF >$STAGING_DIR/etc/rc.local
10577
# network restart required for getting the right gateway
10678
/etc/init.d/networking restart
10779
GUEST_PASSWORD=$GUEST_PASSWORD STAGING_DIR=/ DO_TGZ=0 bash /opt/stack/devstack/tools/xen/prepare_guest.sh > /opt/stack/prepare_guest.log 2>&1
108-
su -c "/opt/stack/run.sh > /opt/stack/run.sh.log" stack
80+
su -c "/opt/stack/run.sh > /opt/stack/run.sh.log 2>&1" stack
10981
exit 0
11082
EOF
11183

112-
# Clean old xva. In the future may not do this every time.
113-
rm -f $XVA
114-
11584
# Configure the hostname
11685
echo $GUEST_NAME > $STAGING_DIR/etc/hostname
11786

@@ -151,10 +120,6 @@ else
151120
sed -e "s,@ETH3_NETMASK@,$PUB_NETMASK,g" -i $INTERFACES
152121
fi
153122

154-
if [ -h $STAGING_DIR/sbin/dhclient3 ]; then
155-
rm -f $STAGING_DIR/sbin/dhclient3
156-
fi
157-
158123
# Gracefully cp only if source file/dir exists
159124
function cp_it {
160125
if [ -e $1 ] || [ -d $1 ]; then
@@ -181,11 +146,4 @@ UPLOAD_LEGACY_TTY=yes HOST_IP=$PUB_IP VIRT_DRIVER=xenserver FORCE=yes MULTI_HOST
181146
EOF
182147
chmod 755 $STAGING_DIR/opt/stack/run.sh
183148

184-
# Create xva
185-
if [ ! -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/
188-
fi
189-
190-
echo "Built $(basename $XVA). If your dom0 is on a different machine, copy this to [devstackdir]/tools/xen/$(basename $XVA)"
191-
echo "Also copy your localrc to [devstackdir]"
149+
echo "Done"
Lines changed: 73 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# Exit on errors
4+
set -o errexit
5+
36
# Abort if localrc is not set
47
if [ ! -e ../../localrc ]; then
58
echo "You must have a localrc with ALL necessary passwords defined before proceeding."
@@ -19,25 +22,29 @@ source xenrc
1922
# Echo commands
2023
set -o xtrace
2124

22-
# Check for xva file
23-
if [ ! -e $XVA ]; then
24-
echo "Missing xva file. Please run build_xva.sh (ideally on a non dom0 host since the build can require lots of space)."
25-
echo "Place the resulting xva file in $XVA"
26-
exit 1
27-
fi
25+
xe_min()
26+
{
27+
local cmd="$1"
28+
shift
29+
xe "$cmd" --minimal "$@"
30+
}
2831

29-
# Make sure we have git
30-
if ! which git; then
31-
GITDIR=/tmp/git-1.7.7
32-
cd /tmp
33-
rm -rf $GITDIR*
34-
wget http://git-core.googlecode.com/files/git-1.7.7.tar.gz
35-
tar xfv git-1.7.7.tar.gz
36-
cd $GITDIR
37-
./configure --with-curl --with-expat
38-
make install
39-
cd $TOP_DIR
32+
cd $TOP_DIR
33+
if [ -f ./master ]
34+
then
35+
rm -rf ./master
36+
rm -rf ./nova
4037
fi
38+
wget https://github.com/openstack/nova/zipball/master --no-check-certificate
39+
unzip -o master -d ./nova
40+
cp -pr ./nova/*/plugins/xenserver/xenapi/etc/xapi.d /etc/
41+
chmod a+x /etc/xapi.d/plugins/*
42+
43+
mkdir -p /boot/guest
44+
45+
GUEST_NAME=${GUEST_NAME:-"DevStackOSDomU"}
46+
SNAME="ubuntusnapshot"
47+
TNAME="ubuntuready"
4148

4249
# Helper to create networks
4350
# Uses echo trickery to return network uuid
@@ -48,23 +55,23 @@ function create_network() {
4855
netname=$4
4956
if [ -z $br ]
5057
then
51-
pif=$(xe pif-list --minimal device=$dev VLAN=$vlan)
58+
pif=$(xe_min pif-list device=$dev VLAN=$vlan)
5259
if [ -z $pif ]
5360
then
5461
net=$(xe network-create name-label=$netname)
5562
else
56-
net=$(xe network-list --minimal PIF-uuids=$pif)
63+
net=$(xe_min network-list PIF-uuids=$pif)
5764
fi
5865
echo $net
5966
return 0
6067
fi
61-
if [ ! $(xe network-list --minimal params=bridge | grep -w --only-matching $br) ]
68+
if [ ! $(xe_min network-list params=bridge | grep -w --only-matching $br) ]
6269
then
6370
echo "Specified bridge $br does not exist"
6471
echo "If you wish to use defaults, please keep the bridge name empty"
6572
exit 1
6673
else
67-
net=$(xe network-list --minimal bridge=$br)
74+
net=$(xe_min network-list bridge=$br)
6875
echo $net
6976
fi
7077
}
@@ -95,13 +102,13 @@ function create_vlan() {
95102
then
96103
return
97104
fi
98-
if [ -z $(xe vlan-list --minimal tag=$vlan) ]
105+
if [ -z $(xe_min vlan-list tag=$vlan) ]
99106
then
100-
pif=$(xe pif-list --minimal network-uuid=$net)
107+
pif=$(xe_min pif-list network-uuid=$net)
101108
# We created a brand new network this time
102109
if [ -z $pif ]
103110
then
104-
pif=$(xe pif-list --minimal device=$dev VLAN=-1)
111+
pif=$(xe_min pif-list device=$dev VLAN=-1)
105112
xe vlan-create pif-uuid=$pif vlan=$vlan network-uuid=$net
106113
else
107114
echo "VLAN does not exist but PIF attached to this network"
@@ -133,24 +140,11 @@ fi
133140
# Enable ip forwarding at runtime as well
134141
echo 1 > /proc/sys/net/ipv4/ip_forward
135142

136-
# Set local storage il8n
137-
SR_UUID=`xe sr-list --minimal name-label="Local storage"`
138-
xe sr-param-set uuid=$SR_UUID other-config:i18n-key=local-storage
139-
140-
# Checkout nova
141-
git_clone $NOVA_REPO $TOP_DIR/nova $NOVA_BRANCH
142-
143-
# Install plugins
144-
cp -pr $TOP_DIR/nova/plugins/xenserver/xenapi/etc/xapi.d /etc/
145-
chmod a+x /etc/xapi.d/plugins/*
146-
yum --enablerepo=base install -y parted
147-
mkdir -p /boot/guest
148-
149143
# Shutdown previous runs
150144
DO_SHUTDOWN=${DO_SHUTDOWN:-1}
151145
if [ "$DO_SHUTDOWN" = "1" ]; then
152146
# Shutdown all domU's that created previously
153-
xe vm-list --minimal name-label="$LABEL" | xargs ./scripts/uninstall-os-vpx.sh
147+
xe_min vm-list name-label="$GUEST_NAME" | xargs ./scripts/uninstall-os-vpx.sh
154148

155149
# Destroy any instances that were launched
156150
for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do
@@ -168,18 +162,54 @@ fi
168162

169163
# Start guest
170164
if [ -z $VM_BR ]; then
171-
VM_BR=$(xe network-list --minimal uuid=$VM_NET params=bridge)
165+
VM_BR=$(xe_min network-list uuid=$VM_NET params=bridge)
172166
fi
173167
if [ -z $MGT_BR ]; then
174-
MGT_BR=$(xe network-list --minimal uuid=$MGT_NET params=bridge)
168+
MGT_BR=$(xe_min network-list uuid=$MGT_NET params=bridge)
175169
fi
176170
if [ -z $PUB_BR ]; then
177-
PUB_BR=$(xe network-list --minimal uuid=$PUB_NET params=bridge)
171+
PUB_BR=$(xe_min network-list uuid=$PUB_NET params=bridge)
178172
fi
179-
$TOP_DIR/scripts/install-os-vpx.sh -f $XVA -v $VM_BR -m $MGT_BR -p $PUB_BR -l $GUEST_NAME -w -k "flat_network_bridge=${VM_BR}"
173+
174+
templateuuid=$(xe template-list name-label="$TNAME")
175+
if [ -n "$templateuuid" ]
176+
then
177+
vm_uuid=$(xe vm-install template="$TNAME" new-name-label="$GUEST_NAME")
178+
else
179+
template=$(xe_min template-list name-label="Ubuntu 11.10 (64-bit)")
180+
if [ -z "$template" ]
181+
then
182+
$TOP_DIR/scripts/xenoneirictemplate.sh
183+
fi
184+
$TOP_DIR/scripts/install-os-vpx.sh -t "Ubuntu 11.10 (64-bit)" -v $VM_BR -m $MGT_BR -p $PUB_BR -l $GUEST_NAME -r $OSDOMU_MEM_MB -k "flat_network_bridge=${VM_BR}"
185+
186+
# Wait for install to finish
187+
while true
188+
do
189+
state=$(xe_min vm-list name-label="$GUEST_NAME" power-state=halted)
190+
if [ -n "$state" ]
191+
then
192+
break
193+
else
194+
echo "Waiting for "$GUEST_NAME" to finish installation..."
195+
sleep 30
196+
fi
197+
done
198+
199+
vm_uuid=$(xe_min vm-list name-label="$GUEST_NAME")
200+
xe vm-param-set actions-after-reboot=Restart uuid="$vm_uuid"
201+
202+
# Make template from VM
203+
snuuid=$(xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME")
204+
template_uuid=$(xe snapshot-clone uuid=$snuuid new-name-label="$TNAME")
205+
fi
206+
207+
$TOP_DIR/build_xva.sh "$GUEST_NAME"
208+
209+
xe vm-start vm="$GUEST_NAME"
180210

181211
if [ $PUB_IP == "dhcp" ]; then
182-
PUB_IP=$(xe vm-list --minimal name-label=$GUEST_NAME params=networks | sed -ne 's,^.*3/ip: \([0-9.]*\).*$,\1,p')
212+
PUB_IP=$(xe_min vm-list name-label=$GUEST_NAME params=networks | sed -ne 's,^.*3/ip: \([0-9.]*\).*$,\1,p')
183213
fi
184214

185215
# If we have copied our ssh credentials, use ssh to monitor while the installation runs

tools/xen/prepare_guest.sh

100644100755
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ set -x
66
GUEST_PASSWORD=${GUEST_PASSWORD:-secrete}
77
STAGING_DIR=${STAGING_DIR:-stage}
88
DO_TGZ=${DO_TGZ:-1}
9-
KERNEL_VERSION=3.0.0-12-virtual
10-
11-
# Debootstrap base system
12-
if [ ! -d $STAGING_DIR ]; then
13-
apt-get install debootstrap
14-
debootstrap --arch amd64 oneiric $STAGING_DIR http://us.archive.ubuntu.com/ubuntu/
15-
fi
169

1710
# Sources.list
1811
cat <<EOF >$STAGING_DIR/etc/apt/sources.list
@@ -28,7 +21,6 @@ EOF
2821

2922
# Install basics
3023
chroot $STAGING_DIR apt-get update
31-
chroot $STAGING_DIR apt-get install -y linux-image-$KERNEL_VERSION
3224
chroot $STAGING_DIR apt-get install -y cracklib-runtime curl wget ssh openssh-server tcpdump ethtool
3325
chroot $STAGING_DIR apt-get install -y curl wget ssh openssh-server python-pip git vim-nox sudo
3426
chroot $STAGING_DIR pip install xenapi

0 commit comments

Comments
 (0)