Browse code

Merge remote-tracking branch 'cloudbuilders/master'

Conflicts:
stack.sh

James E. Blair authored on 2011/10/22 01:07:23
Showing 8 changed files
... ...
@@ -7,11 +7,11 @@
7 7
 #
8 8
 
9 9
 
10
-# This script exits on an error so that errors don't compound and you see 
10
+# This script exits on an error so that errors don't compound and you see
11 11
 # only the first error that occured.
12 12
 set -o errexit
13 13
 
14
-# Print the commands being run so that we can see the command that triggers 
14
+# Print the commands being run so that we can see the command that triggers
15 15
 # an error.  It is also useful for following allowing as the install occurs.
16 16
 set -o xtrace
17 17
 
... ...
@@ -38,11 +38,11 @@ export NOVA_USERNAME=${USERNAME:-demo}
38 38
 # With Keystone you pass the keystone password instead of an api key.
39 39
 export NOVA_API_KEY=${ADMIN_PASSWORD:-secrete}
40 40
 
41
-# With the addition of Keystone, to use an openstack cloud you should 
42
-# authenticate against keystone, which returns a **Token** and **Service 
43
-# Catalog**.  The catalog contains the endpoint for all services the user/tenant 
44
-# has access to - including nova, glance, keystone, swift, ...  We currently 
45
-# recommend using the 2.0 *auth api*.  
41
+# With the addition of Keystone, to use an openstack cloud you should
42
+# authenticate against keystone, which returns a **Token** and **Service
43
+# Catalog**.  The catalog contains the endpoint for all services the user/tenant
44
+# has access to - including nova, glance, keystone, swift, ...  We currently
45
+# recommend using the 2.0 *auth api*.
46 46
 #
47 47
 # *NOTE*: Using the 2.0 *auth api* does mean that compute api is 2.0.  We will
48 48
 # use the 1.1 *compute api*
... ...
@@ -61,7 +61,7 @@ export NOVACLIENT_DEBUG=1
61 61
 # Get a token for clients that don't support service catalog
62 62
 # ==========================================================
63 63
 
64
-# manually create a token by querying keystone (sending JSON data).  Keystone 
64
+# manually create a token by querying keystone (sending JSON data).  Keystone
65 65
 # returns a token and catalog of endpoints.  We use python to parse the token
66 66
 # and save it.
67 67
 
... ...
@@ -120,11 +120,11 @@ IP=`nova show $NAME | grep "private network" | cut -d"|" -f3`
120 120
 # ping it once (timeout of a second)
121 121
 ping -c1 -w1 $IP || true
122 122
 
123
-# sometimes the first ping fails (10 seconds isn't enough time for the VM's 
123
+# sometimes the first ping fails (10 seconds isn't enough time for the VM's
124 124
 # network to respond?), so let's wait 5 seconds and really test ping
125 125
 sleep 5
126 126
 
127
-ping -c1 -w1 $IP 
127
+ping -c1 -w1 $IP
128 128
 # allow icmp traffic
129 129
 nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
130 130
 
... ...
@@ -167,5 +167,5 @@ nova delete $NAME
167 167
 # Delete a secgroup
168 168
 nova secgroup-delete $SECGROUP
169 169
 
170
-# FIXME: validate shutdown within 5 seconds 
170
+# FIXME: validate shutdown within 5 seconds
171 171
 # (nova show $NAME returns 1 or status != ACTIVE)?
... ...
@@ -37,7 +37,7 @@ $BIN_DIR/keystone-manage $* endpointTemplates add RegionOne keystone http://%HOS
37 37
 $BIN_DIR/keystone-manage $* token add %SERVICE_TOKEN% admin admin 2015-02-05T00:00
38 38
 
39 39
 # EC2 related creds - note we are setting the token to user_password
40
-# but keystone doesn't parse them - it is just a blob from keystone's 
40
+# but keystone doesn't parse them - it is just a blob from keystone's
41 41
 # point of view
42 42
 $BIN_DIR/keystone-manage $* credentials add admin EC2 'admin_%ADMIN_PASSWORD%' admin admin || echo "no support for adding credentials"
43 43
 $BIN_DIR/keystone-manage $* credentials add demo EC2 'demo_%ADMIN_PASSWORD%' demo demo || echo "no support for adding credentials"
... ...
@@ -4,7 +4,7 @@
4 4
 
5 5
 # This script installs and configures *nova*, *glance*, *dashboard* and *keystone*
6 6
 
7
-# This script allows you to specify configuration options of what git 
7
+# This script allows you to specify configuration options of what git
8 8
 # repositories to use, enabled services, network configuration and various
9 9
 # passwords.  If you are crafty you can run the script on multiple nodes using
10 10
 # shared settings for common resources (mysql, rabbitmq) and build a multi-node
... ...
@@ -65,11 +65,11 @@ fi
65 65
 # in most cases.
66 66
 #
67 67
 # We our settings from ``stackrc``.  This file is distributed with devstack and
68
-# contains locations for what repositories to use.  If you want to use other 
69
-# repositories and branches, you can add your own settings with another file 
68
+# contains locations for what repositories to use.  If you want to use other
69
+# repositories and branches, you can add your own settings with another file
70 70
 # called ``localrc``
71 71
 #
72
-# If ``localrc`` exists, then ``stackrc`` will load those settings.  This is 
72
+# If ``localrc`` exists, then ``stackrc`` will load those settings.  This is
73 73
 # useful for changing a branch or repostiory to test other versions.  Also you
74 74
 # can store your other settings like **MYSQL_PASSWORD** or **ADMIN_PASSWORD** instead
75 75
 # of letting devstack generate random ones for you.
... ...
@@ -91,8 +91,8 @@ if [[ $EUID -eq 0 ]]; then
91 91
 
92 92
     # since this script runs as a normal user, we need to give that user
93 93
     # ability to run sudo
94
-    apt-get update
95
-    apt-get install -y sudo
94
+    apt_get update
95
+    apt_get install sudo
96 96
 
97 97
     if ! getent passwd stack >/dev/null; then
98 98
         echo "Creating a user called stack"
... ...
@@ -144,6 +144,14 @@ if [ ! -n "$HOST_IP" ]; then
144 144
     HOST_IP=`LC_ALL=C /sbin/ifconfig  | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
145 145
 fi
146 146
 
147
+# apt-get wrapper to just get arguments set correctly
148
+function apt_get() {
149
+    local sudo="sudo"
150
+    [ "$(id -u)" = "0" ] && sudo=""
151
+    $sudo DEBIAN_FRONTEND=noninteractive apt-get \
152
+        --option "Dpkg::Options::=--force-confold" --assume-yes "$@"
153
+}
154
+
147 155
 # Generic helper to configure passwords
148 156
 function read_password {
149 157
     set +o xtrace
... ...
@@ -159,7 +167,7 @@ function read_password {
159 159
             touch $localrc
160 160
         fi
161 161
 
162
-        # Presumably if we got this far it can only be that our localrc is missing 
162
+        # Presumably if we got this far it can only be that our localrc is missing
163 163
         # the required password.  Prompt user for a password and write to localrc.
164 164
         echo ''
165 165
         echo '################################################################################'
... ...
@@ -184,7 +192,7 @@ function read_password {
184 184
 # Nova Network Configuration
185 185
 # --------------------------
186 186
 
187
-# FIXME: more documentation about why these are important flags.  Also 
187
+# FIXME: more documentation about why these are important flags.  Also
188 188
 # we should make sure we use the same variable names as the flag names.
189 189
 
190 190
 PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-eth0}
... ...
@@ -205,15 +213,15 @@ MULTI_HOST=${MULTI_HOST:-0}
205 205
 # variable but make sure that the interface doesn't already have an
206 206
 # ip or you risk breaking things.
207 207
 #
208
-# **DHCP Warning**:  If your flat interface device uses DHCP, there will be a 
209
-# hiccup while the network is moved from the flat interface to the flat network 
210
-# bridge.  This will happen when you launch your first instance.  Upon launch 
211
-# you will lose all connectivity to the node, and the vm launch will probably 
208
+# **DHCP Warning**:  If your flat interface device uses DHCP, there will be a
209
+# hiccup while the network is moved from the flat interface to the flat network
210
+# bridge.  This will happen when you launch your first instance.  Upon launch
211
+# you will lose all connectivity to the node, and the vm launch will probably
212 212
 # fail.
213
-# 
214
-# If you are running on a single node and don't need to access the VMs from 
213
+#
214
+# If you are running on a single node and don't need to access the VMs from
215 215
 # devices other than that node, you can set the flat interface to the same
216
-# value as ``FLAT_NETWORK_BRIDGE``.  This will stop the network hiccup from 
216
+# value as ``FLAT_NETWORK_BRIDGE``.  This will stop the network hiccup from
217 217
 # occuring.
218 218
 FLAT_INTERFACE=${FLAT_INTERFACE:-eth0}
219 219
 
... ...
@@ -223,11 +231,11 @@ FLAT_INTERFACE=${FLAT_INTERFACE:-eth0}
223 223
 # MySQL & RabbitMQ
224 224
 # ----------------
225 225
 
226
-# We configure Nova, Dashboard, Glance and Keystone to use MySQL as their 
226
+# We configure Nova, Dashboard, Glance and Keystone to use MySQL as their
227 227
 # database server.  While they share a single server, each has their own
228 228
 # database and tables.
229 229
 
230
-# By default this script will install and configure MySQL.  If you want to 
230
+# By default this script will install and configure MySQL.  If you want to
231 231
 # use an existing server, you can pass in the user/password/host parameters.
232 232
 # You will need to send the same ``MYSQL_PASSWORD`` to every host if you are doing
233 233
 # a multi-node devstack installation.
... ...
@@ -284,8 +292,8 @@ fi
284 284
 
285 285
 
286 286
 # install apt requirements
287
-sudo apt-get update
288
-sudo apt-get install -qqy `cat $FILES/apts/* | cut -d\# -f1 | grep -Ev "mysql-server|rabbitmq-server"`
287
+apt_get update
288
+apt_get install `cat $FILES/apts/* | cut -d\# -f1 | grep -Ev "mysql-server|rabbitmq-server"`
289 289
 
290 290
 # install python requirements
291 291
 sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install `cat $FILES/pips/*`
... ...
@@ -352,7 +360,11 @@ cp $FILES/screenrc ~/.screenrc
352 352
 
353 353
 if [[ "$ENABLED_SERVICES" =~ "rabbit" ]]; then
354 354
     # Install and start rabbitmq-server
355
-    sudo apt-get install -y -q rabbitmq-server
355
+    # the temp file is necessary due to LP: #878600
356
+    tfile=$(mktemp)
357
+    apt_get install rabbitmq-server > "$tfile" 2>&1
358
+    cat "$tfile"
359
+    rm -f "$tfile"
356 360
     # change the rabbit password since the default is "guest"
357 361
     sudo rabbitmqctl change_password guest $RABBIT_PASSWORD
358 362
 fi
... ...
@@ -384,7 +396,7 @@ EOF
384 384
     fi
385 385
 
386 386
     # Install and start mysql-server
387
-    sudo apt-get -y -q install mysql-server
387
+    apt_get install mysql-server
388 388
     # Update the DB to give user ‘$MYSQL_USER’@’%’ full control of the all databases:
389 389
     sudo mysql -uroot -p$MYSQL_PASSWORD -h127.0.0.1 -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' identified by '$MYSQL_PASSWORD';"
390 390
 
... ...
@@ -472,8 +484,8 @@ if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
472 472
     # attempt to load modules: network block device - used to manage qcow images
473 473
     sudo modprobe nbd || true
474 474
 
475
-    # Check for kvm (hardware based virtualization).  If unable to initialize 
476
-    # kvm, we drop back to the slower emulation mode (qemu).  Note: many systems 
475
+    # Check for kvm (hardware based virtualization).  If unable to initialize
476
+    # kvm, we drop back to the slower emulation mode (qemu).  Note: many systems
477 477
     # come with hardware virtualization disabled in BIOS.
478 478
     if [[ "$LIBVIRT_TYPE" == "kvm" ]]; then
479 479
         sudo modprobe kvm || true
... ...
@@ -487,7 +499,7 @@ if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
487 487
     # splitting a system into many smaller parts.  LXC uses cgroups and chroot
488 488
     # to simulate multiple systems.
489 489
     if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
490
-        sudo apt-get install lxc -y
490
+        apt_get install lxc
491 491
         # lxc uses cgroups (a kernel interface via virtual filesystem) configured
492 492
         # and mounted to ``/cgroup``
493 493
         sudo mkdir -p /cgroup
... ...
@@ -502,7 +514,7 @@ if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
502 502
     # The user that nova runs as needs to be member of libvirtd group otherwise
503 503
     # nova-compute will be unable to use libvirt.
504 504
     sudo usermod -a -G libvirtd `whoami`
505
-    # libvirt detects various settings on startup, as we potentially changed 
505
+    # libvirt detects various settings on startup, as we potentially changed
506 506
     # the system configuration (modules, filesystems), we need to restart
507 507
     # libvirt to detect those changes.
508 508
     sudo /etc/init.d/libvirt-bin restart
... ...
@@ -515,7 +527,7 @@ if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
515 515
     mkdir -p $NOVA_DIR/instances
516 516
 
517 517
     # You can specify a different disk to be mounted and used for backing the
518
-    # virtual machines.  If there is a partition labeled nova-instances we 
518
+    # virtual machines.  If there is a partition labeled nova-instances we
519 519
     # mount it (ext filesystems can be labeled via e2label).
520 520
     if [ -L /dev/disk/by-label/nova-instances ]; then
521 521
         if ! mount -n | grep -q nova-instances; then
... ...
@@ -52,13 +52,13 @@ BASE_IMAGE=$KVMSTACK_DIR/images/natty.raw
52 52
 BASE_IMAGE_COPY=$IMAGES_DIR/$DIST_NAME.raw.copy
53 53
 
54 54
 # Name of our instance, used by libvirt
55
-VM_NAME=${VM_NAME:-kvmstack}
55
+CONTAINER_NAME=${CONTAINER_NAME:-kvmstack}
56 56
 
57 57
 # Mop up after previous runs
58
-virsh destroy $VM_NAME
58
+virsh destroy $CONTAINER_NAME
59 59
 
60 60
 # Where this vm is stored
61
-VM_DIR=$KVMSTACK_DIR/instances/$VM_NAME
61
+VM_DIR=$KVMSTACK_DIR/instances/$CONTAINER_NAME
62 62
 
63 63
 # Create vm dir
64 64
 mkdir -p $VM_DIR
... ...
@@ -148,18 +148,11 @@ git_clone $OPENSTACKX_REPO $COPY_DIR/$DEST/openstackx $OPENSTACKX_BRANCH
148 148
 git_clone $KEYSTONE_REPO $COPY_DIR/$DEST/keystone $KEYSTONE_BRANCH
149 149
 git_clone $NOVNC_REPO $COPY_DIR/$DEST/noVNC $NOVNC_BRANCH
150 150
 
151
-# Back to devstack
152
-cd $TOP_DIR
153
-
154 151
 # Unmount the filesystems
155 152
 unmount_images
156 153
 
157
-# Clean up old runs
158
-cd $VM_DIR
159
-rm -f $VM_DIR/disk
160
-
161
-# Clean up old instance data
162
-qemu-img create -f qcow2 -b $BASE_IMAGE_COPY disk
154
+# Back to devstack
155
+cd $TOP_DIR
163 156
 
164 157
 # Network configuration variables
165 158
 BRIDGE=${BRIDGE:-br0}
... ...
@@ -168,14 +161,16 @@ CONTAINER_IP=${CONTAINER_IP:-192.168.1.50}
168 168
 CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24}
169 169
 CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0}
170 170
 CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1}
171
-CONTAINER_MAC=${CONTAINER_MAC:-02:16:3e:07:70:d7}
171
+CONTAINER_MAC=${CONTAINER_MAC:-"02:16:3e:07:69:`printf '%02X' $(echo $CONTAINER_IP | sed "s/.*\.//")`"}
172
+CONTAINER_RAM=${CONTAINER_RAM:-1524288}
173
+CONTAINER_CORES=${CONTAINER_CORES:-1}
172 174
 
173 175
 # libvirt.xml configuration
174 176
 LIBVIRT_XML=libvirt.xml
175 177
 cat > $LIBVIRT_XML <<EOF
176 178
 <domain type='kvm'>
177
-    <name>$VM_NAME</name>
178
-    <memory>1524288</memory>
179
+    <name>$CONTAINER_NAME</name>
180
+    <memory>$CONTAINER_RAM</memory>
179 181
     <os>
180 182
         <type>hvm</type>
181 183
         <bootmenu enable='yes'/>
... ...
@@ -183,7 +178,7 @@ cat > $LIBVIRT_XML <<EOF
183 183
     <features>
184 184
         <acpi/>
185 185
     </features>
186
-    <vcpu>1</vcpu>
186
+    <vcpu>$CONTAINER_CORES</vcpu>
187 187
     <devices>
188 188
         <disk type='file'>
189 189
             <driver type='qcow2'/>
... ...
@@ -231,8 +226,20 @@ NBD=${NBD:-/dev/nbd5}
231 231
 umount $ROOTFS || echo 'ok'
232 232
 qemu-nbd -d $NBD || echo 'ok'
233 233
 
234
-# Mount the instance
234
+# Clean up old runs
235
+cd $VM_DIR
236
+rm -f $VM_DIR/disk
237
+
238
+# Create our instance fs
239
+qemu-img create -f qcow2 -b $BASE_IMAGE_COPY disk
240
+
241
+sleep 5
242
+
235 243
 qemu-nbd -c $NBD disk
244
+
245
+sleep 5
246
+
247
+# Mount the instance
236 248
 mount $NBD $ROOTFS -o offset=32256 -t ext4
237 249
 
238 250
 # Configure instance network
... ...
@@ -355,7 +362,7 @@ if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
355 355
         kill $TAIL_PID
356 356
         exit 1
357 357
     }
358
- 
358
+
359 359
     # Let Ctrl-c kill tail and exit
360 360
     trap kill_tail SIGINT
361 361
 
... ...
@@ -290,7 +290,7 @@ if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
290 290
         kill $TAIL_PID
291 291
         exit 1
292 292
     }
293
- 
293
+
294 294
     # Let Ctrl-c kill tail and exit
295 295
     trap kill_tail SIGINT
296 296
 
... ...
@@ -22,7 +22,7 @@ rm -rf $DEST
22 22
 # clean install of natty
23 23
 if [ ! -d $CHROOTCACHE/natty-base ]; then
24 24
     $PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base
25
-    # copy kernel modules...  
25
+    # copy kernel modules...
26 26
     # NOTE(ja): is there a better way to do this?
27 27
     cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
28 28
     # a simple password - pass
... ...
@@ -35,7 +35,7 @@ if [ ! -d $CHROOTCACHE/natty-dev ]; then
35 35
     chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
36 36
     chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*`
37 37
 
38
-    # Create a stack user that is a member of the libvirtd group so that stack 
38
+    # Create a stack user that is a member of the libvirtd group so that stack
39 39
     # is able to interact with libvirt.
40 40
     chroot $CHROOTCACHE/natty-dev groupadd libvirtd
41 41
     chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d $DEST -G libvirtd
... ...
@@ -45,7 +45,7 @@ if [ ! -d $CHROOTCACHE/natty-dev ]; then
45 45
     # a simple password - pass
46 46
     echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd
47 47
 
48
-    # and has sudo ability (in the future this should be limited to only what 
48
+    # and has sudo ability (in the future this should be limited to only what
49 49
     # stack requires)
50 50
     echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers
51 51
 fi
... ...
@@ -20,7 +20,7 @@ PROGDIR=`dirname $0`
20 20
 mkdir -p $DEST_DIR/pxelinux.cfg
21 21
 cd $DEST_DIR
22 22
 for i in memdisk menu.c32 pxelinux.0; do
23
-	cp -p /usr/lib/syslinux/$i $DEST_DIR
23
+    cp -p /usr/lib/syslinux/$i $DEST_DIR
24 24
 done
25 25
 
26 26
 CFG=$DEST_DIR/pxelinux.cfg/default
... ...
@@ -27,7 +27,7 @@ USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
27 27
 # clean install of natty
28 28
 if [ ! -d $CHROOTCACHE/natty-base ]; then
29 29
     $PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base
30
-    # copy kernel modules...  
30
+    # copy kernel modules...
31 31
     # NOTE(ja): is there a better way to do this?
32 32
     cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
33 33
     # a simple password - pass
... ...
@@ -40,7 +40,7 @@ if [ ! -d $CHROOTCACHE/natty-dev ]; then
40 40
     chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
41 41
     chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*`
42 42
 
43
-    # Create a stack user that is a member of the libvirtd group so that stack 
43
+    # Create a stack user that is a member of the libvirtd group so that stack
44 44
     # is able to interact with libvirt.
45 45
     chroot $CHROOTCACHE/natty-dev groupadd libvirtd
46 46
     chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d $DEST -G libvirtd
... ...
@@ -50,7 +50,7 @@ if [ ! -d $CHROOTCACHE/natty-dev ]; then
50 50
     # a simple password - pass
51 51
     echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd
52 52
 
53
-    # and has sudo ability (in the future this should be limited to only what 
53
+    # and has sudo ability (in the future this should be limited to only what
54 54
     # stack requires)
55 55
     echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers
56 56
 fi