Browse code

Merge remote-tracking branch 'upstream/master' into 4-run.sh

Dean Troyer authored on 2011/10/18 02:22:01
Showing 13 changed files
1 1
deleted file mode 100644
... ...
@@ -1,42 +0,0 @@
1
-Tool to quickly deploy openstack dev environments.
2
-
3
-# Goals
4
-
5
-* To quickly build dev openstack environments in clean natty environments
6
-* To describe working configurations of openstack (which code branches work together?  what do config files look like for those branches?)
7
-* To make it easier for developers to dive into openstack so that they can productively contribute without having to understand every part of the system at once
8
-* To make it easy to prototype cross-project features
9
-
10
-Be sure to carefully read these scripts before you run them as they install software and may alter your networking configuration.
11
-
12
-# To start a dev cloud on your local machine (installing on a dedicated vm is safer!):
13
-
14
-    ./stack.sh
15
-
16
-If working correctly, you should be able to access openstack endpoints, like:
17
-
18
-* Dashboard: http://myhost/
19
-* Keystone: http://myhost:5000/v2.0/
20
-
21
-# To start a dev cloud in an lxc container:
22
-
23
-    ./build_lxc.sh
24
-
25
-You will need to configure a bridge and network on your host machine (by default br0) before starting build_lxc.sh.  A sample host-only network configuration can be found in lxc_network_hostonlyplusnat.sh.
26
-
27
-# Customizing
28
-
29
-You can tweak environment variables by creating file name 'localrc' should you need to override defaults.  It is likely that you will need to do this to tweak your networking configuration should you need to access your cloud from a different host.
30
-
31
-# Todo
32
-
33
-* Add python-novaclient cli support
34
-* syslog
35
-* allow rabbit connection to be specified via environment variables with sensible defaults
36
-* Add volume support
37
-* Add quantum support
38
-
39
-# Future
40
-
41
-* idea: move from screen to tmux?
42
-* idea: create a live-cd / vmware preview image using this?
43 1
new file mode 100644
... ...
@@ -0,0 +1,43 @@
0
+Tool to quickly deploy openstack dev environments.
1
+
2
+# Goals
3
+
4
+* To quickly build dev openstack environments in clean natty environments
5
+* To describe working configurations of openstack (which code branches work together?  what do config files look like for those branches?)
6
+* To make it easier for developers to dive into openstack so that they can productively contribute without having to understand every part of the system at once
7
+* To make it easy to prototype cross-project features
8
+
9
+Read more at http://devstack.org (built from the gh-pages branch)
10
+
11
+Be sure to carefully read these scripts before you run them as they install software and may alter your networking configuration.
12
+
13
+# To start a dev cloud on your local machine (installing on a dedicated vm is safer!):
14
+
15
+    ./stack.sh
16
+
17
+If working correctly, you should be able to access openstack endpoints, like:
18
+
19
+* Dashboard: http://myhost/
20
+* Keystone: http://myhost:5000/v2.0/
21
+
22
+# To start a dev cloud in an lxc container:
23
+
24
+    ./build_lxc.sh
25
+
26
+You will need to configure a bridge and network on your host machine (by default br0) before starting build_lxc.sh.  A sample host-only network configuration can be found in lxc_network_hostonlyplusnat.sh.
27
+
28
+# Customizing
29
+
30
+You can tweak environment variables by creating file name 'localrc' should you need to override defaults.  It is likely that you will need to do this to tweak your networking configuration should you need to access your cloud from a different host.
31
+
32
+# Todo
33
+
34
+* Add python-novaclient cli support
35
+* syslog
36
+* Add volume support
37
+* Add quantum support
38
+
39
+# Future
40
+
41
+* idea: move from screen to tmux?
42
+* idea: create a live-cd / vmware preview image using this?
0 43
deleted file mode 100755
... ...
@@ -1,251 +0,0 @@
1
-#!/usr/bin/env bash
2
-
3
-# Sanity check
4
-if [ "$EUID" -ne "0" ]; then
5
-  echo "This script must be run with root privileges."
6
-  exit 1
7
-fi
8
-
9
-# Warn users who aren't on natty
10
-if ! grep -q natty /etc/lsb-release; then
11
-    echo "WARNING: this script has only been tested on natty"
12
-fi
13
-
14
-# Source params
15
-source ./stackrc
16
-
17
-# Store cwd
18
-CWD=`pwd`
19
-
20
-# Configurable params
21
-BRIDGE=${BRIDGE:-br0}
22
-CONTAINER=${CONTAINER:-STACK}
23
-CONTAINER_IP=${CONTAINER_IP:-192.168.1.50}
24
-CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24}
25
-CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0}
26
-CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1}
27
-NAMESERVER=${NAMESERVER:-$CONTAINER_GATEWAY}
28
-COPYENV=${COPYENV:-1}
29
-DEST=${DEST:-/opt/stack}
30
-
31
-# Param string to pass to stack.sh.  Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
32
-STACKSH_PARAMS=${STACKSH_PARAMS:-}
33
-
34
-# Option to use the version of devstack on which we are currently working
35
-USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
36
-
37
-
38
-# Install deps
39
-apt-get install -y lxc debootstrap
40
-
41
-# Install cgroup-bin from source, since the packaging is buggy and possibly incompatible with our setup
42
-if ! which cgdelete | grep -q cgdelete; then
43
-    apt-get install -y g++ bison flex libpam0g-dev make
44
-    wget http://sourceforge.net/projects/libcg/files/libcgroup/v0.37.1/libcgroup-0.37.1.tar.bz2/download -O /tmp/libcgroup-0.37.1.tar.bz2
45
-    cd /tmp && bunzip2 libcgroup-0.37.1.tar.bz2  && tar xfv libcgroup-0.37.1.tar
46
-    cd libcgroup-0.37.1
47
-    ./configure
48
-    make install
49
-    ldconfig
50
-fi
51
-
52
-# Create lxc configuration
53
-LXC_CONF=/tmp/$CONTAINER.conf
54
-cat > $LXC_CONF <<EOF
55
-lxc.network.type = veth
56
-lxc.network.link = $BRIDGE
57
-lxc.network.flags = up
58
-lxc.network.ipv4 = $CONTAINER_CIDR
59
-# allow tap/tun devices
60
-lxc.cgroup.devices.allow = c 10:200 rwm
61
-EOF
62
-
63
-# Shutdown any existing container
64
-lxc-stop -n $CONTAINER
65
-
66
-# This kills zombie containers
67
-if [ -d /cgroup/$CONTAINER ]; then
68
-    cgdelete -r cpu,net_cls:$CONTAINER
69
-fi
70
-
71
-# git clone only if directory doesn't exist already.  Since ``DEST`` might not
72
-# be owned by the installation user, we create the directory and change the
73
-# ownership to the proper user.
74
-function git_clone {
75
-    if [ ! -d $2 ]; then
76
-        sudo mkdir $2
77
-        sudo chown `whoami` $2
78
-        git clone $1 $2
79
-        cd $2
80
-        # This checkout syntax works for both branches and tags
81
-        git checkout $3
82
-    fi
83
-}
84
-
85
-# Location of the base image directory
86
-CACHEDIR=/var/cache/lxc/natty/rootfs-amd64
87
-
88
-# Provide option to do totally clean install
89
-if [ "$CLEAR_LXC_CACHE" = "1" ]; then
90
-    rm -rf $CACHEDIR
91
-fi
92
-
93
-# Warm the base image on first install
94
-if [ ! -f $CACHEDIR/bootstrapped ]; then
95
-    # by deleting the container, we force lxc-create to re-bootstrap (lxc is
96
-    # lazy and doesn't do anything if a container already exists)
97
-    lxc-destroy -n $CONTAINER
98
-    # trigger the initial debootstrap
99
-    lxc-create -n $CONTAINER -t natty -f $LXC_CONF
100
-    chroot $CACHEDIR apt-get update
101
-    chroot $CACHEDIR apt-get install -y --force-yes `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
102
-    chroot $CACHEDIR pip install `cat files/pips/*`
103
-    touch $CACHEDIR/bootstrapped
104
-fi
105
-
106
-# Clean out code repos if directed to do so
107
-if [ "$CLEAN" = "1" ]; then
108
-    rm -rf $CACHEDIR/$DEST
109
-fi
110
-
111
-# Cache openstack code
112
-mkdir -p $CACHEDIR/$DEST
113
-git_clone $NOVA_REPO $CACHEDIR/$DEST/nova $NOVA_BRANCH
114
-git_clone $GLANCE_REPO $CACHEDIR/$DEST/glance $GLANCE_BRANCH
115
-git_clone $KEYSTONE_REPO $CACHEDIR/$DESTkeystone $KEYSTONE_BRANCH
116
-git_clone $NOVNC_REPO $CACHEDIR/$DEST/novnc $NOVNC_BRANCH
117
-git_clone $DASH_REPO $CACHEDIR/$DEST/dash $DASH_BRANCH $DASH_TAG
118
-git_clone $NOVACLIENT_REPO $CACHEDIR/$DEST/python-novaclient $NOVACLIENT_BRANCH
119
-git_clone $OPENSTACKX_REPO $CACHEDIR/$DEST/openstackx $OPENSTACKX_BRANCH
120
-
121
-# Use this version of devstack?
122
-if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then
123
-    rm -rf $CACHEDIR/$DEST/devstack
124
-    cp -pr $CWD $CACHEDIR/$DEST/devstack
125
-fi
126
-
127
-# Destroy the old container
128
-lxc-destroy -n $CONTAINER
129
-
130
-# If this call is to TERMINATE the container then exit
131
-if [ "$TERMINATE" = "1" ]; then
132
-    exit
133
-fi
134
-
135
-# Create the container
136
-lxc-create -n $CONTAINER -t natty -f $LXC_CONF
137
-
138
-# Specify where our container rootfs lives
139
-ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/
140
-
141
-# Create a stack user that is a member of the libvirtd group so that stack
142
-# is able to interact with libvirt.
143
-chroot $ROOTFS groupadd libvirtd
144
-chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd
145
-
146
-# a simple password - pass
147
-echo stack:pass | chroot $ROOTFS chpasswd
148
-
149
-# and has sudo ability (in the future this should be limited to only what
150
-# stack requires)
151
-echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers
152
-
153
-# Copy kernel modules
154
-mkdir -p $ROOTFS/lib/modules/`uname -r`/kernel
155
-cp -p /lib/modules/`uname -r`/modules.dep $ROOTFS/lib/modules/`uname -r`/
156
-cp -pR /lib/modules/`uname -r`/kernel/net $ROOTFS/lib/modules/`uname -r`/kernel/
157
-
158
-# Gracefully cp only if source file/dir exists
159
-function 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
166
-if [ "$COPYENV" = "1" ]; then
167
-    cp_it ~/.ssh $ROOTFS/$DEST/.ssh
168
-    cp_it ~/.ssh/id_rsa.pub $ROOTFS/$DEST/.ssh/authorized_keys
169
-    cp_it ~/.gitconfig $ROOTFS/$DEST/.gitconfig
170
-    cp_it ~/.vimrc $ROOTFS/$DEST/.vimrc
171
-    cp_it ~/.bashrc $ROOTFS/$DEST/.bashrc
172
-fi
173
-
174
-# Make our ip address hostnames look nice at the command prompt
175
-echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/$DEST/.bashrc
176
-echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile
177
-
178
-# Give stack ownership over $DEST so it may do the work needed
179
-chroot $ROOTFS chown -R stack $DEST
180
-
181
-# Configure instance network
182
-INTERFACES=$ROOTFS/etc/network/interfaces
183
-cat > $INTERFACES <<EOF
184
-auto lo
185
-iface lo inet loopback
186
-
187
-auto eth0
188
-iface eth0 inet static
189
-        address $CONTAINER_IP
190
-        netmask $CONTAINER_NETMASK
191
-        gateway $CONTAINER_GATEWAY
192
-EOF
193
-
194
-# Configure the runner
195
-RUN_SH=$ROOTFS/$DEST/run.sh
196
-cat > $RUN_SH <<EOF
197
-#!/usr/bin/env bash
198
-# Make sure dns is set up
199
-echo "nameserver $NAMESERVER" | sudo resolvconf -a eth0
200
-sleep 1
201
-
202
-# Kill any existing screens
203
-killall screen
204
-
205
-# Install and run stack.sh
206
-sudo apt-get update
207
-sudo apt-get -y --force-yes install git-core vim-nox sudo
208
-if [ ! -d "$DEST/devstack" ]; then
209
-    git clone git://github.com/cloudbuilders/devstack.git $DEST/devstack
210
-fi
211
-cd $DEST/devstack && $STACKSH_PARAMS ./stack.sh > /$DEST/run.sh.log
212
-echo >> /$DEST/run.sh.log
213
-echo >> /$DEST/run.sh.log
214
-echo "All done! Time to start clicking." >> /$DEST/run.sh.log
215
-EOF
216
-
217
-# Make the run.sh executable
218
-chmod 755 $RUN_SH
219
-
220
-# Make runner launch on boot
221
-RC_LOCAL=$ROOTFS/etc/rc.local
222
-cat > $RC_LOCAL <<EOF
223
-#!/bin/sh -e
224
-su -c "$DEST/run.sh" stack
225
-EOF
226
-
227
-# Configure cgroup directory
228
-if ! mount | grep -q cgroup; then
229
-    mkdir -p /cgroup
230
-    mount none -t cgroup /cgroup
231
-fi
232
-
233
-# Start our container
234
-lxc-start -d -n $CONTAINER
235
-
236
-# Done creating the container, let's tail the log
237
-echo
238
-echo "============================================================="
239
-echo "                          -- YAY! --"
240
-echo "============================================================="
241
-echo
242
-echo "We're done creating the container, about to start tailing the"
243
-echo "stack.sh log. It will take a second or two to start."
244
-echo
245
-echo "Just CTRL-C at any time to stop tailing."
246
-
247
-while [ ! -e "$ROOTFS/$DEST/run.sh.log" ]; do
248
-  sleep 1
249
-done
250
-
251
-tail -F $ROOTFS/$DEST/run.sh.log
252 1
deleted file mode 100755
... ...
@@ -1,39 +0,0 @@
1
-#!/usr/bin/env bash
2
-# Head node host, which runs glance, api, keystone
3
-HEAD_HOST=${HEAD_HOST:-192.168.1.52}
4
-COMPUTE_HOSTS=${COMPUTE_HOSTS:-192.168.1.53,192.168.1.54}
5
-
6
-# Networking params
7
-NAMESERVER=${NAMESERVER:-192.168.1.1}
8
-GATEWAY=${GATEWAY:-192.168.1.1}
9
-NETMASK=${NETMASK:-255.255.255.0}
10
-FLOATING_RANGE=${FLOATING_RANGE:-192.168.1.196/30}
11
-
12
-# Setting this to 1 shuts down and destroys our containers without relaunching.
13
-TERMINATE=${TERMINATE:-0}
14
-
15
-# Variables common amongst all hosts in the cluster
16
-COMMON_VARS="MYSQL_HOST=$HEAD_HOST RABBIT_HOST=$HEAD_HOST GLANCE_HOSTPORT=$HEAD_HOST:9292 NET_MAN=FlatDHCPManager FLAT_INTERFACE=eth0 FLOATING_RANGE=$FLOATING_RANGE MULTI_HOST=1"
17
-
18
-# Helper to launch containers
19
-function run_lxc {
20
-    # For some reason container names with periods can cause issues :/
21
-    CONTAINER=$1 CONTAINER_IP=$2 CONTAINER_NETMASK=$NETMASK CONTAINER_GATEWAY=$GATEWAY NAMESERVER=$NAMESERVER TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $3" ./build_lxc.sh
22
-}
23
-
24
-# Launch the head node - headnode uses a non-ip domain name,
25
-# because rabbit won't launch with an ip addr hostname :(
26
-run_lxc STACKMASTER $HEAD_HOST "ENABLED_SERVICES=g-api,g-reg,key,n-api,n-sch,n-vnc,dash,mysql,rabbit"
27
-
28
-# Wait till the head node is up
29
-if [ ! "$TERMINATE" = "1" ]; then
30
-    while ! wget -q -O- http://$HEAD_HOST | grep -q username; do
31
-        echo "Waiting for head node ($HEAD_HOST) to start..."
32
-        sleep 5
33
-    done
34
-fi
35
-
36
-# Launch the compute hosts
37
-for compute_host in ${COMPUTE_HOSTS//,/ }; do
38
-    run_lxc $compute_host $compute_host "ENABLED_SERVICES=n-cpu,n-net,n-api"
39
-done
... ...
@@ -52,10 +52,17 @@ export NOVA_VERSION=1.1
52 52
 # FIXME - why does this need to be specified?
53 53
 export NOVA_REGION_NAME=RegionOne
54 54
 
55
+# set log level to DEBUG (helps debug issues)
56
+export NOVACLIENT_DEBUG=1
55 57
 
56 58
 # Get a token for clients that don't support service catalog
57 59
 # ==========================================================
58
-SERVICE_TOKEN=`curl -s -d  "{\"auth\":{\"passwordCredentials\": {\"username\": \"$NOVA_PROJECT_ID\", \"password\": \"$NOVA_API_KEY\"}}}" -H "Content-type: application/json" http://$HOST:5000/v2.0/tokens | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['access']['token']['id'];"`
60
+
61
+# manually create a token by querying keystone (sending JSON data).  Keystone 
62
+# returns a token and catalog of endpoints.  We use python to parse the token
63
+# and save it.
64
+
65
+TOKEN=`curl -s -d  "{\"auth\":{\"passwordCredentials\": {\"username\": \"$NOVA_USERNAME\", \"password\": \"$NOVA_API_KEY\"}}}" -H "Content-type: application/json" http://$HOST:5000/v2.0/tokens | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['access']['token']['id'];"`
59 66
 
60 67
 # Launching a server
61 68
 # ==================
... ...
@@ -63,9 +70,6 @@ SERVICE_TOKEN=`curl -s -d  "{\"auth\":{\"passwordCredentials\": {\"username\": \
63 63
 # List servers for tenant:
64 64
 nova list
65 65
 
66
-# List of flavors:
67
-nova flavor-list
68
-
69 66
 # Images
70 67
 # ------
71 68
 
... ...
@@ -73,10 +77,46 @@ nova flavor-list
73 73
 nova image-list
74 74
 
75 75
 # But we recommend using glance directly
76
-glance -A $SERVICE_TOKEN index
76
+glance -A $TOKEN index
77
+
78
+# Let's grab the id of the first AMI image to launch
79
+IMAGE=`glance -A $TOKEN index | egrep ami | cut -d" " -f1`
80
+
81
+
82
+# Flavors
83
+# -------
84
+
85
+# List of flavors:
86
+nova flavor-list
87
+
88
+# and grab the first flavor in the list to launch
89
+FLAVOR=`nova flavor-list | head -n 4 | tail -n 1 | cut -d"|" -f2`
90
+
91
+NAME="firstpost"
92
+
93
+nova boot --flavor $FLAVOR --image $IMAGE $NAME
94
+
95
+# let's give it 10 seconds to launch
96
+sleep 10
97
+
98
+# check that the status is active
99
+nova show $NAME | grep status | grep -q ACTIVE
100
+
101
+# get the IP of the server
102
+IP=`nova show $NAME | grep "private network" | cut -d"|" -f3`
103
+
104
+# ping it once (timeout of a second)
105
+ping -c1 -w1 $IP || true
106
+
107
+# sometimes the first ping fails (10 seconds isn't enough time for the VM's 
108
+# network to respond?), so let's wait 5 seconds and really test ping
109
+sleep 5
110
+
111
+ping -c1 -w1 $IP 
112
+
113
+# shutdown the server
114
+nova delete $NAME
115
+
116
+# FIXME: validate shutdown within 5 seconds 
117
+# (nova show $NAME returns 1 or status != ACTIVE)?
77 118
 
78
-# show details of the active servers::
79
-#
80
-#     nova show 1234
81
-#
82
-nova list | grep ACTIVE | cut -d \| -f2 | xargs -n1 nova show
83 119
deleted file mode 100755
... ...
@@ -1,93 +0,0 @@
1
-#!/bin/bash
2
-
3
-# Print some usage info
4
-function usage {
5
-  echo "Usage: $0 [OPTION] [host_ip]"
6
-  echo "Set up temporary networking for LXC"
7
-  echo ""
8
-  echo "  -n, --dry-run            Just print the commands that would execute."
9
-  echo "  -h, --help               Print this usage message."
10
-  echo ""
11
-  exit
12
-}
13
-
14
-# Allow passing the ip address on the command line.
15
-function process_option {
16
-  case "$1" in
17
-    -h|--help) usage;;
18
-    -n|--dry-run) dry_run=1;;
19
-    *) host_ip="$1"
20
-  esac
21
-}
22
-
23
-# Set up some defaults
24
-host_ip=
25
-dry_run=0
26
-bridge=br0
27
-DRIER=
28
-
29
-# Process the args
30
-for arg in "$@"; do
31
-  process_option $arg
32
-done
33
-
34
-if [ $dry_run ]; then
35
-  DRIER=echo
36
-fi
37
-
38
-if [ "$UID" -ne "0" ]; then
39
-  echo "This script must be run with root privileges."
40
-  exit 1
41
-fi
42
-
43
-# Check for bridge-utils.
44
-BRCTL=`which brctl`
45
-if [ ! -x "$BRCTL" ]; then
46
-  echo "This script requires you to install bridge-utils."
47
-  echo "Try: sudo apt-get install bridge-utils."
48
-  exit 1
49
-fi
50
-
51
-# Scare off the nubs.
52
-echo "====================================================="
53
-echo
54
-echo "WARNING"
55
-echo
56
-echo "This script will modify your current network setup,"
57
-echo "this can be a scary thing and it is recommended that"
58
-echo "you have something equivalent to physical access to"
59
-echo "this machine before continuing in case your network"
60
-echo "gets all funky."
61
-echo
62
-echo "If you don't want to continue, hit CTRL-C now."
63
-
64
-if [ -z "$host_ip" ];
65
-then
66
-  echo "Otherwise, please type in your host's ip address and"
67
-  echo "hit enter."
68
-  echo
69
-  echo "====================================================="
70
-  read host_ip
71
-else
72
-  echo "Otherwise hit enter."
73
-  echo
74
-  echo "====================================================="
75
-  read accept
76
-fi
77
-
78
-
79
-# Add a bridge interface, this will choke if there is already
80
-# a bridge named $bridge
81
-$DRIER $BRCTL addbr $bridge
82
-$DRIER ip addr add 192.168.1.1/24 dev $bridge
83
-if [ $dry_run ]; then
84
-  echo "echo 1 > /proc/sys/net/ipv4/ip_forward"
85
-else
86
-  echo 1 > /proc/sys/net/ipv4/ip_forward
87
-fi
88
-$DRIER ifconfig $bridge up
89
-
90
-# Set up the NAT for the instances
91
-$DRIER iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source $host_ip
92
-$DRIER iptables -I FORWARD -s 192.168.1.0/24 -j ACCEPT
93
-
... ...
@@ -20,9 +20,6 @@
20 20
 # Sanity Check
21 21
 # ============
22 22
 
23
-# Record the start time.  This allows us to print how long this script takes to run.
24
-START_TIME=`python -c "import time; print time.time()"`
25
-
26 23
 # Warn users who aren't on natty, but allow them to override check and attempt
27 24
 # installation with ``FORCE=yes ./stack``
28 25
 if ! grep -q natty /etc/lsb-release; then
... ...
@@ -43,6 +40,9 @@ if [ ! -d $FILES ]; then
43 43
     exit 1
44 44
 fi
45 45
 
46
+# Keep track of the current devstack directory.
47
+TOP_DIR=$(cd $(dirname "$0") && pwd)
48
+
46 49
 # OpenStack is designed to be run as a regular user (Dashboard will fail to run
47 50
 # as root, since apache refused to startup serve content from root user).  If
48 51
 # stack.sh is run as root, it automatically creates a stack user with
... ...
@@ -50,40 +50,38 @@ fi
50 50
 
51 51
 if [[ $EUID -eq 0 ]]; then
52 52
     echo "You are running this script as root."
53
+    echo "In 10 seconds, we will create a user 'stack' and run as that user"
54
+    sleep 10 
53 55
 
54 56
     # since this script runs as a normal user, we need to give that user
55 57
     # ability to run sudo
56 58
     apt-get update
57
-    apt-get install -qqy sudo
59
+    apt-get install -y sudo
58 60
 
59
-    if ! getent passwd | grep -q stack; then
61
+    if ! getent passwd stack >/dev/null; then
60 62
         echo "Creating a user called stack"
61 63
         useradd -U -G sudo -s /bin/bash -m stack
62 64
     fi
65
+
63 66
     echo "Giving stack user passwordless sudo priviledges"
64
-    echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
67
+    # natty uec images sudoers does not have a '#includedir'. add one.
68
+    grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||
69
+        echo "#includedir /etc/sudoers.d" >> /etc/sudoers
70
+    ( umask 226 && echo "stack ALL=(ALL) NOPASSWD:ALL" \
71
+        > /etc/sudoers.d/50_stack_sh )
65 72
 
66 73
     echo "Copying files to stack user"
67
-    cp -r -f `pwd` /home/stack/
68
-    THIS_DIR=$(basename $(dirname $(readlink -f $0)))
69
-    chown -R stack /home/stack/$THIS_DIR
70
-    echo "Running the script as stack in 3 seconds..."
71
-    sleep 3
74
+    STACK_DIR="/home/stack/${PWD##*/}"
75
+    cp -r -f "$PWD" "$STACK_DIR"
76
+    chown -R stack "$STACK_DIR"
72 77
     if [[ "$SHELL_AFTER_RUN" != "no" ]]; then
73
-	exec su -c "cd /home/stack/$THIS_DIR/; bash stack.sh; bash" stack
78
+        exec su -c "set -e; cd $STACK_DIR; bash stack.sh; bash" stack
74 79
     else
75
-	exec su -c "cd /home/stack/$THIS_DIR/; bash stack.sh" stack
80
+        exec su -c "set -e; cd $STACK_DIR; bash stack.sh" stack
76 81
     fi
77
-    exit 0
82
+    exit 1
78 83
 fi
79 84
 
80
-# So that errors don't compound we exit on any errors so you see only the
81
-# first error that occured.
82
-set -o errexit
83
-
84
-# Print the commands being run so that we can see the command that triggers
85
-# an error.  It is also useful for following allowing as the install occurs.
86
-set -o xtrace
87 85
 
88 86
 # Settings
89 87
 # ========
... ...
@@ -91,14 +89,14 @@ set -o xtrace
91 91
 # This script is customizable through setting environment variables.  If you
92 92
 # want to override a setting you can either::
93 93
 #
94
-#     export MYSQL_PASS=anothersecret
94
+#     export MYSQL_PASSWORD=anothersecret
95 95
 #     ./stack.sh
96 96
 #
97
-# You can also pass options on a single line ``MYSQL_PASS=simple ./stack.sh``
97
+# You can also pass options on a single line ``MYSQL_PASSWORD=simple ./stack.sh``
98 98
 #
99 99
 # Additionally, you can put any local variables into a ``localrc`` file, like::
100 100
 #
101
-#     MYSQL_PASS=anothersecret
101
+#     MYSQL_PASSWORD=anothersecret
102 102
 #     MYSQL_USER=hellaroot
103 103
 #
104 104
 # We try to have sensible defaults, so you should be able to run ``./stack.sh``
... ...
@@ -111,14 +109,12 @@ set -o xtrace
111 111
 #
112 112
 # If ``localrc`` exists, then ``stackrc`` will load those settings.  This is 
113 113
 # useful for changing a branch or repostiory to test other versions.  Also you
114
-# can store your other settings like **MYSQL_PASS** or **ADMIN_PASSWORD** instead
114
+# can store your other settings like **MYSQL_PASSWORD** or **ADMIN_PASSWORD** instead
115 115
 # of letting devstack generate random ones for you.
116 116
 source ./stackrc
117 117
 
118 118
 # Destination path for installation ``DEST``
119 119
 DEST=${DEST:-/opt/stack}
120
-sudo mkdir -p $DEST
121
-sudo chown `whoami` $DEST
122 120
 
123 121
 # Set the destination directories for openstack projects
124 122
 NOVA_DIR=$DEST/nova
... ...
@@ -146,6 +142,43 @@ if [ ! -n "$HOST_IP" ]; then
146 146
     HOST_IP=`LC_ALL=C /sbin/ifconfig  | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
147 147
 fi
148 148
 
149
+# Generic helper to configure passwords
150
+function read_password {
151
+    set +o xtrace
152
+    var=$1; msg=$2
153
+    pw=${!var}
154
+
155
+    localrc=$TOP_DIR/localrc
156
+
157
+    # If the password is not defined yet, proceed to prompt user for a password.
158
+    if [ ! $pw ]; then
159
+        # If there is no localrc file, create one
160
+        if [ ! -e $localrc ]; then
161
+            touch $localrc
162
+        fi
163
+
164
+        # Presumably if we got this far it can only be that our localrc is missing 
165
+        # the required password.  Prompt user for a password and write to localrc.
166
+        echo ''
167
+        echo '################################################################################'
168
+        echo $msg
169
+        echo '################################################################################'
170
+        echo "This value will be written to your localrc file so you don't have to enter it again."
171
+        echo "It is probably best to avoid spaces and weird characters."
172
+        echo "If you leave this blank, a random default value will be used."
173
+        echo "Enter a password now:"
174
+        read $var
175
+        pw=${!var}
176
+        if [ ! $pw ]; then
177
+            pw=`openssl rand -hex 10`
178
+        fi
179
+        eval "$var=$pw"
180
+        echo "$var=$pw" >> $localrc
181
+    fi
182
+    set -o xtrace
183
+}
184
+
185
+
149 186
 # Nova Network Configuration
150 187
 # --------------------------
151 188
 
... ...
@@ -194,32 +227,51 @@ FLAT_INTERFACE=${FLAT_INTERFACE:-eth0}
194 194
 
195 195
 # By default this script will install and configure MySQL.  If you want to 
196 196
 # use an existing server, you can pass in the user/password/host parameters.
197
-# You will need to send the same ``MYSQL_PASS`` to every host if you are doing
197
+# You will need to send the same ``MYSQL_PASSWORD`` to every host if you are doing
198 198
 # a multi-node devstack installation.
199 199
 MYSQL_USER=${MYSQL_USER:-root}
200
-MYSQL_PASS=${MYSQL_PASS:-`openssl rand -hex 12`}
200
+read_password MYSQL_PASSWORD "ENTER A PASSWORD TO USE FOR MYSQL."
201 201
 MYSQL_HOST=${MYSQL_HOST:-localhost}
202 202
 
203 203
 # don't specify /db in this string, so we can use it for multiple services
204
-BASE_SQL_CONN=${BASE_SQL_CONN:-mysql://$MYSQL_USER:$MYSQL_PASS@$MYSQL_HOST}
204
+BASE_SQL_CONN=${BASE_SQL_CONN:-mysql://$MYSQL_USER:$MYSQL_PASSWORD@$MYSQL_HOST}
205 205
 
206 206
 # Rabbit connection info
207 207
 RABBIT_HOST=${RABBIT_HOST:-localhost}
208 208
 RABBIT_PASSWORD=${RABBIT_PASSWORD:-`openssl rand -hex 12`}
209
+read_password RABBIT_PASSWORD "ENTER A PASSWORD TO USE FOR RABBIT."
209 210
 
210 211
 # Glance connection info.  Note the port must be specified.
211 212
 GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$HOST_IP:9292}
212 213
 
214
+
213 215
 # Keystone
214 216
 # --------
215 217
 
216 218
 # Service Token - Openstack components need to have an admin token
217 219
 # to validate user tokens.
218
-SERVICE_TOKEN=${SERVICE_TOKEN:-`openssl rand -hex 12`}
220
+read_password SERVICE_TOKEN "ENTER A SERVICE_TOKEN TO USE FOR THE SERVICE ADMIN TOKEN."
219 221
 # Dash currently truncates usernames and passwords at 20 characters
220
-# so use 10 bytes
221
-ADMIN_PASSWORD=${ADMIN_PASSWORD:-`openssl rand -hex 10`}
222
+read_password ADMIN_PASSWORD "ENTER A PASSWORD TO USE FOR DASH AND KEYSTONE (20 CHARS OR LESS)."
223
+
224
+LOGFILE=${LOGFILE:-"$PWD/stack.sh.$$.log"}
225
+(
226
+# So that errors don't compound we exit on any errors so you see only the
227
+# first error that occured.
228
+trap failed ERR
229
+failed() {
230
+    local r=$?
231
+    set +o xtrace
232
+    [ -n "$LOGFILE" ] && echo "${0##*/} failed: full log in $LOGFILE"
233
+    exit $r
234
+}
235
+
236
+# Print the commands being run so that we can see the command that triggers
237
+# an error.  It is also useful for following along as the install occurs.
238
+set -o xtrace
222 239
 
240
+sudo mkdir -p $DEST
241
+sudo chown `whoami` $DEST
223 242
 
224 243
 # Install Packages
225 244
 # ================
... ...
@@ -228,6 +280,7 @@ ADMIN_PASSWORD=${ADMIN_PASSWORD:-`openssl rand -hex 10`}
228 228
 
229 229
 
230 230
 # install apt requirements
231
+sudo apt-get update
231 232
 sudo apt-get install -qqy `cat $FILES/apts/* | cut -d\# -f1 | grep -Ev "mysql-server|rabbitmq-server"`
232 233
 
233 234
 # install python requirements
... ...
@@ -301,15 +354,28 @@ if [[ "$ENABLED_SERVICES" =~ "mysql" ]]; then
301 301
     # Seed configuration with mysql password so that apt-get install doesn't
302 302
     # prompt us for a password upon install.
303 303
     cat <<MYSQL_PRESEED | sudo debconf-set-selections
304
-mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS
305
-mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS
304
+mysql-server-5.1 mysql-server/root_password password $MYSQL_PASSWORD
305
+mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASSWORD
306 306
 mysql-server-5.1 mysql-server/start_on_boot boolean true
307 307
 MYSQL_PRESEED
308 308
 
309
+    # while ``.my.cnf`` is not needed for openstack to function, it is useful
310
+    # as it allows you to access the mysql databases via ``mysql nova`` instead
311
+    # of having to specify the username/password each time.
312
+    if [[ ! -e $HOME/.my.cnf ]]; then
313
+        cat <<EOF >$HOME/.my.cnf
314
+[client]
315
+user=$MYSQL_USER
316
+password=$MYSQL_PASSWORD
317
+host=$MYSQL_HOST
318
+EOF
319
+        chmod 0600 $HOME/.my.cnf
320
+    fi
321
+
309 322
     # Install and start mysql-server
310 323
     sudo apt-get -y -q install mysql-server
311 324
     # Update the DB to give user ‘$MYSQL_USER’@’%’ full control of the all databases:
312
-    sudo mysql -uroot -p$MYSQL_PASS -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' identified by '$MYSQL_PASS';"
325
+    sudo mysql -uroot -p$MYSQL_PASSWORD -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' identified by '$MYSQL_PASSWORD';"
313 326
 
314 327
     # Edit /etc/mysql/my.cnf to change ‘bind-address’ from localhost (127.0.0.1) to any (0.0.0.0) and restart the mysql service:
315 328
     sudo sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
... ...
@@ -360,8 +426,8 @@ if [[ "$ENABLED_SERVICES" =~ "g-reg" ]]; then
360 360
     mkdir -p $GLANCE_IMAGE_DIR
361 361
 
362 362
     # (re)create glance database
363
-    mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE IF EXISTS glance;'
364
-    mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE glance;'
363
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS glance;'
364
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE glance;'
365 365
     # Copy over our glance-registry.conf
366 366
     GLANCE_CONF=$GLANCE_DIR/etc/glance-registry.conf
367 367
     cp $FILES/glance-registry.conf $GLANCE_CONF
... ...
@@ -490,8 +556,8 @@ fi
490 490
 
491 491
 if [[ "$ENABLED_SERVICES" =~ "mysql" ]]; then
492 492
     # (re)create nova database
493
-    mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE IF EXISTS nova;'
494
-    mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
493
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS nova;'
494
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE nova;'
495 495
 
496 496
     # (re)create nova database
497 497
     $NOVA_DIR/bin/nova-manage db sync
... ...
@@ -509,8 +575,8 @@ fi
509 509
 
510 510
 if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
511 511
     # (re)create keystone database
512
-    mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE IF EXISTS keystone;'
513
-    mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE keystone;'
512
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS keystone;'
513
+    mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE keystone;'
514 514
 
515 515
     # FIXME (anthony) keystone should use keystone.conf.example
516 516
     KEYSTONE_CONF=$KEYSTONE_DIR/etc/keystone.conf
... ...
@@ -584,9 +650,8 @@ fi
584 584
 # have to do a little more than that in our script.  Since we add the group
585 585
 # ``libvirtd`` to our user in this script, when nova-compute is run it is
586 586
 # within the context of our original shell (so our groups won't be updated).
587
-# We can send the command nova-compute to the ``newgrp`` command to execute
588
-# in a specific context.
589
-screen_it n-cpu "cd $NOVA_DIR && echo $NOVA_DIR/bin/nova-compute | newgrp libvirtd"
587
+# Use 'sg' to execute nova-compute as a member of the libvirtd group.
588
+screen_it n-cpu "cd $NOVA_DIR && sg libvirtd $NOVA_DIR/bin/nova-compute"
590 589
 screen_it n-net "cd $NOVA_DIR && $NOVA_DIR/bin/nova-network"
591 590
 screen_it n-sch "cd $NOVA_DIR && $NOVA_DIR/bin/nova-scheduler"
592 591
 screen_it n-vnc "cd $NOVNC_DIR && ./utils/nova-wsproxy.py 6080 --web . --flagfile=../nova/bin/nova.conf"
... ...
@@ -595,57 +660,53 @@ screen_it dash "cd $DASH_DIR && sudo /etc/init.d/apache2 restart; sudo tail -f /
595 595
 # Install Images
596 596
 # ==============
597 597
 
598
-# Upload a couple images to glance.  **TTY** is a simple small image that use the 
599
-# lets you login to it with username/password of user/password.  TTY is useful 
600
-# for basic functionality.  We all include an Ubuntu cloud build of **Natty**.
601
-# Natty uses cloud-init, supporting login via keypair and sending scripts as
602
-# userdata.  
598
+# Upload an image to glance.
603 599
 #
604
-# Read more about cloud-init at https://help.ubuntu.com/community/CloudInit
600
+# The default image is a small ***TTY*** testing image, which lets you login
601
+# the username/password of root/password.
602
+#
603
+# TTY also uses cloud-init, supporting login via keypair and sending scripts as
604
+# userdata.  See https://help.ubuntu.com/community/CloudInit for more on cloud-init
605
+#
606
+# Override IMAGE_URLS if you would to launch a different image(s).  
607
+# Specify IMAGE_URLS as a comma-separated list of uec urls.  Some other options include:
608
+#   natty: http://uec-images.ubuntu.com/natty/current/natty-server-cloudimg-amd64.tar.gz
609
+#   oneiric: http://uec-images.ubuntu.com/oneiric/current/oneiric-server-cloudimg-amd64.tar.gz
605 610
 
606 611
 if [[ "$ENABLED_SERVICES" =~ "g-reg" ]]; then
607
-    # create a directory for the downloadedthe images tarballs.
612
+    # Create a directory for the downloaded image tarballs.
608 613
     mkdir -p $FILES/images
609 614
 
610
-    # Debug Image (TTY)
611
-    # -----------------
615
+    for image_url in ${IMAGE_URLS//,/ }; do
616
+        # Downloads the image (uec ami+aki style), then extracts it.
617
+        IMAGE_FNAME=`echo "$image_url" | python -c "import sys; print sys.stdin.read().split('/')[-1]"`
618
+        IMAGE_NAME=`echo "$IMAGE_FNAME" | python -c "import sys; print sys.stdin.read().split('.tar.gz')[0].split('.tgz')[0]"`
619
+        if [ ! -f $FILES/$IMAGE_FNAME ]; then
620
+            wget -c $image_url -O $FILES/$IMAGE_FNAME
621
+        fi
612 622
 
613
-    # Downloads the image (ami/aki/ari style), then extracts it.  Upon extraction
614
-    # we upload to glance with the glance cli tool.  TTY is a stripped down 
615
-    # version of ubuntu.
616
-    if [ ! -f $FILES/tty.tgz ]; then
617
-        wget -c http://images.ansolabs.com/tty.tgz -O $FILES/tty.tgz
618
-    fi
623
+        # Extract ami and aki files
624
+        tar -zxf $FILES/$IMAGE_FNAME -C $FILES/images
619 625
 
620
-    # extract ami-tty/image, aki-tty/image & ari-tty/image
621
-    tar -zxf $FILES/tty.tgz -C $FILES/images
622
-
623
-    # Use glance client to add the kernel, ramdisk and finally the root 
624
-    # filesystem.  We parse the results of the uploads to get glance IDs of the
625
-    # ramdisk and kernel and use them for the root filesystem.
626
-    RVAL=`glance add -A $SERVICE_TOKEN name="tty-kernel" is_public=true container_format=aki disk_format=aki < $FILES/images/aki-tty/image`
627
-    KERNEL_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "`
628
-    RVAL=`glance add -A $SERVICE_TOKEN name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < $FILES/images/ari-tty/image`
629
-    RAMDISK_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "`
630
-    glance add -A $SERVICE_TOKEN name="tty" is_public=true container_format=ami disk_format=ami kernel_id=$KERNEL_ID ramdisk_id=$RAMDISK_ID < $FILES/images/ami-tty/image
631
-
632
-    # Ubuntu 11.04 aka Natty
633
-    # ----------------------
634
-
635
-    # Downloaded from ubuntu enterprise cloud images.  This
636
-    # image doesn't use the ramdisk functionality
637
-    if [ ! -f $FILES/natty.tgz ]; then
638
-        wget -c http://uec-images.ubuntu.com/natty/current/natty-server-cloudimg-amd64.tar.gz -O $FILES/natty.tgz
639
-    fi
640
-    
641
-    tar -zxf $FILES/natty.tgz -C $FILES/images
626
+        # Use glance client to add the kernel the root filesystem.
627
+        # We parse the results of the first upload to get the glance ID of the
628
+        # kernel for use when uploading the root filesystem.
629
+        RVAL=`glance add -A $SERVICE_TOKEN name="$IMAGE_NAME-kernel" is_public=true container_format=aki disk_format=aki < $FILES/images/$IMAGE_NAME-vmlinuz*`
630
+        KERNEL_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "`
631
+        glance add -A $SERVICE_TOKEN name="$IMAGE_NAME" is_public=true container_format=ami disk_format=ami kernel_id=$KERNEL_ID < $FILES/images/$IMAGE_NAME.img
632
+    done
633
+fi
642 634
 
643
-    RVAL=`glance add -A $SERVICE_TOKEN name="uec-natty-kernel" is_public=true container_format=aki disk_format=aki < $FILES/images/natty-server-cloudimg-amd64-vmlinuz-virtual`
644
-    KERNEL_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "`
645
-    glance add -A $SERVICE_TOKEN name="uec-natty" is_public=true container_format=ami disk_format=ami kernel_id=$KERNEL_ID < $FILES/images/natty-server-cloudimg-amd64.img
635
+# Fin
636
+# ===
646 637
 
647
-fi
648 638
 
639
+) 2>&1 | tee "${LOGFILE}"
640
+
641
+# Check that the left side of the above pipe succeeded
642
+for ret in "${PIPESTATUS[@]}"; do [ $ret -eq 0 ] || exit $ret; done
643
+
644
+(
649 645
 # Using the cloud
650 646
 # ===============
651 647
 
... ...
@@ -663,10 +724,7 @@ if [[ "$ENABLED_SERVICES" =~ "key" ]]; then
663 663
     echo "the password: $ADMIN_PASSWORD"
664 664
 fi
665 665
 
666
-# Fin
667
-# ===
666
+# indicate how long this took to run (bash maintained variable 'SECONDS')
667
+echo "stack.sh completed in $SECONDS seconds."
668 668
 
669
-# End our timer and give a timing summary
670
-END_TIME=`python -c "import time; print time.time()"`
671
-ELAPSED=`python -c "print $END_TIME - $START_TIME"`
672
-echo "stack.sh completed in $ELAPSED seconds."
669
+) | tee -a "$LOGFILE"
... ...
@@ -27,6 +27,9 @@ NOVACLIENT_BRANCH=master
27 27
 OPENSTACKX_REPO=https://github.com/cloudbuilders/openstackx.git
28 28
 OPENSTACKX_BRANCH=diablo
29 29
 
30
+# Specify a comma-separated list of uec images to download and install into glance.
31
+IMAGE_URLS=http://smoser.brickies.net/ubuntu/ttylinux-uec/ttylinux-uec-amd64-11.2_2.6.35-15_1.tar.gz
32
+
30 33
 # allow local overrides of env variables
31 34
 if [ -f ./localrc ]; then
32 35
     source ./localrc
33 36
new file mode 100755
... ...
@@ -0,0 +1,299 @@
0
+#!/usr/bin/env bash
1
+
2
+# Sanity check
3
+if [ "$EUID" -ne "0" ]; then
4
+  echo "This script must be run with root privileges."
5
+  exit 1
6
+fi
7
+
8
+# Keep track of ubuntu version
9
+UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'`
10
+
11
+# Move to top devstack dir
12
+cd ..
13
+
14
+# Abort if localrc is not set
15
+if [ ! -e ./localrc ]; then
16
+    echo "You must have a localrc with ALL necessary passwords defined before proceeding."
17
+    echo "See stack.sh for required passwords."
18
+    exit 1
19
+fi
20
+
21
+# Source params
22
+source ./stackrc
23
+
24
+# Store cwd
25
+CWD=`pwd`
26
+
27
+# Configurable params
28
+BRIDGE=${BRIDGE:-br0}
29
+CONTAINER=${CONTAINER:-STACK}
30
+CONTAINER_IP=${CONTAINER_IP:-192.168.1.50}
31
+CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24}
32
+CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0}
33
+CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1}
34
+NAMESERVER=${NAMESERVER:-$CONTAINER_GATEWAY}
35
+COPYENV=${COPYENV:-1}
36
+DEST=${DEST:-/opt/stack}
37
+WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
38
+
39
+# Param string to pass to stack.sh.  Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
40
+STACKSH_PARAMS=${STACKSH_PARAMS:-}
41
+
42
+# Option to use the version of devstack on which we are currently working
43
+USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
44
+
45
+
46
+# Install deps
47
+apt-get install -y lxc debootstrap
48
+
49
+# Install cgroup-bin from source, since the packaging is buggy and possibly incompatible with our setup
50
+if ! which cgdelete | grep -q cgdelete; then
51
+    apt-get install -y g++ bison flex libpam0g-dev make
52
+    wget http://sourceforge.net/projects/libcg/files/libcgroup/v0.37.1/libcgroup-0.37.1.tar.bz2/download -O /tmp/libcgroup-0.37.1.tar.bz2
53
+    cd /tmp && bunzip2 libcgroup-0.37.1.tar.bz2  && tar xfv libcgroup-0.37.1.tar
54
+    cd libcgroup-0.37.1
55
+    ./configure
56
+    make install
57
+    ldconfig
58
+fi
59
+
60
+# Create lxc configuration
61
+LXC_CONF=/tmp/$CONTAINER.conf
62
+cat > $LXC_CONF <<EOF
63
+lxc.network.type = veth
64
+lxc.network.link = $BRIDGE
65
+lxc.network.flags = up
66
+lxc.network.ipv4 = $CONTAINER_CIDR
67
+# allow tap/tun devices
68
+lxc.cgroup.devices.allow = c 10:200 rwm
69
+EOF
70
+
71
+# Shutdown any existing container
72
+lxc-stop -n $CONTAINER
73
+
74
+# This kills zombie containers
75
+if [ -d /cgroup/$CONTAINER ]; then
76
+    cgdelete -r cpu,net_cls:$CONTAINER
77
+fi
78
+
79
+# git clone only if directory doesn't exist already.  Since ``DEST`` might not
80
+# be owned by the installation user, we create the directory and change the
81
+# ownership to the proper user.
82
+function git_clone {
83
+    if [ ! -d $2 ]; then
84
+        sudo mkdir $2
85
+        sudo chown `whoami` $2
86
+        git clone $1 $2
87
+        cd $2
88
+        # This checkout syntax works for both branches and tags
89
+        git checkout $3
90
+    fi
91
+}
92
+
93
+# Helper to create the container
94
+function create_lxc {
95
+    if [ "natty" = "$UBUNTU_VERSION" ]; then
96
+        lxc-create -n $CONTAINER -t natty -f $LXC_CONF
97
+    else
98
+        lxc-create -n $CONTAINER -t ubuntu -f $LXC_CONF
99
+    fi
100
+}
101
+
102
+# Location of the base image directory
103
+if [ "natty" = "$UBUNTU_VERSION" ]; then
104
+    CACHEDIR=/var/cache/lxc/natty/rootfs-amd64
105
+else
106
+    CACHEDIR=/var/cache/lxc/oneiric/rootfs-amd64
107
+fi
108
+
109
+# Provide option to do totally clean install
110
+if [ "$CLEAR_LXC_CACHE" = "1" ]; then
111
+    rm -rf $CACHEDIR
112
+fi
113
+
114
+# Warm the base image on first install
115
+if [ ! -f $CACHEDIR/bootstrapped ]; then
116
+    # by deleting the container, we force lxc-create to re-bootstrap (lxc is
117
+    # lazy and doesn't do anything if a container already exists)
118
+    lxc-destroy -n $CONTAINER
119
+    # trigger the initial debootstrap
120
+    create_lxc
121
+    chroot $CACHEDIR apt-get update
122
+    chroot $CACHEDIR apt-get install -y --force-yes `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
123
+    chroot $CACHEDIR pip install `cat files/pips/*`
124
+    touch $CACHEDIR/bootstrapped
125
+fi
126
+
127
+# Clean out code repos if directed to do so
128
+if [ "$CLEAN" = "1" ]; then
129
+    rm -rf $CACHEDIR/$DEST
130
+fi
131
+
132
+# Cache openstack code
133
+mkdir -p $CACHEDIR/$DEST
134
+git_clone $NOVA_REPO $CACHEDIR/$DEST/nova $NOVA_BRANCH
135
+git_clone $GLANCE_REPO $CACHEDIR/$DEST/glance $GLANCE_BRANCH
136
+git_clone $KEYSTONE_REPO $CACHEDIR/$DESTkeystone $KEYSTONE_BRANCH
137
+git_clone $NOVNC_REPO $CACHEDIR/$DEST/novnc $NOVNC_BRANCH
138
+git_clone $DASH_REPO $CACHEDIR/$DEST/dash $DASH_BRANCH $DASH_TAG
139
+git_clone $NOVACLIENT_REPO $CACHEDIR/$DEST/python-novaclient $NOVACLIENT_BRANCH
140
+git_clone $OPENSTACKX_REPO $CACHEDIR/$DEST/openstackx $OPENSTACKX_BRANCH
141
+
142
+# Use this version of devstack?
143
+if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then
144
+    rm -rf $CACHEDIR/$DEST/devstack
145
+    cp -pr $CWD $CACHEDIR/$DEST/devstack
146
+fi
147
+
148
+# Destroy the old container
149
+lxc-destroy -n $CONTAINER
150
+
151
+# If this call is to TERMINATE the container then exit
152
+if [ "$TERMINATE" = "1" ]; then
153
+    exit
154
+fi
155
+
156
+# Create the container
157
+create_lxc
158
+
159
+# Specify where our container rootfs lives
160
+ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/
161
+
162
+# Create a stack user that is a member of the libvirtd group so that stack
163
+# is able to interact with libvirt.
164
+chroot $ROOTFS groupadd libvirtd
165
+chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd
166
+
167
+# a simple password - pass
168
+echo stack:pass | chroot $ROOTFS chpasswd
169
+
170
+# and has sudo ability (in the future this should be limited to only what
171
+# stack requires)
172
+echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers
173
+
174
+# Copy kernel modules
175
+mkdir -p $ROOTFS/lib/modules/`uname -r`/kernel
176
+cp -p /lib/modules/`uname -r`/modules.dep $ROOTFS/lib/modules/`uname -r`/
177
+cp -pR /lib/modules/`uname -r`/kernel/net $ROOTFS/lib/modules/`uname -r`/kernel/
178
+
179
+# Gracefully cp only if source file/dir exists
180
+function cp_it {
181
+    if [ -e $1 ] || [ -d $1 ]; then
182
+        cp -pRL $1 $2
183
+    fi
184
+}
185
+
186
+# Copy over your ssh keys and env if desired
187
+if [ "$COPYENV" = "1" ]; then
188
+    cp_it ~/.ssh $ROOTFS/$DEST/.ssh
189
+    cp_it ~/.ssh/id_rsa.pub $ROOTFS/$DEST/.ssh/authorized_keys
190
+    cp_it ~/.gitconfig $ROOTFS/$DEST/.gitconfig
191
+    cp_it ~/.vimrc $ROOTFS/$DEST/.vimrc
192
+    cp_it ~/.bashrc $ROOTFS/$DEST/.bashrc
193
+fi
194
+
195
+# Make our ip address hostnames look nice at the command prompt
196
+echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/$DEST/.bashrc
197
+echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile
198
+
199
+# Give stack ownership over $DEST so it may do the work needed
200
+chroot $ROOTFS chown -R stack $DEST
201
+
202
+# Configure instance network
203
+INTERFACES=$ROOTFS/etc/network/interfaces
204
+cat > $INTERFACES <<EOF
205
+auto lo
206
+iface lo inet loopback
207
+
208
+auto eth0
209
+iface eth0 inet static
210
+        address $CONTAINER_IP
211
+        netmask $CONTAINER_NETMASK
212
+        gateway $CONTAINER_GATEWAY
213
+EOF
214
+
215
+# Configure the runner
216
+RUN_SH=$ROOTFS/$DEST/run.sh
217
+cat > $RUN_SH <<EOF
218
+#!/usr/bin/env bash
219
+# Make sure dns is set up
220
+echo "nameserver $NAMESERVER" | sudo resolvconf -a eth0
221
+# Make there is a default route - needed for natty
222
+if ! route | grep -q default; then
223
+    sudo ip route add default via $CONTAINER_GATEWAY
224
+fi
225
+sleep 1
226
+
227
+# Kill any existing screens
228
+killall screen
229
+
230
+# Install and run stack.sh
231
+sudo apt-get update
232
+sudo apt-get -y --force-yes install git-core vim-nox sudo
233
+if [ ! -d "$DEST/devstack" ]; then
234
+    git clone git://github.com/cloudbuilders/devstack.git $DEST/devstack
235
+fi
236
+cd $DEST/devstack && $STACKSH_PARAMS FORCE=yes ./stack.sh > /$DEST/run.sh.log
237
+echo >> /$DEST/run.sh.log
238
+echo >> /$DEST/run.sh.log
239
+echo "All done! Time to start clicking." >> /$DEST/run.sh.log
240
+EOF
241
+
242
+# Make the run.sh executable
243
+chmod 755 $RUN_SH
244
+
245
+# Make runner launch on boot
246
+RC_LOCAL=$ROOTFS/etc/init.d/local
247
+cat > $RC_LOCAL <<EOF
248
+#!/bin/sh -e
249
+su -c "$DEST/run.sh" stack
250
+EOF
251
+chmod +x $RC_LOCAL
252
+chroot $ROOTFS sudo update-rc.d local defaults 80
253
+
254
+# Configure cgroup directory
255
+if ! mount | grep -q cgroup; then
256
+    mkdir -p /cgroup
257
+    mount none -t cgroup /cgroup
258
+fi
259
+
260
+# Start our container
261
+lxc-start -d -n $CONTAINER
262
+
263
+if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
264
+    # Done creating the container, let's tail the log
265
+    echo
266
+    echo "============================================================="
267
+    echo "                          -- YAY! --"
268
+    echo "============================================================="
269
+    echo
270
+    echo "We're done creating the container, about to start tailing the"
271
+    echo "stack.sh log. It will take a second or two to start."
272
+    echo
273
+    echo "Just CTRL-C at any time to stop tailing."
274
+
275
+    while [ ! -e "$ROOTFS/$DEST/run.sh.log" ]; do
276
+      sleep 1
277
+    done
278
+
279
+    tail -F $ROOTFS/$DEST/run.sh.log &
280
+
281
+    TAIL_PID=$!
282
+
283
+    function kill_tail() {
284
+        exit 1
285
+    }
286
+ 
287
+    # Let Ctrl-c kill tail and exit
288
+    trap kill_tail SIGINT
289
+
290
+    echo "Waiting stack.sh to finish..."
291
+    while ! cat $ROOTFS/$DEST/run.sh.log | grep -q 'All done' ; do
292
+        sleep 5
293
+    done
294
+
295
+    kill $TAIL_PID
296
+    echo ""
297
+    echo "Finished - Zip-a-dee Doo-dah!"
298
+fi
0 299
new file mode 100755
... ...
@@ -0,0 +1,39 @@
0
+#!/usr/bin/env bash
1
+# Head node host, which runs glance, api, keystone
2
+HEAD_HOST=${HEAD_HOST:-192.168.1.52}
3
+COMPUTE_HOSTS=${COMPUTE_HOSTS:-192.168.1.53,192.168.1.54}
4
+
5
+# Networking params
6
+NAMESERVER=${NAMESERVER:-192.168.1.1}
7
+GATEWAY=${GATEWAY:-192.168.1.1}
8
+NETMASK=${NETMASK:-255.255.255.0}
9
+FLOATING_RANGE=${FLOATING_RANGE:-192.168.1.196/30}
10
+
11
+# Setting this to 1 shuts down and destroys our containers without relaunching.
12
+TERMINATE=${TERMINATE:-0}
13
+
14
+# Variables common amongst all hosts in the cluster
15
+COMMON_VARS="MYSQL_HOST=$HEAD_HOST RABBIT_HOST=$HEAD_HOST GLANCE_HOSTPORT=$HEAD_HOST:9292 NET_MAN=FlatDHCPManager FLAT_INTERFACE=eth0 FLOATING_RANGE=$FLOATING_RANGE MULTI_HOST=1"
16
+
17
+# Helper to launch containers
18
+function run_lxc {
19
+    # For some reason container names with periods can cause issues :/
20
+    CONTAINER=$1 CONTAINER_IP=$2 CONTAINER_NETMASK=$NETMASK CONTAINER_GATEWAY=$GATEWAY NAMESERVER=$NAMESERVER TERMINATE=$TERMINATE STACKSH_PARAMS="$COMMON_VARS $3" ./build_lxc.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
+run_lxc STACKMASTER $HEAD_HOST "ENABLED_SERVICES=g-api,g-reg,key,n-api,n-sch,n-vnc,dash,mysql,rabbit"
26
+
27
+# Wait till the head node is up
28
+if [ ! "$TERMINATE" = "1" ]; then
29
+    while ! wget -q -O- http://$HEAD_HOST | grep -q username; do
30
+        echo "Waiting for head node ($HEAD_HOST) to start..."
31
+        sleep 5
32
+    done
33
+fi
34
+
35
+# Launch the compute hosts
36
+for compute_host in ${COMPUTE_HOSTS//,/ }; do
37
+    run_lxc $compute_host $compute_host "ENABLED_SERVICES=n-cpu,n-net,n-api"
38
+done
... ...
@@ -4,15 +4,8 @@
4 4
 # build_pxe_boot.sh [-k kernel-version] destdir
5 5
 #
6 6
 # Assumes syslinux is installed
7
-# Assumes devstack files are in `pwd`/pxe
8 7
 # Only needs to run as root if the destdir permissions require it
9 8
 
10
-UBUNTU_MIRROR=http://archive.ubuntu.com/ubuntu/dists/natty/main/installer-amd64/current/images/netboot/ubuntu-installer/amd64
11
-
12
-MEMTEST_VER=4.10
13
-MEMTEST_BIN=memtest86+-${MEMTEST_VER}.bin
14
-MEMTEST_URL=http://www.memtest.org/download/${MEMTEST_VER}/
15
-
16 9
 KVER=`uname -r`
17 10
 if [ "$1" = "-k" ]; then
18 11
     KVER=$2
... ...
@@ -30,8 +23,8 @@ for i in memdisk menu.c32 pxelinux.0; do
30 30
 	cp -p /usr/lib/syslinux/$i $DEST_DIR
31 31
 done
32 32
 
33
-DEFAULT=$DEST_DIR/pxelinux.cfg/default
34
-cat >$DEFAULT <<EOF
33
+CFG=$DEST_DIR/pxelinux.cfg/default
34
+cat >$CFG <<EOF
35 35
 default menu.c32
36 36
 prompt 0
37 37
 timeout 0
... ...
@@ -59,7 +52,7 @@ if [ ! -r $PXEDIR/stack-initrd.gz ]; then
59 59
     sudo $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.gz
60 60
 fi
61 61
 cp -p $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
62
-cat >>$DEFAULT <<EOF
62
+cat >>$CFG <<EOF
63 63
 
64 64
 LABEL devstack
65 65
     MENU LABEL ^devstack
... ...
@@ -69,48 +62,21 @@ LABEL devstack
69 69
 EOF
70 70
 
71 71
 # Get Ubuntu
72
-if [ -d $PXEDIR ]; then
72
+if [ -d $PXEDIR -a -r $PXEDIR/natty-base-initrd.gz ]; then
73 73
     cp -p $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
74
-fi
75
-cat >>$DEFAULT <<EOF
74
+    cat >>$CFG <<EOF
76 75
 
77 76
 LABEL ubuntu
78 77
     MENU LABEL ^Ubuntu Natty
79 78
     KERNEL ubuntu/vmlinuz-$KVER
80 79
     APPEND initrd=ubuntu/natty-base-initrd.gz ramdisk_size=419600 root=/dev/ram0
81 80
 EOF
82
-
83
-# Get Memtest
84
-cd $DEST_DIR
85
-if [ ! -r $MEMTEST_BIN ]; then
86
-    wget -N --quiet ${MEMTEST_URL}/${MEMTEST_BIN}.gz
87
-    gunzip $MEMTEST_BIN
88 81
 fi
89
-cat >>$DEFAULT <<EOF
90
-
91
-LABEL memtest
92
-    MENU LABEL ^Memtest86+
93
-    KERNEL $MEMTEST_BIN
94
-EOF
95
-
96
-# Get FreeDOS
97
-mkdir -p $DEST_DIR/freedos
98
-cd $DEST_DIR/freedos
99
-wget -N --quiet http://www.fdos.org/bootdisks/autogen/FDSTD.288.gz
100
-gunzip -f FDSTD.288.gz
101
-cat >>$DEFAULT <<EOF
102
-
103
-LABEL freedos
104
-	MENU LABEL ^FreeDOS bootdisk
105
-	KERNEL memdisk
106
-	APPEND initrd=freedos/FDSTD.288
107
-EOF
108 82
 
109 83
 # Local disk boot
110
-cat >>$DEFAULT <<EOF
84
+cat >>$CFG <<EOF
111 85
 
112 86
 LABEL local
113 87
     MENU LABEL ^Local disk
114
-    MENU DEFAULT
115 88
     LOCALBOOT 0
116 89
 EOF
117 90
new file mode 100755
... ...
@@ -0,0 +1,103 @@
0
+#!/bin/bash -e
1
+# build_usb_boot.sh - Create a syslinux boot environment
2
+#
3
+# build_usb_boot.sh [-k kernel-version] destdev
4
+#
5
+# Assumes syslinux is installed
6
+# Needs to run as root
7
+
8
+KVER=`uname -r`
9
+if [ "$1" = "-k" ]; then
10
+    KVER=$2
11
+    shift;shift
12
+fi
13
+
14
+DEST_DIR=${1:-/tmp/syslinux-boot}
15
+PXEDIR=${PXEDIR:-/var/cache/devstack/pxe}
16
+OPWD=`pwd`
17
+PROGDIR=`dirname $0`
18
+
19
+if [ -b $DEST_DIR ]; then
20
+    # We have a block device, install syslinux and mount it
21
+    DEST_DEV=$DEST_DIR
22
+    DEST_DIR=`mktemp -d mntXXXXXX`
23
+
24
+    # Install syslinux on the device
25
+    syslinux --install --directory syslinux $DEST_DEV
26
+
27
+    mount $DEST_DEV $DEST_DIR
28
+else
29
+    # We have a directory (for sanity checking output)
30
+	DEST_DEV=""
31
+	if [ ! -d $DEST_DIR/syslinux ]; then
32
+	    mkdir -p $DEST_DIR/syslinux
33
+	fi
34
+fi
35
+
36
+# Get some more stuff from syslinux
37
+for i in memdisk menu.c32; do
38
+	cp -p /usr/lib/syslinux/$i $DEST_DIR/syslinux
39
+done
40
+
41
+CFG=$DEST_DIR/syslinux/syslinux.cfg
42
+cat >$CFG <<EOF
43
+default /syslinux/menu.c32
44
+prompt 0
45
+timeout 0
46
+
47
+MENU TITLE Boot Menu
48
+
49
+EOF
50
+
51
+# Setup devstack boot
52
+mkdir -p $DEST_DIR/ubuntu
53
+if [ ! -d $PXEDIR ]; then
54
+    mkdir -p $PXEDIR
55
+fi
56
+if [ ! -r $PXEDIR/vmlinuz-${KVER} ]; then
57
+    sudo chmod 644 /boot/vmlinuz-${KVER}
58
+    if [ ! -r /boot/vmlinuz-${KVER} ]; then
59
+        echo "No kernel found"
60
+    else
61
+        cp -p /boot/vmlinuz-${KVER} $PXEDIR
62
+    fi
63
+fi
64
+cp -p $PXEDIR/vmlinuz-${KVER} $DEST_DIR/ubuntu
65
+if [ ! -r $PXEDIR/stack-initrd.gz ]; then
66
+    cd $OPWD
67
+    sudo $PROGDIR/build_ramdisk.sh $PXEDIR/stack-initrd.gz
68
+fi
69
+cp -p $PXEDIR/stack-initrd.gz $DEST_DIR/ubuntu
70
+cat >>$CFG <<EOF
71
+
72
+LABEL devstack
73
+    MENU LABEL ^devstack
74
+    MENU DEFAULT
75
+    KERNEL /ubuntu/vmlinuz-$KVER
76
+    APPEND initrd=/ubuntu/stack-initrd.gz ramdisk_size=2109600 root=/dev/ram0
77
+EOF
78
+
79
+# Get Ubuntu
80
+if [ -d $PXEDIR -a -r $PXEDIR/natty-base-initrd.gz ]; then
81
+    cp -p $PXEDIR/natty-base-initrd.gz $DEST_DIR/ubuntu
82
+    cat >>$CFG <<EOF
83
+
84
+LABEL ubuntu
85
+    MENU LABEL ^Ubuntu Natty
86
+    KERNEL /ubuntu/vmlinuz-$KVER
87
+    APPEND initrd=/ubuntu/natty-base-initrd.gz ramdisk_size=419600 root=/dev/ram0
88
+EOF
89
+fi
90
+
91
+# Local disk boot
92
+cat >>$CFG <<EOF
93
+
94
+LABEL local
95
+    MENU LABEL ^Local disk
96
+    LOCALBOOT 0
97
+EOF
98
+
99
+if [ -n "$DEST_DEV" ]; then
100
+    umount $DEST_DIR
101
+    rmdir $DEST_DIR
102
+fi
0 103
new file mode 100755
... ...
@@ -0,0 +1,93 @@
0
+#!/bin/bash
1
+
2
+# Print some usage info
3
+function usage {
4
+  echo "Usage: $0 [OPTION] [host_ip]"
5
+  echo "Set up temporary networking for LXC"
6
+  echo ""
7
+  echo "  -n, --dry-run            Just print the commands that would execute."
8
+  echo "  -h, --help               Print this usage message."
9
+  echo ""
10
+  exit
11
+}
12
+
13
+# Allow passing the ip address on the command line.
14
+function process_option {
15
+  case "$1" in
16
+    -h|--help) usage;;
17
+    -n|--dry-run) dry_run=1;;
18
+    *) host_ip="$1"
19
+  esac
20
+}
21
+
22
+# Set up some defaults
23
+host_ip=
24
+dry_run=0
25
+bridge=br0
26
+DRIER=
27
+
28
+# Process the args
29
+for arg in "$@"; do
30
+  process_option $arg
31
+done
32
+
33
+if [ $dry_run ]; then
34
+  DRIER=echo
35
+fi
36
+
37
+if [ "$UID" -ne "0" ]; then
38
+  echo "This script must be run with root privileges."
39
+  exit 1
40
+fi
41
+
42
+# Check for bridge-utils.
43
+BRCTL=`which brctl`
44
+if [ ! -x "$BRCTL" ]; then
45
+  echo "This script requires you to install bridge-utils."
46
+  echo "Try: sudo apt-get install bridge-utils."
47
+  exit 1
48
+fi
49
+
50
+# Scare off the nubs.
51
+echo "====================================================="
52
+echo
53
+echo "WARNING"
54
+echo
55
+echo "This script will modify your current network setup,"
56
+echo "this can be a scary thing and it is recommended that"
57
+echo "you have something equivalent to physical access to"
58
+echo "this machine before continuing in case your network"
59
+echo "gets all funky."
60
+echo
61
+echo "If you don't want to continue, hit CTRL-C now."
62
+
63
+if [ -z "$host_ip" ];
64
+then
65
+  echo "Otherwise, please type in your host's ip address and"
66
+  echo "hit enter."
67
+  echo
68
+  echo "====================================================="
69
+  read host_ip
70
+else
71
+  echo "Otherwise hit enter."
72
+  echo
73
+  echo "====================================================="
74
+  read accept
75
+fi
76
+
77
+
78
+# Add a bridge interface, this will choke if there is already
79
+# a bridge named $bridge
80
+$DRIER $BRCTL addbr $bridge
81
+$DRIER ip addr add 192.168.1.1/24 dev $bridge
82
+if [ $dry_run ]; then
83
+  echo "echo 1 > /proc/sys/net/ipv4/ip_forward"
84
+else
85
+  echo 1 > /proc/sys/net/ipv4/ip_forward
86
+fi
87
+$DRIER ifconfig $bridge up
88
+
89
+# Set up the NAT for the instances
90
+$DRIER iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source $host_ip
91
+$DRIER iptables -I FORWARD -s 192.168.1.0/24 -j ACCEPT
92
+