Merge remote-tracking branch 'upstream/master'
diff --git a/.gitignore b/.gitignore
index 7964faa..22a7898 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 proto
 *~
+localrc
diff --git a/build_lxc.sh b/build_lxc.sh
index a13ca35..191c493 100755
--- a/build_lxc.sh
+++ b/build_lxc.sh
@@ -1,5 +1,16 @@
 #!/usr/bin/env bash
 
+# Sanity check
+if [ "$EUID" -ne "0" ]; then
+  echo "This script must be run with root privileges."
+  exit 1
+fi
+
+# Warn users who aren't on natty
+if ! grep -q natty /etc/lsb-release; then
+    echo "WARNING: this script has only been tested on natty"
+fi
+
 # Source params
 source ./stackrc
 
@@ -23,18 +34,14 @@
 # Option to use the version of devstack on which we are currently working
 USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
 
-# Warn users who aren't on natty
-if ! grep -q natty /etc/lsb-release; then
-    echo "WARNING: this script has only been tested on natty"
-fi
 
 # Install deps
 apt-get install -y lxc debootstrap
 
 # Install cgroup-bin from source, since the packaging is buggy and possibly incompatible with our setup
 if ! which cgdelete | grep -q cgdelete; then
-    apt-get install -y g++ bison flex libpam0g-dev
-    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 
+    apt-get install -y g++ bison flex libpam0g-dev make
+    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
     cd /tmp && bunzip2 libcgroup-0.37.1.tar.bz2  && tar xfv libcgroup-0.37.1.tar
     cd libcgroup-0.37.1
     ./configure
@@ -75,17 +82,25 @@
     fi
 }
 
-# Warm the base image on first install
+# Location of the base image directory
 CACHEDIR=/var/cache/lxc/natty/rootfs-amd64
-if [ ! -d $CACHEDIR ]; then
+
+# Provide option to do totally clean install
+if [ "$CLEAR_LXC_CACHE" = "1" ]; then
+    rm -rf $CACHEDIR
+fi
+
+# Warm the base image on first install
+if [ ! -f $CACHEDIR/bootstrapped ]; then
     # by deleting the container, we force lxc-create to re-bootstrap (lxc is
     # lazy and doesn't do anything if a container already exists)
     lxc-destroy -n $CONTAINER
     # trigger the initial debootstrap
     lxc-create -n $CONTAINER -t natty -f $LXC_CONF
     chroot $CACHEDIR apt-get update
-    chroot $CACHEDIR apt-get install -y --force-yes `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
+    chroot $CACHEDIR apt-get install -y --force-yes `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server|munin-node)"`
     chroot $CACHEDIR pip install `cat files/pips/*`
+    touch $CACHEDIR/bootstrapped
 fi
 
 # Clean out code repos if directed to do so
@@ -125,7 +140,7 @@
 # Specify where our container rootfs lives
 ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/
 
-# Create a stack user that is a member of the libvirtd group so that stack 
+# Create a stack user that is a member of the libvirtd group so that stack
 # is able to interact with libvirt.
 chroot $ROOTFS groupadd libvirtd
 chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd
@@ -133,7 +148,7 @@
 # a simple password - pass
 echo stack:pass | chroot $ROOTFS chpasswd
 
-# and has sudo ability (in the future this should be limited to only what 
+# and has sudo ability (in the future this should be limited to only what
 # stack requires)
 echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers
 
@@ -145,7 +160,7 @@
 # Gracefully cp only if source file/dir exists
 function cp_it {
     if [ -e $1 ] || [ -d $1 ]; then
-        cp -pr $1 $2
+        cp -pRL $1 $2
     fi
 }
 
@@ -196,6 +211,9 @@
     git clone git://github.com/cloudbuilders/devstack.git $DEST/devstack
 fi
 cd $DEST/devstack && $STACKSH_PARAMS ./stack.sh > /$DEST/run.sh.log
+echo >> /$DEST/run.sh.log
+echo >> /$DEST/run.sh.log
+echo "All done! Time to start clicking." >> /$DEST/run.sh.log
 EOF
 
 # Make the run.sh executable
@@ -216,3 +234,20 @@
 
 # Start our container
 lxc-start -d -n $CONTAINER
+
+# Done creating the container, let's tail the log
+echo
+echo "============================================================="
+echo "                          -- YAY! --"
+echo "============================================================="
+echo
+echo "We're done creating the container, about to start tailing the"
+echo "stack.sh log. It will take a second or two to start."
+echo
+echo "Just CTRL-C at any time to stop tailing."
+
+while [ ! -e "$ROOTFS/$DEST/run.sh.log" ]; do
+  sleep 1
+done
+
+tail -F $ROOTFS/$DEST/run.sh.log
diff --git a/build_pxe_ramdisk.sh b/build_pxe_ramdisk.sh
index 0f598f8..648fc3b 100755
--- a/build_pxe_ramdisk.sh
+++ b/build_pxe_ramdisk.sh
@@ -14,7 +14,7 @@
     debootstrap natty natty-base
     # copy kernel modules...  
     # NOTE(ja): is there a better way to do this?
-    cp -pr /lib/modules/`uname -r` proto/lib/modules
+    cp -pr /lib/modules/`uname -r` natty-base/lib/modules
     cp files/sources.list natty-base/etc/apt/sources.list
     chroot natty-base apt-get update
 fi
@@ -89,8 +89,8 @@
 IMG=$BASE.img
 MNT=$BASE/
 
-# create a 2GB blank filesystem
-dd if=/dev/zero of=$IMG bs=1024k count=2048
+# (quickly) create a 2GB blank filesystem
+dd bs=1 count=1 seek=$((2*1024*1024*1024)) if=/dev/zero of=$IMG
 # force it to be initialized as ext2
 mkfs.ext2 -F $IMG
 
diff --git a/lxc_network_hostonlyplusnat.sh b/lxc_network_hostonlyplusnat.sh
new file mode 100755
index 0000000..4e29ed7
--- /dev/null
+++ b/lxc_network_hostonlyplusnat.sh
@@ -0,0 +1,93 @@
+#!/bin/bash
+
+# Print some usage info
+function usage {
+  echo "Usage: $0 [OPTION] [host_ip]"
+  echo "Set up temporary networking for LXC"
+  echo ""
+  echo "  -n, --dry-run            Just print the commands that would execute."
+  echo "  -h, --help               Print this usage message."
+  echo ""
+  exit
+}
+
+# Allow passing the ip address on the command line.
+function process_option {
+  case "$1" in
+    -h|--help) usage;;
+    -n|--dry-run) dry_run=1;;
+    *) host_ip="$1"
+  esac
+}
+
+# Set up some defaults
+host_ip=
+dry_run=0
+bridge=br0
+DRIER=
+
+# Process the args
+for arg in "$@"; do
+  process_option $arg
+done
+
+if [ $dry_run ]; then
+  DRIER=echo
+fi
+
+if [ "$UID" -ne "0" ]; then
+  echo "This script must be run with root privileges."
+  exit 1
+fi
+
+# Check for bridge-utils.
+BRCTL=`which brctl`
+if [ ! -x "$BRCTL" ]; then
+  echo "This script requires you to install bridge-utils."
+  echo "Try: sudo apt-get install bridge-utils."
+  exit 1
+fi
+
+# Scare off the nubs.
+echo "====================================================="
+echo
+echo "WARNING"
+echo
+echo "This script will modify your current network setup,"
+echo "this can be a scary thing and it is recommended that"
+echo "you have something equivalent to physical access to"
+echo "this machine before continuing in case your network"
+echo "gets all funky."
+echo
+echo "If you don't want to continue, hit CTRL-C now."
+
+if [ -z "$host_ip" ];
+then
+  echo "Otherwise, please type in your host's ip address and"
+  echo "hit enter."
+  echo
+  echo "====================================================="
+  read host_ip
+else
+  echo "Otherwise hit enter."
+  echo
+  echo "====================================================="
+  read accept
+fi
+
+
+# Add a bridge interface, this will choke if there is already
+# a bridge named $bridge
+$DRIER $BRCTL addbr $bridge
+$DRIER ip addr add 192.168.1.1/24 dev $bridge
+if [ $dry_run ]; then
+  echo "echo 1 > /proc/sys/net/ipv4/ip_forward"
+else
+  echo 1 > /proc/sys/net/ipv4/ip_forward
+fi
+$DRIER ifconfig $bridge up
+
+# Set up the NAT for the instances
+$DRIER iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source $host_ip
+$DRIER iptables -I FORWARD -s 192.168.1.0/24 -j ACCEPT
+
diff --git a/stack.sh b/stack.sh
index f21b371..4daa95d 100755
--- a/stack.sh
+++ b/stack.sh
@@ -13,6 +13,9 @@
 # Sanity Check
 # ============
 
+# Start our timer
+START_TIME=`python -c "import time; print time.time()"`
+
 # Warn users who aren't on natty, but allow them to override check and attempt
 # installation with ``FORCE=yes ./stack``
 if ! grep -q natty /etc/lsb-release; then
@@ -37,6 +40,15 @@
     exit 1
 fi
 
+# you need to run this as a regular user with sudo priviledges
+if [[ $EUID -eq 0 ]]; then
+   echo "This script cannot be run as root." 1>&2
+   echo "You should run this script as the user you wish openstack to run as" 1>&2
+   echo "The user will need to be a sudoer (without password)" 1>&2
+   exit 1
+fi
+
+
 # Settings
 # ========
 
@@ -48,6 +60,11 @@
 #
 # You can also pass options on a single line ``MYSQL_PASS=simple ./stack.sh``
 #
+# Additionally, you can put any local variables into a ``localrc`` file, like::
+#
+#     MYSQL_PASS=anothersecret
+#     MYSQL_USER=hellaroot
+#
 # We try to have sensible defaults, so you should be able to run ``./stack.sh``
 # in most cases.
 
@@ -377,7 +394,7 @@
     $NOVA_DIR/bin/nova-manage db sync
 
     # create a small network
-    $NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 $FIXED_NETWORK_SIZE 
+    $NOVA_DIR/bin/nova-manage network create private $FIXED_RANGE 1 $FIXED_NETWORK_SIZE
 
     # create some floating ips
     $NOVA_DIR/bin/nova-manage floating create $FLOATING_RANGE
@@ -500,3 +517,11 @@
     echo "keystone is serving at http://$HOST_IP:5000/v2.0/"
     echo "examples on using novaclient command line is in exercise.sh"
 fi
+
+# Summary
+# =======
+
+# End our timer and give a timing summary
+END_TIME=`python -c "import time; print time.time()"`
+ELAPSED=`python -c "print $END_TIME - $START_TIME"`
+echo "stack.sh completed in $ELAPSED seconds."
diff --git a/stackrc b/stackrc
index 2d265d3..deb467b 100644
--- a/stackrc
+++ b/stackrc
@@ -1,6 +1,6 @@
 # compute service
-NOVA_REPO=https://github.com/openstack/nova.git
-NOVA_BRANCH=2011.3
+NOVA_REPO=https://github.com/cloudbuilders/nova.git
+NOVA_BRANCH=diablo
 
 # image catalog service
 GLANCE_REPO=https://github.com/cloudbuilders/glance.git
@@ -34,3 +34,8 @@
 # openstack-munin is a collection of munin plugins for monitoring the stack
 MUNIN_REPO=https://github.com/cloudbuilders/openstack-munin.git
 MUNIN_BRANCH=master
+
+# allow local overrides of env variables
+if [ -f ./localrc ]; then
+    source ./localrc
+fi