Merge "Add configurable use of veths with Quantum+OVS."
diff --git a/files/apts/nova b/files/apts/nova
index f4615c4..298e25f 100644
--- a/files/apts/nova
+++ b/files/apts/nova
@@ -2,8 +2,7 @@
 dnsmasq-utils # for dhcp_release only available in dist:oneiric,precise,quantal
 kpartx
 parted
-arping # only available in dist:natty
-iputils-arping # only available in dist:oneiric
+iputils-arping
 mysql-server # NOPRIME
 python-mysqldb
 python-xattr # needed for glance which is needed for nova --- this shouldn't be here
diff --git a/files/rpms/general b/files/rpms/general
index fc3412b..764b602 100644
--- a/files/rpms/general
+++ b/files/rpms/general
@@ -1,14 +1,19 @@
 bridge-utils
 curl
+dbus
 euca2ools # only for testing client
+gcc # dist:rhel6 [2]
 git-core
 openssh-server
 openssl
+libxml2-devel # dist:rhel6 [2]
+libxslt-devel # dist:rhel6 [2]
 psmisc
 pylint
 python-netaddr
 python-pep8
 python-pip
+python-prettytable # dist:rhel6 [1]
 python-unittest2
 python-virtualenv
 screen
@@ -16,3 +21,12 @@
 tcpdump
 unzip
 wget
+
+# [1] : some of installed tools have unversioned dependencies on this,
+# but others have versioned (<=0.7).  So if a later version (0.7.1)
+# gets installed in response to an unversioned dependency, it breaks.
+# This pre-installs a compatible 0.6(ish) version from RHEL
+
+# [2] : RHEL6 rpm versions of python-lxml is old, and has to be
+# removed.  Several tools rely on it, so we install the dependencies
+# pip needs to build it here (see tools/install_prereqs.sh)
\ No newline at end of file
diff --git a/files/rpms/glance b/files/rpms/glance
index 34e3f9a..097cf3f 100644
--- a/files/rpms/glance
+++ b/files/rpms/glance
@@ -1,3 +1,4 @@
+gcc
 libxml2-devel
 python-argparse
 python-devel
diff --git a/lib/database b/lib/database
index e63d5e2..442ed56 100644
--- a/lib/database
+++ b/lib/database
@@ -38,7 +38,7 @@
 for db in $DATABASE_BACKENDS; do
     # Set the type for the rest of the backend to use
     if is_service_enabled $db; then
-        # Set this now for the rest of the database funtions
+        # Set this now for the rest of the database functions
         DATABASE_TYPE=$db
     fi
 done
@@ -110,13 +110,11 @@
     configure_database_$DATABASE_TYPE
 }
 
-# Generate an SQLAlchemy connection URL and store it in a variable
-#  $1 The variable name in which to store the connection URL
-#  $2 The name of the database
+# Generate an SQLAlchemy connection URL and output it using echo
+#  $1 The name of the database
 function database_connection_url {
-    local var=$1
-    local db=$2
-    database_connection_url_$DATABASE_TYPE $var $db
+    local db=$1
+    database_connection_url_$DATABASE_TYPE $db
 }
 
 
diff --git a/lib/horizon b/lib/horizon
index 05bf6d3..3d8b3e6 100644
--- a/lib/horizon
+++ b/lib/horizon
@@ -61,16 +61,47 @@
     fi
 }
 
+# Basic install of upstream nodejs for platforms that want it
+function install_nodejs() {
+    if [[ $(which node) ]]; then
+        echo "You already appear to have nodejs, skipping install"
+        return
+    fi
+
+    # There are several node deployment scripts; one may be more
+    # appropriate at some future point, but for now direct download is
+    # the simplest way.  The version barely matters for lesscss which
+    # doesn't use anything fancy.
+    local ver=0.10.1
+    local nodejs=node-v${ver}-linux-x64
+    local tar=$nodejs.tar.gz
+    local nodejs_url=http://nodejs.org/dist/v${ver}/${tar}
+
+    curl -Ss ${nodejs_url} | tar -C ${DEST} -xz
+    if [ $? -ne 0 ]; then
+        echo "*** Download of nodejs failed"
+        return 1
+    fi
+
+    # /usr/bin so it gets found in the PATH available to horizon
+    sudo ln -s $DEST/$nodejs/bin/node /usr/bin/node
+}
+
 # Entry Points
 # ------------
 
 # cleanup_horizon() - Remove residual data files, anything left over from previous
 # runs that a clean run would need to clean up
 function cleanup_horizon() {
-    # kill instances (nova)
-    # delete image files (glance)
-    # This function intentionally left blank
-    :
+
+    if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
+    # if the /usr/bin/node link looks like it's pointing into $DEST,
+    # then we installed it via install_nodejs
+        if [[ $(readlink -f /usr/bin/node) =~ ($DEST) ]]; then
+            sudo rm /usr/bin/node
+        fi
+    fi
+
 }
 
 # configure_horizon() - Set config files, create data dirs, etc
@@ -159,6 +190,14 @@
         exit_distro_not_supported "apache installation"
     fi
 
+    if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
+        # RHEL6 currently has no native way to get nodejs, so we do a
+        # basic install here (see cleanup_horizon too).
+        # TODO: does nova have a better way that we can limit
+        # requirement of site-wide nodejs install?
+        install_nodejs
+    fi
+
     # NOTE(sdague) quantal changed the name of the node binary
     if is_ubuntu; then
         if [[ ! -e "/usr/bin/node" ]]; then
diff --git a/lib/nova b/lib/nova
index ea73bad..f28094e 100644
--- a/lib/nova
+++ b/lib/nova
@@ -296,10 +296,32 @@
 
 
 
-        if is_fedora; then
-            # Starting with fedora 18 enable stack-user to virsh -c qemu:///system
-            # by creating a policy-kit rule for stack-user
-            if [[ "$os_RELEASE" -ge "18" ]]; then
+        if is_fedora || is_suse; then
+            if is_fedora && [[ "$os_RELEASE" -le "17" ]]; then
+                sudo bash -c 'cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
+[libvirt Management Access]
+Identity=unix-group:libvirtd
+Action=org.libvirt.unix.manage
+ResultAny=yes
+ResultInactive=yes
+ResultActive=yes
+EOF'
+            elif is_suse && [[ $os_RELEASE = 12.2 || "$os_VENDOR" = "SUSE LINUX" ]]; then
+                # openSUSE < 12.3 or SLE
+                # Work around the fact that polkit-default-privs overrules pklas
+                # with 'unix-group:$group'.
+                sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
+[libvirt Management Access]
+Identity=unix-user:$USER
+Action=org.libvirt.unix.manage
+ResultAny=yes
+ResultInactive=yes
+ResultActive=yes
+EOF"
+            else
+                # Starting with fedora 18 and opensuse-12.3 enable stack-user to
+                # virsh -c qemu:///system by creating a policy-kit rule for
+                # stack-user using the new Javascript syntax
                 rules_dir=/etc/polkit-1/rules.d
                 sudo mkdir -p $rules_dir
                 sudo bash -c "cat <<EOF > $rules_dir/50-libvirt-$STACK_USER.rules
@@ -311,27 +333,7 @@
 });
 EOF"
                 unset rules_dir
-            else
-                sudo bash -c 'cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
-[libvirt Management Access]
-Identity=unix-group:libvirtd
-Action=org.libvirt.unix.manage
-ResultAny=yes
-ResultInactive=yes
-ResultActive=yes
-EOF'
             fi
-        elif is_suse; then
-            # Work around the fact that polkit-default-privs overrules pklas
-            # with 'unix-group:$group'.
-            sudo bash -c "cat <<EOF >/etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla
-[libvirt Management Access]
-Identity=unix-user:$USER
-Action=org.libvirt.unix.manage
-ResultAny=yes
-ResultInactive=yes
-ResultActive=yes
-EOF"
         fi
 
         # The user that nova runs as needs to be member of **libvirtd** group otherwise
diff --git a/stack.sh b/stack.sh
index e192588..d534b87 100755
--- a/stack.sh
+++ b/stack.sh
@@ -525,7 +525,6 @@
 # an error.  It is also useful for following along as the install occurs.
 set -o xtrace
 
-
 # Install Packages
 # ================
 
@@ -546,6 +545,42 @@
     install_quantum_agent_packages
 fi
 
+#
+# System-specific preconfigure
+# ============================
+
+if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
+    # An old version (2.0.1) of python-crypto is probably installed on
+    # a fresh system, via the dependency chain
+    # cas->python-paramiko->python-crypto (related to anaconda).
+    # Unfortunately, "pip uninstall pycrypto" will remove the
+    # .egg-info file for this rpm-installed version, but leave most of
+    # the actual library files behind in /usr/lib64/python2.6/Crypto.
+    # When later "pip install pycrypto" happens, the built library
+    # will be installed over these existing files; the result is a
+    # useless mess of old, rpm-packaged files and pip-installed files.
+    # Unsurprisingly, the end result is it doesn't work.  Thus we have
+    # to get rid of it now so that any packages that pip-install
+    # pycrypto get a "clean slate".
+    # (note, we have to be careful about other RPM packages specified
+    # pulling in python-crypto as well.  That's why RHEL6 doesn't
+    # install python-paramiko packages for example...)
+    uninstall_package python-crypto
+
+    # A similar thing happens for python-lxml (a dependency of
+    # ipa-client, an auditing thing we don't care about).  We have the
+    # build-dependencies the lxml pip-install will need (gcc,
+    # libxml2-dev & libxslt-dev) in the "general" rpm lists
+    uninstall_package python-lxml
+
+    # If the dbus rpm was installed by the devstack rpm dependencies
+    # then you may hit a bug where the uuid isn't generated because
+    # the service was never started (PR#598200), causing issues for
+    # Nova stopping later on complaining that
+    # '/var/lib/dbus/machine-id' doesn't exist.
+    sudo service messagebus restart
+fi
+
 TRACK_DEPENDS=${TRACK_DEPENDS:-False}
 
 # Install python packages into a virtualenv so that we can track them
@@ -559,7 +594,6 @@
     $DEST/.venv/bin/pip freeze > $DEST/requires-pre-pip
 fi
 
-
 # Check Out and Install Source
 # ----------------------------
 
diff --git a/tools/install_prereqs.sh b/tools/install_prereqs.sh
index 7c4386f..68f11ce 100755
--- a/tools/install_prereqs.sh
+++ b/tools/install_prereqs.sh
@@ -42,7 +42,8 @@
 LAST_RUN=$(head -1 $PREREQ_RERUN_MARKER 2>/dev/null || echo "0")
 DELTA=$(($NOW - $LAST_RUN))
 if [[ $DELTA -lt $PREREQ_RERUN_SECONDS && -z "$FORCE_PREREQ" ]]; then
-    echo "Re-run time has not expired ($(($PREREQ_RERUN_SECONDS - $DELTA)) seconds remaining); exiting..."
+    echo "Re-run time has not expired ($(($PREREQ_RERUN_SECONDS - $DELTA)) seconds remaining) "
+    echo "and FORCE_PREREQ not set; exiting..."
     return 0
 fi
 
diff --git a/tools/xen/README.md b/tools/xen/README.md
index 1cd45cf..3fadc78 100644
--- a/tools/xen/README.md
+++ b/tools/xen/README.md
@@ -57,8 +57,12 @@
     MULTI_HOST=1
     # Give extra time for boot
     ACTIVE_TIMEOUT=45
-    # Interface on which you would like to access services
-    HOST_IP_IFACE=ethX
+    # Host Interface, i.e. the interface on the nova vm you want to expose the
+    # services on. Usually eth2 (management network) or eth3 (public network) and
+    # not eth0 (private network with XenServer host) or eth1 (VM traffic network)
+    # This is also used as the interface for the Ubuntu install
+    # The default is eth3.
+    # HOST_IP_IFACE=eth3
     # First time Ubuntu network install params
     NETINSTALLIP="dhcp"
     NAMESERVERS=""