Browse code

Merge changes Ie7cb4858,Iadb6e181,I2dc31acb,Ia3e2e65b

* changes:
Remove cloning of devstack
Multiple vpx for xen, post splitting of script
Add logging for prepare_guest
Generalize xen network config

Jenkins authored on 2012/02/18 06:44:11
Showing 10 changed files
... ...
@@ -200,14 +200,13 @@ LIBVIRT_TYPE=${LIBVIRT_TYPE:-kvm}
200 200
 # cases unless you are working on multi-zone mode.
201 201
 SCHEDULER=${SCHEDULER:-nova.scheduler.simple.SimpleScheduler}
202 202
 
203
+HOST_IP_IFACE=${HOST_IP_IFACE:-eth0}
203 204
 # Use the eth0 IP unless an explicit is set by ``HOST_IP`` environment variable
204
-if [ ! -n "$HOST_IP" ]; then
205
-    HOST_IP=`LC_ALL=C /sbin/ifconfig eth0 | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
205
+if [ -z "$HOST_IP" -o "$HOST_IP" == "dhcp" ]; then
206
+    HOST_IP=`LC_ALL=C /sbin/ifconfig ${HOST_IP_IFACE} | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
206 207
     if [ "$HOST_IP" = "" ]; then
207 208
         echo "Could not determine host ip address."
208
-        echo "If this is not your first run of stack.sh, it is "
209
-        echo "possible that nova moved your eth0 ip address to the FLAT_NETWORK_BRIDGE."
210
-        echo "Please specify your HOST_IP in your localrc."
209
+        echo "Either localrc specified dhcp on ${HOST_IP_IFACE} or defaulted to eth0"
211 210
         exit 1
212 211
     fi
213 212
 fi
... ...
@@ -37,51 +37,85 @@ if ! which git; then
37 37
 fi
38 38
 
39 39
 # Helper to create networks
40
+# Uses echo trickery to return network uuid
40 41
 function create_network() {
41
-    if ! xe network-list | grep bridge | grep -q $1; then
42
-        echo "Creating bridge $1"
43
-        xe network-create name-label=$1
42
+    br=$1
43
+    dev=$2
44
+    vlan=$3
45
+    netname=$4
46
+    if [ -z $br ]
47
+    then
48
+        pif=$(xe pif-list --minimal device=$dev VLAN=$vlan)
49
+        if [ -z $pif ]
50
+        then
51
+            net=$(xe network-create name-label=$netname)
52
+        else
53
+            net=$(xe network-list --minimal PIF-uuids=$pif)
54
+        fi
55
+        echo $net
56
+        return 0
57
+    fi
58
+    if [ ! $(xe network-list --minimal params=bridge | grep -w --only-matching $br) ]
59
+    then
60
+        echo "Specified bridge $br does not exist"
61
+        echo "If you wish to use defaults, please keep the bridge name empty"
62
+        exit 1
63
+    else
64
+        net=$(xe network-list --minimal bridge=$br)
65
+        echo $net
44 66
     fi
45 67
 }
46 68
 
47
-# Create host, vm, mgmt, pub networks
48
-create_network xapi0
49
-create_network $VM_BR
50
-create_network $MGT_BR
51
-create_network $PUB_BR
52
-
53
-# Get the uuid for our physical (public) interface
54
-PIF=`xe pif-list --minimal device=eth0`
69
+function errorcheck() {
70
+    rc=$?
71
+    if [ $rc -ne 0 ]
72
+    then
73
+        exit $rc
74
+    fi
75
+}
55 76
 
56
-# Create networks/bridges for vm and management
57
-VM_NET=`xe network-list --minimal bridge=$VM_BR`
58
-MGT_NET=`xe network-list --minimal bridge=$MGT_BR`
77
+# Create host, vm, mgmt, pub networks
78
+VM_NET=$(create_network "$VM_BR" "$VM_DEV" "$VM_VLAN" "vmbr")
79
+errorcheck
80
+MGT_NET=$(create_network "$MGT_BR" "$MGT_DEV" "$MGT_VLAN" "mgtbr")
81
+errorcheck
82
+PUB_NET=$(create_network "$PUB_BR" "$PUB_DEV" "$PUB_VLAN" "pubbr")
83
+errorcheck
59 84
 
60 85
 # Helper to create vlans
61 86
 function create_vlan() {
62
-    pif=$1
87
+    dev=$1
63 88
     vlan=$2
64 89
     net=$3
65
-    if ! xe vlan-list | grep tag | grep -q $vlan; then
66
-        xe vlan-create pif-uuid=$pif vlan=$vlan network-uuid=$net
90
+    # VLAN -1 refers to no VLAN (physical network)
91
+    if [ $vlan -eq -1 ]
92
+    then
93
+        return
94
+    fi
95
+    if [ -z $(xe vlan-list --minimal tag=$vlan) ]
96
+    then
97
+        pif=$(xe pif-list --minimal network-uuid=$net)
98
+        # We created a brand new network this time
99
+        if [ -z $pif ]
100
+        then
101
+            pif=$(xe pif-list --minimal device=$dev VLAN=-1)
102
+            xe vlan-create pif-uuid=$pif vlan=$vlan network-uuid=$net
103
+        else
104
+            echo "VLAN does not exist but PIF attached to this network"
105
+            echo "How did we reach here?"
106
+            exit 1
107
+        fi
67 108
     fi
68 109
 }
69 110
 
70 111
 # Create vlans for vm and management
71
-create_vlan $PIF $VM_VLAN $VM_NET
72
-create_vlan $PIF $MGT_VLAN $MGT_NET
112
+create_vlan $PUB_DEV $PUB_VLAN $PUB_NET
113
+create_vlan $VM_DEV $VM_VLAN $VM_NET
114
+create_vlan $MGT_DEV $MGT_VLAN $MGT_NET
73 115
 
74 116
 # dom0 ip
75 117
 HOST_IP=${HOST_IP:-`ifconfig xenbr0 | grep "inet addr" | cut -d ":" -f2 | sed "s/ .*//"`}
76 118
 
77
-# Setup host-only nat rules
78
-HOST_NET=169.254.0.0/16
79
-if ! iptables -L -v -t nat | grep -q $HOST_NET; then
80
-    iptables -t nat -A POSTROUTING -s $HOST_NET -j SNAT --to-source $HOST_IP
81
-    iptables -I FORWARD 1 -s $HOST_NET -j ACCEPT
82
-    /etc/init.d/iptables save
83
-fi
84
-
85 119
 # Set up ip forwarding
86 120
 if ! grep -q "FORWARD_IPV4=YES" /etc/sysconfig/network; then
87 121
     # FIXME: This doesn't work on reboot!
... ...
@@ -139,7 +173,16 @@ if [ "$DO_SHUTDOWN" = "1" ]; then
139 139
 fi
140 140
 
141 141
 # Start guest
142
-$TOP_DIR/scripts/install-os-vpx.sh -f $XVA -v $VM_BR -m $MGT_BR -p $PUB_BR
142
+if [ -z $VM_BR ]; then
143
+    VM_BR=$(xe network-list --minimal uuid=$VM_NET params=bridge)
144
+fi
145
+if [ -z $MGT_BR ]; then
146
+    MGT_BR=$(xe network-list --minimal uuid=$MGT_NET params=bridge)
147
+fi
148
+if [ -z $PUB_BR ]; then
149
+    PUB_BR=$(xe network-list --minimal uuid=$PUB_NET params=bridge)
150
+fi
151
+$TOP_DIR/scripts/install-os-vpx.sh -f $XVA -v $VM_BR -m $MGT_BR -p $PUB_BR -l $GUEST_NAME -w
143 152
 
144 153
 # If we have copied our ssh credentials, use ssh to monitor while the installation runs
145 154
 WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
... ...
@@ -17,19 +17,19 @@ FLOATING_RANGE=${FLOATING_RANGE:-192.168.1.196/30}
17 17
 COMMON_VARS="$STACKSH_PARAMS MYSQL_HOST=$HEAD_MGT_IP RABBIT_HOST=$HEAD_MGT_IP GLANCE_HOSTPORT=$HEAD_MGT_IP:9292 FLOATING_RANGE=$FLOATING_RANGE"
18 18
 
19 19
 # Helper to launch containers
20
-function build_domU {
21
-    GUEST_NAME=$1 PUB_IP=$2 MGT_IP=$3 DO_SHUTDOWN=$4 TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $5" ./build_domU.sh
20
+function build_xva {
21
+    GUEST_NAME=$1 PUB_IP=$2 MGT_IP=$3 DO_SHUTDOWN=$4 TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $5" ./build_xva.sh
22 22
 }
23 23
 
24 24
 # Launch the head node - headnode uses a non-ip domain name,
25 25
 # because rabbit won't launch with an ip addr hostname :(
26
-build_domU HEADNODE $HEAD_PUB_IP $HEAD_MGT_IP 1 "ENABLED_SERVICES=g-api,g-reg,key,n-api,n-sch,n-vnc,horizon,mysql,rabbit"
26
+build_xva HEADNODE $HEAD_PUB_IP $HEAD_MGT_IP 1 "ENABLED_SERVICES=g-api,g-reg,key,n-api,n-sch,n-vnc,horizon,mysql,rabbit"
27 27
 
28 28
 # Wait till the head node is up
29
-while ! curl -L http://$HEAD_PUB_IP | grep -q username; do
30
-    echo "Waiting for head node ($HEAD_PUB_IP) to start..."
31
-    sleep 5
32
-done
29
+#while ! curl -L http://$HEAD_PUB_IP | grep -q username; do
30
+#    echo "Waiting for head node ($HEAD_PUB_IP) to start..."
31
+#    sleep 5
32
+#done
33 33
 
34 34
 # Build the HA compute host
35
-build_domU $COMPUTE_PUB_IP $COMPUTE_PUB_IP $COMPUTE_MGT_IP 0 "ENABLED_SERVICES=n-cpu,n-net,n-api"
35
+build_xva COMPUTENODE $COMPUTE_PUB_IP $COMPUTE_MGT_IP 0 "ENABLED_SERVICES=n-cpu,n-net,n-api"
... ...
@@ -62,7 +62,7 @@ XVA_DIR=$TOP_DIR/xvas
62 62
 mkdir -p $XVA_DIR
63 63
 
64 64
 # Path to xva
65
-XVA=$XVA_DIR/$GUEST_NAME.xva 
65
+XVA=$XVA_DIR/$GUEST_NAME.xva
66 66
 
67 67
 # Setup fake grub
68 68
 rm -rf $STAGING_DIR/boot/grub/
... ...
@@ -102,7 +102,9 @@ sed -e "s,@BUILD_NUMBER@,$BUILD_NUMBER,g" -i $OVA
102 102
 
103 103
 # Run devstack on launch
104 104
 cat <<EOF >$STAGING_DIR/etc/rc.local
105
-GUEST_PASSWORD=$GUEST_PASSWORD STAGING_DIR=/ DO_TGZ=0 bash /opt/stack/devstack/tools/xen/prepare_guest.sh
105
+# network restart required for getting the right gateway
106
+/etc/init.d/networking restart
107
+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
106 108
 su -c "/opt/stack/run.sh > /opt/stack/run.sh.log" stack
107 109
 exit 0
108 110
 EOF
... ...
@@ -122,12 +124,36 @@ EOF
122 122
 # Configure the network
123 123
 INTERFACES=$STAGING_DIR/etc/network/interfaces
124 124
 cp $TEMPLATES_DIR/interfaces.in  $INTERFACES
125
-sed -e "s,@ETH1_IP@,$VM_IP,g" -i $INTERFACES
126
-sed -e "s,@ETH1_NETMASK@,$VM_NETMASK,g" -i $INTERFACES
127
-sed -e "s,@ETH2_IP@,$MGT_IP,g" -i $INTERFACES
128
-sed -e "s,@ETH2_NETMASK@,$MGT_NETMASK,g" -i $INTERFACES
129
-sed -e "s,@ETH3_IP@,$PUB_IP,g" -i $INTERFACES
130
-sed -e "s,@ETH3_NETMASK@,$PUB_NETMASK,g" -i $INTERFACES
125
+if [ $VM_IP == "dhcp" ]; then
126
+    echo 'eth1 on dhcp'
127
+    sed -e "s,iface eth1 inet static,iface eth1 inet dhcp,g" -i $INTERFACES
128
+    sed -e '/@ETH1_/d' -i $INTERFACES
129
+else
130
+    sed -e "s,@ETH1_IP@,$VM_IP,g" -i $INTERFACES
131
+    sed -e "s,@ETH1_NETMASK@,$VM_NETMASK,g" -i $INTERFACES
132
+fi
133
+
134
+if [ $MGT_IP == "dhcp" ]; then
135
+    echo 'eth2 on dhcp'
136
+    sed -e "s,iface eth2 inet static,iface eth2 inet dhcp,g" -i $INTERFACES
137
+    sed -e '/@ETH2_/d' -i $INTERFACES
138
+else
139
+    sed -e "s,@ETH2_IP@,$MGT_IP,g" -i $INTERFACES
140
+    sed -e "s,@ETH2_NETMASK@,$MGT_NETMASK,g" -i $INTERFACES
141
+fi
142
+
143
+if [ $PUB_IP == "dhcp" ]; then
144
+    echo 'eth3 on dhcp'
145
+    sed -e "s,iface eth3 inet static,iface eth3 inet dhcp,g" -i $INTERFACES
146
+    sed -e '/@ETH3_/d' -i $INTERFACES
147
+else
148
+    sed -e "s,@ETH3_IP@,$PUB_IP,g" -i $INTERFACES
149
+    sed -e "s,@ETH3_NETMASK@,$PUB_NETMASK,g" -i $INTERFACES
150
+fi
151
+
152
+if [ -h $STAGING_DIR/sbin/dhclient3 ]; then
153
+    rm -f $STAGING_DIR/sbin/dhclient3
154
+fi
131 155
 
132 156
 # Gracefully cp only if source file/dir exists
133 157
 function cp_it {
... ...
@@ -151,7 +177,7 @@ cat <<EOF >$STAGING_DIR/opt/stack/run.sh
151 151
 #!/bin/bash
152 152
 cd /opt/stack/devstack
153 153
 killall screen
154
-UPLOAD_LEGACY_TTY=yes HOST_IP=$PUB_IP VIRT_DRIVER=xenserver FORCE=yes MULTI_HOST=1 $STACKSH_PARAMS ./stack.sh
154
+UPLOAD_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
155 155
 EOF
156 156
 chmod 755 $STAGING_DIR/opt/stack/run.sh
157 157
 
158 158
new file mode 100755
... ...
@@ -0,0 +1,40 @@
0
+#!/usr/bin/env bash
1
+
2
+# Echo commands
3
+set -o xtrace
4
+
5
+# Head node host, which runs glance, api, keystone
6
+HEAD_PUB_IP=${HEAD_PUB_IP:-192.168.1.57}
7
+HEAD_MGT_IP=${HEAD_MGT_IP:-172.16.100.57}
8
+
9
+COMPUTE_PUB_IP=${COMPUTE_PUB_IP:-192.168.1.58}
10
+COMPUTE_MGT_IP=${COMPUTE_MGT_IP:-172.16.100.58}
11
+
12
+# Networking params
13
+FLOATING_RANGE=${FLOATING_RANGE:-192.168.1.196/30}
14
+
15
+# Variables common amongst all hosts in the cluster
16
+COMMON_VARS="$STACKSH_PARAMS MYSQL_HOST=$HEAD_MGT_IP RABBIT_HOST=$HEAD_MGT_IP GLANCE_HOSTPORT=$HEAD_MGT_IP:9292 FLOATING_RANGE=$FLOATING_RANGE"
17
+
18
+# Helper to launch containers
19
+function install_domU {
20
+    GUEST_NAME=$1 PUB_IP=$2 MGT_IP=$3 DO_SHUTDOWN=$4 TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $5" ./build_domU.sh
21
+}
22
+
23
+# Launch the head node - headnode uses a non-ip domain name,
24
+# because rabbit won't launch with an ip addr hostname :(
25
+install_domU HEADNODE $HEAD_PUB_IP $HEAD_MGT_IP 1 "ENABLED_SERVICES=g-api,g-reg,key,n-api,n-sch,n-vnc,horizon,mysql,rabbit"
26
+
27
+if [ $HEAD_PUB_IP == "dhcp" ]
28
+then
29
+    guestnet=$(xe vm-list --minimal name-label=HEADNODE params=networks)
30
+    HEAD_PUB_IP=$(echo $guestnet | grep -w -o --only-matching "3/ip: [0-9,.]*;" | cut -d ':' -f2 | cut -d ';' -f 1)
31
+fi
32
+# Wait till the head node is up
33
+while ! curl -L http://$HEAD_PUB_IP | grep -q username; do
34
+    echo "Waiting for head node ($HEAD_PUB_IP) to start..."
35
+    sleep 5
36
+done
37
+
38
+# Build the HA compute host
39
+install_domU COMPUTENODE $COMPUTE_PUB_IP $COMPUTE_MGT_IP 0 "ENABLED_SERVICES=n-cpu,n-net,n-api"
... ...
@@ -34,8 +34,3 @@ if ! which git; then
34 34
     make install
35 35
 fi
36 36
 
37
-# Clone devstack
38
-DEVSTACK=/root/devstack
39
-if [ ! -d $DEVSTACK ]; then
40
-    git clone git://github.com/cloudbuilders/devstack.git $DEVSTACK
41
-fi
... ...
@@ -1,5 +1,7 @@
1 1
 #!/bin/bash
2 2
 
3
+set -x
4
+
3 5
 # Configurable nuggets
4 6
 GUEST_PASSWORD=${GUEST_PASSWORD:-secrete}
5 7
 STAGING_DIR=${STAGING_DIR:-stage}
... ...
@@ -38,7 +38,7 @@ usage()
38 38
 cat << EOF
39 39
 
40 40
   Usage: $0 [-f FILE_PATH] [-d DISK_SIZE] [-v BRIDGE_NAME] [-m BRIDGE_NAME] [-p BRIDGE_NAME]
41
-            [-k PARAMS] [-r RAM] [-i|-c] [-w] [-b]
41
+            [-k PARAMS] [-r RAM] [-i|-c] [-w] [-b] [-l NAME_LABEL]
42 42
 
43 43
   Installs XenServer OpenStack VPX.
44 44
 
... ...
@@ -60,6 +60,7 @@ cat << EOF
60 60
      -k params    Specifies kernel parameters.
61 61
      -r MiB       Specifies RAM used by the VPX, in MiB.
62 62
                   By default it will take the value from the XVA.
63
+     -l name      Specifies the name label for the VM.
63 64
 
64 65
   EXAMPLES:
65 66
 
... ...
@@ -87,7 +88,7 @@ EOF
87 87
 
88 88
 get_params()
89 89
 {
90
-  while getopts "hicwbf:d:v:m:p:k:r:" OPTION; 
90
+  while getopts "hicwbf:d:v:m:p:k:r:l:" OPTION; 
91 91
   do
92 92
     case $OPTION in
93 93
       h) usage
... ...
@@ -126,6 +127,9 @@ get_params()
126 126
       v)
127 127
          BRIDGE_V=$OPTARG
128 128
          ;;
129
+     l)
130
+         NAME_LABEL=$OPTARG
131
+         ;;
129 132
       ?)
130 133
          usage
131 134
          exit
... ...
@@ -443,7 +447,7 @@ else
443 443
 
444 444
   renumber_system_disk "$vm_uuid"
445 445
 
446
-  nl=$(xe_min vm-list params=name-label uuid=$vm_uuid)
446
+  nl=${NAME_LABEL:-$(xe_min vm-list params=name-label uuid=$vm_uuid)}
447 447
   xe vm-param-set \
448 448
     "name-label=${nl/ import/}" \
449 449
     other-config:os-vpx=true \
... ...
@@ -1,8 +1,15 @@
1 1
 auto lo
2 2
 iface lo inet loopback
3 3
 
4
-auto eth0
5
-iface eth0 inet dhcp
4
+# If eth3 is static, the order should not matter
5
+# and eth0 will have the default gateway. If not,
6
+# we probably want the default gateway to be
7
+# what is on the public interface. Hence changed
8
+# the order here.
9
+auto eth3
10
+iface eth3 inet static
11
+        address @ETH3_IP@
12
+        netmask @ETH3_NETMASK@
6 13
 
7 14
 auto eth1
8 15
 iface eth1 inet static
... ...
@@ -15,7 +22,5 @@ iface eth2 inet static
15 15
         address @ETH2_IP@
16 16
         netmask @ETH2_NETMASK@
17 17
 
18
-auto eth3
19
-iface eth3 inet static
20
-        address @ETH3_IP@
21
-        netmask @ETH3_NETMASK@
18
+auto eth0
19
+iface eth0 inet dhcp
... ...
@@ -9,24 +9,31 @@ VDI_MB=${VDI_MB:-2500}
9 9
 # VM Password
10 10
 GUEST_PASSWORD=${GUEST_PASSWORD:-secrete}
11 11
 
12
-# Our nova host's network info 
12
+# Host Interface, i.e. the public facing interface on the nova vm
13
+HOST_IP_IFACE=${HOST_IP_IFACE:-eth0}
14
+
15
+# Our nova host's network info
13 16
 VM_IP=${VM_IP:-10.255.255.255} # A host-only ip that let's the interface come up, otherwise unused
14 17
 MGT_IP=${MGT_IP:-172.16.100.55}
15 18
 PUB_IP=${PUB_IP:-192.168.1.55}
16 19
 
17 20
 # Public network
18
-PUB_BR=${PUB_BR:-xenbr0}
21
+PUB_BR=${PUB_BR:-"xenbr0"}
22
+PUB_DEV=${PUB_DEV:-eth0}
23
+PUB_VLAN=${PUB_VLAN:--1}
19 24
 PUB_NETMASK=${PUB_NETMASK:-255.255.255.0}
20 25
 
21 26
 # VM network params
22 27
 VM_NETMASK=${VM_NETMASK:-255.255.255.0}
23
-VM_BR=${VM_BR:-xapi1}
28
+VM_BR=${VM_BR:-""}
24 29
 VM_VLAN=${VM_VLAN:-100}
30
+VM_DEV=${VM_DEV:-eth0}
25 31
 
26 32
 # MGMT network params
27 33
 MGT_NETMASK=${MGT_NETMASK:-255.255.255.0}
28
-MGT_BR=${MGT_BR:-xapi2}
34
+MGT_BR=${MGT_BR:-""}
29 35
 MGT_VLAN=${MGT_VLAN:-101}
36
+MGT_DEV=${MGT_DEV:-eth0}
30 37
 
31 38
 # XVA Directory
32 39
 XVA_DIR=${XVA_DIR:-xvas}