Browse code

Merge remote-tracking branch 'origin/master' into openrc

Conflicts:
exercise.sh

Anthony Young authored on 2011/10/21 03:37:53
Showing 9 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
 
... ...
@@ -25,7 +25,7 @@ source ./openrc
25 25
 # Get a token for clients that don't support service catalog
26 26
 # ==========================================================
27 27
 
28
-# manually create a token by querying keystone (sending JSON data).  Keystone 
28
+# manually create a token by querying keystone (sending JSON data).  Keystone
29 29
 # returns a token and catalog of endpoints.  We use python to parse the token
30 30
 # and save it.
31 31
 
... ...
@@ -84,11 +84,11 @@ IP=`nova show $NAME | grep "private network" | cut -d"|" -f3`
84 84
 # ping it once (timeout of a second)
85 85
 ping -c1 -w1 $IP || true
86 86
 
87
-# sometimes the first ping fails (10 seconds isn't enough time for the VM's 
87
+# sometimes the first ping fails (10 seconds isn't enough time for the VM's
88 88
 # network to respond?), so let's wait 5 seconds and really test ping
89 89
 sleep 5
90 90
 
91
-ping -c1 -w1 $IP 
91
+ping -c1 -w1 $IP
92 92
 # allow icmp traffic
93 93
 nova secgroup-add-rule $SECGROUP icmp -1 -1 0.0.0.0/0
94 94
 
... ...
@@ -131,5 +131,5 @@ nova delete $NAME
131 131
 # Delete a secgroup
132 132
 nova secgroup-delete $SECGROUP
133 133
 
134
-# FIXME: validate shutdown within 5 seconds 
134
+# FIXME: validate shutdown within 5 seconds
135 135
 # (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"
... ...
@@ -20,11 +20,11 @@ export NOVA_USERNAME=${USERNAME:-demo}
20 20
 # With Keystone you pass the keystone password instead of an api key.
21 21
 export NOVA_API_KEY=${ADMIN_PASSWORD:-secrete}
22 22
 
23
-# With the addition of Keystone, to use an openstack cloud you should 
24
-# authenticate against keystone, which returns a **Token** and **Service 
25
-# Catalog**.  The catalog contains the endpoint for all services the user/tenant 
26
-# has access to - including nova, glance, keystone, swift, ...  We currently 
27
-# recommend using the 2.0 *auth api*.  
23
+# With the addition of Keystone, to use an openstack cloud you should
24
+# authenticate against keystone, which returns a **Token** and **Service
25
+# Catalog**.  The catalog contains the endpoint for all services the user/tenant
26
+# has access to - including nova, glance, keystone, swift, ...  We currently
27
+# recommend using the 2.0 *auth api*.
28 28
 #
29 29
 # *NOTE*: Using the 2.0 *auth api* does mean that compute api is 2.0.  We will
30 30
 # use the 1.1 *compute api*
... ...
@@ -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.
... ...
@@ -86,12 +86,12 @@ DEST=${DEST:-/opt/stack}
86 86
 if [[ $EUID -eq 0 ]]; then
87 87
     echo "You are running this script as root."
88 88
     echo "In 10 seconds, we will create a user 'stack' and run as that user"
89
-    sleep 10 
89
+    sleep 10
90 90
 
91 91
     # since this script runs as a normal user, we need to give that user
92 92
     # ability to run sudo
93
-    apt-get update
94
-    apt-get install -y sudo
93
+    apt_get update
94
+    apt_get install sudo
95 95
 
96 96
     if ! getent passwd stack >/dev/null; then
97 97
         echo "Creating a user called stack"
... ...
@@ -143,6 +143,14 @@ if [ ! -n "$HOST_IP" ]; then
143 143
     HOST_IP=`LC_ALL=C /sbin/ifconfig  | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
144 144
 fi
145 145
 
146
+# apt-get wrapper to just get arguments set correctly
147
+function apt_get() {
148
+    local sudo="sudo"
149
+    [ "$(id -u)" = "0" ] && sudo=""
150
+    $sudo DEBIAN_FRONTEND=noninteractive apt-get \
151
+        --option "Dpkg::Options::=--force-confold" --assume-yes "$@"
152
+}
153
+
146 154
 # Generic helper to configure passwords
147 155
 function read_password {
148 156
     set +o xtrace
... ...
@@ -158,7 +166,7 @@ function read_password {
158 158
             touch $localrc
159 159
         fi
160 160
 
161
-        # Presumably if we got this far it can only be that our localrc is missing 
161
+        # Presumably if we got this far it can only be that our localrc is missing
162 162
         # the required password.  Prompt user for a password and write to localrc.
163 163
         echo ''
164 164
         echo '################################################################################'
... ...
@@ -183,7 +191,7 @@ function read_password {
183 183
 # Nova Network Configuration
184 184
 # --------------------------
185 185
 
186
-# FIXME: more documentation about why these are important flags.  Also 
186
+# FIXME: more documentation about why these are important flags.  Also
187 187
 # we should make sure we use the same variable names as the flag names.
188 188
 
189 189
 PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-eth0}
... ...
@@ -204,15 +212,15 @@ MULTI_HOST=${MULTI_HOST:-0}
204 204
 # variable but make sure that the interface doesn't already have an
205 205
 # ip or you risk breaking things.
206 206
 #
207
-# **DHCP Warning**:  If your flat interface device uses DHCP, there will be a 
208
-# hiccup while the network is moved from the flat interface to the flat network 
209
-# bridge.  This will happen when you launch your first instance.  Upon launch 
210
-# you will lose all connectivity to the node, and the vm launch will probably 
207
+# **DHCP Warning**:  If your flat interface device uses DHCP, there will be a
208
+# hiccup while the network is moved from the flat interface to the flat network
209
+# bridge.  This will happen when you launch your first instance.  Upon launch
210
+# you will lose all connectivity to the node, and the vm launch will probably
211 211
 # fail.
212
-# 
213
-# If you are running on a single node and don't need to access the VMs from 
212
+#
213
+# If you are running on a single node and don't need to access the VMs from
214 214
 # devices other than that node, you can set the flat interface to the same
215
-# value as ``FLAT_NETWORK_BRIDGE``.  This will stop the network hiccup from 
215
+# value as ``FLAT_NETWORK_BRIDGE``.  This will stop the network hiccup from
216 216
 # occuring.
217 217
 FLAT_INTERFACE=${FLAT_INTERFACE:-eth0}
218 218
 
... ...
@@ -222,11 +230,11 @@ FLAT_INTERFACE=${FLAT_INTERFACE:-eth0}
222 222
 # MySQL & RabbitMQ
223 223
 # ----------------
224 224
 
225
-# We configure Nova, Dashboard, Glance and Keystone to use MySQL as their 
225
+# We configure Nova, Dashboard, Glance and Keystone to use MySQL as their
226 226
 # database server.  While they share a single server, each has their own
227 227
 # database and tables.
228 228
 
229
-# By default this script will install and configure MySQL.  If you want to 
229
+# By default this script will install and configure MySQL.  If you want to
230 230
 # use an existing server, you can pass in the user/password/host parameters.
231 231
 # You will need to send the same ``MYSQL_PASSWORD`` to every host if you are doing
232 232
 # a multi-node devstack installation.
... ...
@@ -283,8 +291,8 @@ fi
283 283
 
284 284
 
285 285
 # install apt requirements
286
-sudo apt-get update
287
-sudo apt-get install -qqy `cat $FILES/apts/* | cut -d\# -f1 | grep -Ev "mysql-server|rabbitmq-server"`
286
+apt_get update
287
+apt_get install `cat $FILES/apts/* | cut -d\# -f1 | grep -Ev "mysql-server|rabbitmq-server"`
288 288
 
289 289
 # install python requirements
290 290
 sudo PIP_DOWNLOAD_CACHE=/var/cache/pip pip install `cat $FILES/pips/*`
... ...
@@ -351,7 +359,11 @@ cp $FILES/screenrc ~/.screenrc
351 351
 
352 352
 if [[ "$ENABLED_SERVICES" =~ "rabbit" ]]; then
353 353
     # Install and start rabbitmq-server
354
-    sudo apt-get install -y -q rabbitmq-server
354
+    # the temp file is necessary due to LP: #878600
355
+    tfile=$(mktemp)
356
+    apt_get install rabbitmq-server > "$tfile" 2>&1
357
+    cat "$tfile"
358
+    rm -f "$tfile"
355 359
     # change the rabbit password since the default is "guest"
356 360
     sudo rabbitmqctl change_password guest $RABBIT_PASSWORD
357 361
 fi
... ...
@@ -383,7 +395,7 @@ EOF
383 383
     fi
384 384
 
385 385
     # Install and start mysql-server
386
-    sudo apt-get -y -q install mysql-server
386
+    apt_get install mysql-server
387 387
     # Update the DB to give user ‘$MYSQL_USER’@’%’ full control of the all databases:
388 388
     sudo mysql -uroot -p$MYSQL_PASSWORD -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' identified by '$MYSQL_PASSWORD';"
389 389
 
... ...
@@ -471,8 +483,8 @@ if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
471 471
     # attempt to load modules: network block device - used to manage qcow images
472 472
     sudo modprobe nbd || true
473 473
 
474
-    # Check for kvm (hardware based virtualization).  If unable to initialize 
475
-    # kvm, we drop back to the slower emulation mode (qemu).  Note: many systems 
474
+    # Check for kvm (hardware based virtualization).  If unable to initialize
475
+    # kvm, we drop back to the slower emulation mode (qemu).  Note: many systems
476 476
     # come with hardware virtualization disabled in BIOS.
477 477
     if [[ "$LIBVIRT_TYPE" == "kvm" ]]; then
478 478
         sudo modprobe kvm || true
... ...
@@ -486,7 +498,7 @@ if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
486 486
     # splitting a system into many smaller parts.  LXC uses cgroups and chroot
487 487
     # to simulate multiple systems.
488 488
     if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
489
-        sudo apt-get install lxc -y
489
+        apt_get install lxc
490 490
         # lxc uses cgroups (a kernel interface via virtual filesystem) configured
491 491
         # and mounted to ``/cgroup``
492 492
         sudo mkdir -p /cgroup
... ...
@@ -501,7 +513,7 @@ if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
501 501
     # The user that nova runs as needs to be member of libvirtd group otherwise
502 502
     # nova-compute will be unable to use libvirt.
503 503
     sudo usermod -a -G libvirtd `whoami`
504
-    # libvirt detects various settings on startup, as we potentially changed 
504
+    # libvirt detects various settings on startup, as we potentially changed
505 505
     # the system configuration (modules, filesystems), we need to restart
506 506
     # libvirt to detect those changes.
507 507
     sudo /etc/init.d/libvirt-bin restart
... ...
@@ -514,7 +526,7 @@ if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
514 514
     mkdir -p $NOVA_DIR/instances
515 515
 
516 516
     # You can specify a different disk to be mounted and used for backing the
517
-    # virtual machines.  If there is a partition labeled nova-instances we 
517
+    # virtual machines.  If there is a partition labeled nova-instances we
518 518
     # mount it (ext filesystems can be labeled via e2label).
519 519
     if [ -L /dev/disk/by-label/nova-instances ]; then
520 520
         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
... ...
@@ -168,13 +168,13 @@ 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 172
 
173 173
 # libvirt.xml configuration
174 174
 LIBVIRT_XML=libvirt.xml
175 175
 cat > $LIBVIRT_XML <<EOF
176 176
 <domain type='kvm'>
177
-    <name>$VM_NAME</name>
177
+    <name>$CONTAINER_NAME</name>
178 178
     <memory>1524288</memory>
179 179
     <os>
180 180
         <type>hvm</type>
... ...
@@ -355,7 +355,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