| 1 | 1 |
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 |
- |
| ... | ... |
@@ -40,6 +40,9 @@ if [ ! -d $FILES ]; then |
| 40 | 40 |
exit 1 |
| 41 | 41 |
fi |
| 42 | 42 |
|
| 43 |
+# Keep track of the current devstack directory. |
|
| 44 |
+TOP_DIR=$(cd $(dirname "$0") && pwd) |
|
| 45 |
+ |
|
| 43 | 46 |
# OpenStack is designed to be run as a regular user (Dashboard will fail to run |
| 44 | 47 |
# as root, since apache refused to startup serve content from root user). If |
| 45 | 48 |
# stack.sh is run as root, it automatically creates a stack user with |
| ... | ... |
@@ -86,14 +89,14 @@ fi |
| 86 | 86 |
# This script is customizable through setting environment variables. If you |
| 87 | 87 |
# want to override a setting you can either:: |
| 88 | 88 |
# |
| 89 |
-# export MYSQL_PASS=anothersecret |
|
| 89 |
+# export MYSQL_PASSWORD=anothersecret |
|
| 90 | 90 |
# ./stack.sh |
| 91 | 91 |
# |
| 92 |
-# You can also pass options on a single line ``MYSQL_PASS=simple ./stack.sh`` |
|
| 92 |
+# You can also pass options on a single line ``MYSQL_PASSWORD=simple ./stack.sh`` |
|
| 93 | 93 |
# |
| 94 | 94 |
# Additionally, you can put any local variables into a ``localrc`` file, like:: |
| 95 | 95 |
# |
| 96 |
-# MYSQL_PASS=anothersecret |
|
| 96 |
+# MYSQL_PASSWORD=anothersecret |
|
| 97 | 97 |
# MYSQL_USER=hellaroot |
| 98 | 98 |
# |
| 99 | 99 |
# We try to have sensible defaults, so you should be able to run ``./stack.sh`` |
| ... | ... |
@@ -106,7 +109,7 @@ fi |
| 106 | 106 |
# |
| 107 | 107 |
# If ``localrc`` exists, then ``stackrc`` will load those settings. This is |
| 108 | 108 |
# useful for changing a branch or repostiory to test other versions. Also you |
| 109 |
-# can store your other settings like **MYSQL_PASS** or **ADMIN_PASSWORD** instead |
|
| 109 |
+# can store your other settings like **MYSQL_PASSWORD** or **ADMIN_PASSWORD** instead |
|
| 110 | 110 |
# of letting devstack generate random ones for you. |
| 111 | 111 |
source ./stackrc |
| 112 | 112 |
|
| ... | ... |
@@ -139,6 +142,43 @@ if [ ! -n "$HOST_IP" ]; then |
| 139 | 139 |
HOST_IP=`LC_ALL=C /sbin/ifconfig | grep -m 1 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
|
| 140 | 140 |
fi |
| 141 | 141 |
|
| 142 |
+# Generic helper to configure passwords |
|
| 143 |
+function read_password {
|
|
| 144 |
+ set +o xtrace |
|
| 145 |
+ var=$1; msg=$2 |
|
| 146 |
+ pw=${!var}
|
|
| 147 |
+ |
|
| 148 |
+ localrc=$TOP_DIR/localrc |
|
| 149 |
+ |
|
| 150 |
+ # If the password is not defined yet, proceed to prompt user for a password. |
|
| 151 |
+ if [ ! $pw ]; then |
|
| 152 |
+ # If there is no localrc file, create one |
|
| 153 |
+ if [ ! -e $localrc ]; then |
|
| 154 |
+ touch $localrc |
|
| 155 |
+ fi |
|
| 156 |
+ |
|
| 157 |
+ # Presumably if we got this far it can only be that our localrc is missing |
|
| 158 |
+ # the required password. Prompt user for a password and write to localrc. |
|
| 159 |
+ echo '' |
|
| 160 |
+ echo '################################################################################' |
|
| 161 |
+ echo $msg |
|
| 162 |
+ echo '################################################################################' |
|
| 163 |
+ echo "This value will be written to your localrc file so you don't have to enter it again." |
|
| 164 |
+ echo "It is probably best to avoid spaces and weird characters." |
|
| 165 |
+ echo "If you leave this blank, a random default value will be used." |
|
| 166 |
+ echo "Enter a password now:" |
|
| 167 |
+ read $var |
|
| 168 |
+ pw=${!var}
|
|
| 169 |
+ if [ ! $pw ]; then |
|
| 170 |
+ pw=`openssl rand -hex 10` |
|
| 171 |
+ fi |
|
| 172 |
+ eval "$var=$pw" |
|
| 173 |
+ echo "$var=$pw" >> $localrc |
|
| 174 |
+ fi |
|
| 175 |
+ set -o xtrace |
|
| 176 |
+} |
|
| 177 |
+ |
|
| 178 |
+ |
|
| 142 | 179 |
# Nova Network Configuration |
| 143 | 180 |
# -------------------------- |
| 144 | 181 |
|
| ... | ... |
@@ -187,31 +227,32 @@ FLAT_INTERFACE=${FLAT_INTERFACE:-eth0}
|
| 187 | 187 |
|
| 188 | 188 |
# By default this script will install and configure MySQL. If you want to |
| 189 | 189 |
# use an existing server, you can pass in the user/password/host parameters. |
| 190 |
-# You will need to send the same ``MYSQL_PASS`` to every host if you are doing |
|
| 190 |
+# You will need to send the same ``MYSQL_PASSWORD`` to every host if you are doing |
|
| 191 | 191 |
# a multi-node devstack installation. |
| 192 | 192 |
MYSQL_USER=${MYSQL_USER:-root}
|
| 193 |
-MYSQL_PASS=${MYSQL_PASS:-`openssl rand -hex 12`}
|
|
| 193 |
+read_password MYSQL_PASSWORD "ENTER A PASSWORD TO USE FOR MYSQL." |
|
| 194 | 194 |
MYSQL_HOST=${MYSQL_HOST:-localhost}
|
| 195 | 195 |
|
| 196 | 196 |
# don't specify /db in this string, so we can use it for multiple services |
| 197 |
-BASE_SQL_CONN=${BASE_SQL_CONN:-mysql://$MYSQL_USER:$MYSQL_PASS@$MYSQL_HOST}
|
|
| 197 |
+BASE_SQL_CONN=${BASE_SQL_CONN:-mysql://$MYSQL_USER:$MYSQL_PASSWORD@$MYSQL_HOST}
|
|
| 198 | 198 |
|
| 199 | 199 |
# Rabbit connection info |
| 200 | 200 |
RABBIT_HOST=${RABBIT_HOST:-localhost}
|
| 201 | 201 |
RABBIT_PASSWORD=${RABBIT_PASSWORD:-`openssl rand -hex 12`}
|
| 202 |
+read_password RABBIT_PASSWORD "ENTER A PASSWORD TO USE FOR RABBIT." |
|
| 202 | 203 |
|
| 203 | 204 |
# Glance connection info. Note the port must be specified. |
| 204 | 205 |
GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$HOST_IP:9292}
|
| 205 | 206 |
|
| 207 |
+ |
|
| 206 | 208 |
# Keystone |
| 207 | 209 |
# -------- |
| 208 | 210 |
|
| 209 | 211 |
# Service Token - Openstack components need to have an admin token |
| 210 | 212 |
# to validate user tokens. |
| 211 |
-SERVICE_TOKEN=${SERVICE_TOKEN:-`openssl rand -hex 12`}
|
|
| 213 |
+read_password SERVICE_TOKEN "ENTER A SERVICE_TOKEN TO USE FOR THE SERVICE ADMIN TOKEN." |
|
| 212 | 214 |
# Dash currently truncates usernames and passwords at 20 characters |
| 213 |
-# so use 10 bytes |
|
| 214 |
-ADMIN_PASSWORD=${ADMIN_PASSWORD:-`openssl rand -hex 10`}
|
|
| 215 |
+read_password ADMIN_PASSWORD "ENTER A PASSWORD TO USE FOR DASH AND KEYSTONE (20 CHARS OR LESS)." |
|
| 215 | 216 |
|
| 216 | 217 |
LOGFILE=${LOGFILE:-"$PWD/stack.sh.$$.log"}
|
| 217 | 218 |
( |
| ... | ... |
@@ -313,8 +354,8 @@ if [[ "$ENABLED_SERVICES" =~ "mysql" ]]; then |
| 313 | 313 |
# Seed configuration with mysql password so that apt-get install doesn't |
| 314 | 314 |
# prompt us for a password upon install. |
| 315 | 315 |
cat <<MYSQL_PRESEED | sudo debconf-set-selections |
| 316 |
-mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS |
|
| 317 |
-mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS |
|
| 316 |
+mysql-server-5.1 mysql-server/root_password password $MYSQL_PASSWORD |
|
| 317 |
+mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASSWORD |
|
| 318 | 318 |
mysql-server-5.1 mysql-server/start_on_boot boolean true |
| 319 | 319 |
MYSQL_PRESEED |
| 320 | 320 |
|
| ... | ... |
@@ -325,7 +366,7 @@ MYSQL_PRESEED |
| 325 | 325 |
cat <<EOF >$HOME/.my.cnf |
| 326 | 326 |
[client] |
| 327 | 327 |
user=$MYSQL_USER |
| 328 |
-password=$MYSQL_PASS |
|
| 328 |
+password=$MYSQL_PASSWORD |
|
| 329 | 329 |
host=$MYSQL_HOST |
| 330 | 330 |
EOF |
| 331 | 331 |
chmod 0600 $HOME/.my.cnf |
| ... | ... |
@@ -334,7 +375,7 @@ EOF |
| 334 | 334 |
# Install and start mysql-server |
| 335 | 335 |
sudo apt-get -y -q install mysql-server |
| 336 | 336 |
# Update the DB to give user ‘$MYSQL_USER’@’%’ full control of the all databases: |
| 337 |
- sudo mysql -uroot -p$MYSQL_PASS -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' identified by '$MYSQL_PASS';" |
|
| 337 |
+ sudo mysql -uroot -p$MYSQL_PASSWORD -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' identified by '$MYSQL_PASSWORD';" |
|
| 338 | 338 |
|
| 339 | 339 |
# 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: |
| 340 | 340 |
sudo sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf |
| ... | ... |
@@ -385,8 +426,8 @@ if [[ "$ENABLED_SERVICES" =~ "g-reg" ]]; then |
| 385 | 385 |
mkdir -p $GLANCE_IMAGE_DIR |
| 386 | 386 |
|
| 387 | 387 |
# (re)create glance database |
| 388 |
- mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE IF EXISTS glance;' |
|
| 389 |
- mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE glance;' |
|
| 388 |
+ mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS glance;' |
|
| 389 |
+ mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE glance;' |
|
| 390 | 390 |
# Copy over our glance-registry.conf |
| 391 | 391 |
GLANCE_CONF=$GLANCE_DIR/etc/glance-registry.conf |
| 392 | 392 |
cp $FILES/glance-registry.conf $GLANCE_CONF |
| ... | ... |
@@ -515,8 +556,8 @@ fi |
| 515 | 515 |
|
| 516 | 516 |
if [[ "$ENABLED_SERVICES" =~ "mysql" ]]; then |
| 517 | 517 |
# (re)create nova database |
| 518 |
- mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE IF EXISTS nova;' |
|
| 519 |
- mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE nova;' |
|
| 518 |
+ mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS nova;' |
|
| 519 |
+ mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE nova;' |
|
| 520 | 520 |
|
| 521 | 521 |
# (re)create nova database |
| 522 | 522 |
$NOVA_DIR/bin/nova-manage db sync |
| ... | ... |
@@ -534,8 +575,8 @@ fi |
| 534 | 534 |
|
| 535 | 535 |
if [[ "$ENABLED_SERVICES" =~ "key" ]]; then |
| 536 | 536 |
# (re)create keystone database |
| 537 |
- mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'DROP DATABASE IF EXISTS keystone;' |
|
| 538 |
- mysql -u$MYSQL_USER -p$MYSQL_PASS -e 'CREATE DATABASE keystone;' |
|
| 537 |
+ mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS keystone;' |
|
| 538 |
+ mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'CREATE DATABASE keystone;' |
|
| 539 | 539 |
|
| 540 | 540 |
# FIXME (anthony) keystone should use keystone.conf.example |
| 541 | 541 |
KEYSTONE_CONF=$KEYSTONE_DIR/etc/keystone.conf |
| ... | ... |
@@ -619,55 +660,41 @@ screen_it dash "cd $DASH_DIR && sudo /etc/init.d/apache2 restart; sudo tail -f / |
| 619 | 619 |
# Install Images |
| 620 | 620 |
# ============== |
| 621 | 621 |
|
| 622 |
-# Upload a couple images to glance. **TTY** is a simple small image that use the |
|
| 623 |
-# lets you login to it with username/password of user/password. TTY is useful |
|
| 624 |
-# for basic functionality. We all include an Ubuntu cloud build of **Natty**. |
|
| 625 |
-# Natty uses cloud-init, supporting login via keypair and sending scripts as |
|
| 626 |
-# userdata. |
|
| 622 |
+# Upload an image to glance. |
|
| 623 |
+# |
|
| 624 |
+# The default image is a small ***TTY*** testing image, which lets you login |
|
| 625 |
+# the username/password of root/password. |
|
| 627 | 626 |
# |
| 628 |
-# Read more about cloud-init at https://help.ubuntu.com/community/CloudInit |
|
| 627 |
+# TTY also uses cloud-init, supporting login via keypair and sending scripts as |
|
| 628 |
+# userdata. See https://help.ubuntu.com/community/CloudInit for more on cloud-init |
|
| 629 |
+# |
|
| 630 |
+# Override IMAGE_URLS if you would to launch a different image(s). |
|
| 631 |
+# Specify IMAGE_URLS as a comma-separated list of uec urls. Some other options include: |
|
| 632 |
+# natty: http://uec-images.ubuntu.com/natty/current/natty-server-cloudimg-amd64.tar.gz |
|
| 633 |
+# oneiric: http://uec-images.ubuntu.com/oneiric/current/oneiric-server-cloudimg-amd64.tar.gz |
|
| 629 | 634 |
|
| 630 | 635 |
if [[ "$ENABLED_SERVICES" =~ "g-reg" ]]; then |
| 631 |
- # create a directory for the downloadedthe images tarballs. |
|
| 636 |
+ # Create a directory for the downloaded image tarballs. |
|
| 632 | 637 |
mkdir -p $FILES/images |
| 633 | 638 |
|
| 634 |
- # Debug Image (TTY) |
|
| 635 |
- # ----------------- |
|
| 636 |
- |
|
| 637 |
- # Downloads the image (ami/aki/ari style), then extracts it. Upon extraction |
|
| 638 |
- # we upload to glance with the glance cli tool. TTY is a stripped down |
|
| 639 |
- # version of ubuntu. |
|
| 640 |
- if [ ! -f $FILES/tty.tgz ]; then |
|
| 641 |
- wget -c http://images.ansolabs.com/tty.tgz -O $FILES/tty.tgz |
|
| 642 |
- fi |
|
| 643 |
- |
|
| 644 |
- # extract ami-tty/image, aki-tty/image & ari-tty/image |
|
| 645 |
- tar -zxf $FILES/tty.tgz -C $FILES/images |
|
| 646 |
- |
|
| 647 |
- # Use glance client to add the kernel, ramdisk and finally the root |
|
| 648 |
- # filesystem. We parse the results of the uploads to get glance IDs of the |
|
| 649 |
- # ramdisk and kernel and use them for the root filesystem. |
|
| 650 |
- RVAL=`glance add -A $SERVICE_TOKEN name="tty-kernel" is_public=true container_format=aki disk_format=aki < $FILES/images/aki-tty/image` |
|
| 651 |
- KERNEL_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "` |
|
| 652 |
- RVAL=`glance add -A $SERVICE_TOKEN name="tty-ramdisk" is_public=true container_format=ari disk_format=ari < $FILES/images/ari-tty/image` |
|
| 653 |
- RAMDISK_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "` |
|
| 654 |
- 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 |
|
| 655 |
- |
|
| 656 |
- # Ubuntu 11.04 aka Natty |
|
| 657 |
- # ---------------------- |
|
| 658 |
- |
|
| 659 |
- # Downloaded from ubuntu enterprise cloud images. This |
|
| 660 |
- # image doesn't use the ramdisk functionality |
|
| 661 |
- if [ ! -f $FILES/natty.tgz ]; then |
|
| 662 |
- wget -c http://uec-images.ubuntu.com/natty/current/natty-server-cloudimg-amd64.tar.gz -O $FILES/natty.tgz |
|
| 663 |
- fi |
|
| 664 |
- |
|
| 665 |
- tar -zxf $FILES/natty.tgz -C $FILES/images |
|
| 639 |
+ for image_url in ${IMAGE_URLS//,/ }; do
|
|
| 640 |
+ # Downloads the image (uec ami+aki style), then extracts it. |
|
| 641 |
+ IMAGE_FNAME=`echo "$image_url" | python -c "import sys; print sys.stdin.read().split('/')[-1]"`
|
|
| 642 |
+ IMAGE_NAME=`echo "$IMAGE_FNAME" | python -c "import sys; print sys.stdin.read().split('.tar.gz')[0].split('.tgz')[0]"`
|
|
| 643 |
+ if [ ! -f $FILES/$IMAGE_FNAME ]; then |
|
| 644 |
+ wget -c $image_url -O $FILES/$IMAGE_FNAME |
|
| 645 |
+ fi |
|
| 666 | 646 |
|
| 667 |
- 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` |
|
| 668 |
- KERNEL_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "` |
|
| 669 |
- 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 |
|
| 647 |
+ # Extract ami and aki files |
|
| 648 |
+ tar -zxf $FILES/$IMAGE_FNAME -C $FILES/images |
|
| 670 | 649 |
|
| 650 |
+ # Use glance client to add the kernel the root filesystem. |
|
| 651 |
+ # We parse the results of the first upload to get the glance ID of the |
|
| 652 |
+ # kernel for use when uploading the root filesystem. |
|
| 653 |
+ RVAL=`glance add -A $SERVICE_TOKEN name="$IMAGE_NAME-kernel" is_public=true container_format=aki disk_format=aki < $FILES/images/$IMAGE_NAME-vmlinuz*` |
|
| 654 |
+ KERNEL_ID=`echo $RVAL | cut -d":" -f2 | tr -d " "` |
|
| 655 |
+ 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 |
|
| 656 |
+ done |
|
| 671 | 657 |
fi |
| 672 | 658 |
|
| 673 | 659 |
# Fin |
| ... | ... |
@@ -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 |
| 0 | 39 |
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 |
+ |