Merge "Disable non-dhcp resolv.conf"
diff --git a/files/apts/ryu b/files/apts/ryu
index 1e8f2d2..4a4fc52 100644
--- a/files/apts/ryu
+++ b/files/apts/ryu
@@ -1,4 +1,5 @@
 python-setuptools
 python-gevent
 python-gflags
+python-netifaces
 python-sphinx
diff --git a/files/rpms/ryu b/files/rpms/ryu
index 1e8f2d2..4a4fc52 100644
--- a/files/rpms/ryu
+++ b/files/rpms/ryu
@@ -1,4 +1,5 @@
 python-setuptools
 python-gevent
 python-gflags
+python-netifaces
 python-sphinx
diff --git a/functions b/functions
index 68aec5d..3f26b7f 100644
--- a/functions
+++ b/functions
@@ -80,6 +80,27 @@
 }
 
 
+# HTTP and HTTPS proxy servers are supported via the usual environment variables [1]
+# ``http_proxy``, ``https_proxy`` and ``no_proxy``. They can be set in
+# ``localrc`` or on the command line if necessary::
+#
+# [1] http://www.w3.org/Daemon/User/Proxies/ProxyClients.html
+#
+#     http_proxy=http://proxy.example.com:3128/ no_proxy=repo.example.net ./stack.sh
+
+function export_proxy_variables() {
+    if [[ -n "$http_proxy" ]]; then
+        export http_proxy=$http_proxy
+    fi
+    if [[ -n "$https_proxy" ]]; then
+        export https_proxy=$https_proxy
+    fi
+    if [[ -n "$no_proxy" ]]; then
+        export no_proxy=$no_proxy
+    fi
+}
+
+
 # Grab a numbered field from python prettytable output
 # Fields are numbered starting with 1
 # Reverse syntax is supported: -1 is the last field, -2 is second to last, etc.
diff --git a/lib/baremetal b/lib/baremetal
index 3cc2429..7c31d1f 100644
--- a/lib/baremetal
+++ b/lib/baremetal
@@ -90,6 +90,9 @@
     BM_DNSMASQ_RANGE=${BM_DNSMASQ_RANGE:-}
 fi
 
+# BM_DNSMASQ_DNS provide dns server to bootstrap clients
+BM_DNSMASQ_DNS=${BM_DNSMASQ_DNS:-}
+
 # BM_FIRST_MAC *must* be set to the MAC address of the node you will boot.
 #              This is passed to dnsmasq along with the kernel/ramdisk to
 #              deploy via PXE.
diff --git a/lib/ceilometer b/lib/ceilometer
index 41a5f53..bc37d92 100644
--- a/lib/ceilometer
+++ b/lib/ceilometer
@@ -73,6 +73,7 @@
 
     # Install the policy file for the API server
     cp $CEILOMETER_DIR/etc/ceilometer/policy.json $CEILOMETER_CONF_DIR
+    cp $CEILOMETER_DIR/etc/ceilometer/pipeline.yaml $CEILOMETER_CONF_DIR
     iniset $CEILOMETER_CONF DEFAULT policy_file $CEILOMETER_CONF_DIR/policy.json
 
     # the compute and central agents need these credentials in order to
diff --git a/lib/quantum_plugins/bigswitch_floodlight b/lib/quantum_plugins/bigswitch_floodlight
index 35276a5..2c928be 100644
--- a/lib/quantum_plugins/bigswitch_floodlight
+++ b/lib/quantum_plugins/bigswitch_floodlight
@@ -2,7 +2,7 @@
 # ------------------------------------
 
 # Save trace setting
-XTRACE=$(set +o | grep xtrace)
+MY_XTRACE=$(set +o | grep xtrace)
 set +o xtrace
 
 source $TOP_DIR/lib/quantum_plugins/ovs_base
@@ -52,4 +52,4 @@
 }
 
 # Restore xtrace
-$XTRACE
+$MY_XTRACE
diff --git a/lib/quantum_plugins/linuxbridge b/lib/quantum_plugins/linuxbridge
index e8ba68c..6d5d4e0 100644
--- a/lib/quantum_plugins/linuxbridge
+++ b/lib/quantum_plugins/linuxbridge
@@ -2,7 +2,7 @@
 # ---------------------------
 
 # Save trace setting
-XTRACE=$(set +o | grep xtrace)
+MY_XTRACE=$(set +o | grep xtrace)
 set +o xtrace
 
 function is_quantum_ovs_base_plugin() {
@@ -76,4 +76,4 @@
 }
 
 # Restore xtrace
-$XTRACE
+$MY_XTRACE
diff --git a/lib/quantum_plugins/openvswitch b/lib/quantum_plugins/openvswitch
index 5415e86..12bc244 100644
--- a/lib/quantum_plugins/openvswitch
+++ b/lib/quantum_plugins/openvswitch
@@ -2,7 +2,7 @@
 # ---------------------------
 
 # Save trace setting
-XTRACE=$(set +o | grep xtrace)
+MY_XTRACE=$(set +o | grep xtrace)
 set +o xtrace
 
 source $TOP_DIR/lib/quantum_plugins/ovs_base
@@ -141,4 +141,4 @@
 }
 
 # Restore xtrace
-$XTRACE
+$MY_XTRACE
diff --git a/lib/quantum_plugins/ovs_base b/lib/quantum_plugins/ovs_base
index d9f6fd0..8563674 100644
--- a/lib/quantum_plugins/ovs_base
+++ b/lib/quantum_plugins/ovs_base
@@ -2,7 +2,7 @@
 # -------------------------------------
 
 # Save trace setting
-XTRACE=$(set +o | grep xtrace)
+MY_XTRACE=$(set +o | grep xtrace)
 set +o xtrace
 
 function is_quantum_ovs_base_plugin() {
@@ -12,7 +12,7 @@
 
 function _quantum_ovs_base_setup_bridge() {
     local bridge=$1
-    quantum-ovs-cleanup --ovs_integration_bridge $bridge
+    quantum-ovs-cleanup
     sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge
     sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge
 }
@@ -39,11 +39,11 @@
 function _quantum_ovs_base_configure_l3_agent() {
     iniset $Q_L3_CONF_FILE DEFAULT external_network_bridge $PUBLIC_BRIDGE
 
-    quantum-ovs-cleanup --external_network_bridge $PUBLIC_BRIDGE
+    quantum-ovs-cleanup
     sudo ovs-vsctl --no-wait -- --may-exist add-br $PUBLIC_BRIDGE
     # ensure no IP is configured on the public bridge
     sudo ip addr flush dev $PUBLIC_BRIDGE
 }
 
 # Restore xtrace
-$XTRACE
+$MY_XTRACE
diff --git a/lib/quantum_plugins/ryu b/lib/quantum_plugins/ryu
index 86105bc..2dfd4f7 100644
--- a/lib/quantum_plugins/ryu
+++ b/lib/quantum_plugins/ryu
@@ -2,7 +2,7 @@
 # ------------------
 
 # Save trace setting
-XTRACE=$(set +o | grep xtrace)
+MY_XTRACE=$(set +o | grep xtrace)
 set +o xtrace
 
 source $TOP_DIR/lib/quantum_plugins/ovs_base
@@ -15,6 +15,9 @@
 
 function quantum_plugin_install_agent_packages() {
     _quantum_ovs_base_install_agent_packages
+
+    # quantum_ryu_agent requires ryu module
+    install_ryu
 }
 
 function quantum_plugin_configure_common() {
@@ -60,4 +63,4 @@
 }
 
 # Restore xtrace
-$XTRACE
+$MY_XTRACE
diff --git a/lib/quantum_thirdparty/bigswitch_floodlight b/lib/quantum_thirdparty/bigswitch_floodlight
index 77aeb61..60e3924 100644
--- a/lib/quantum_thirdparty/bigswitch_floodlight
+++ b/lib/quantum_thirdparty/bigswitch_floodlight
@@ -2,7 +2,7 @@
 # ------------------------------------------
 
 # Save trace setting
-XTRACE=$(set +o | grep xtrace)
+MY_XTRACE=$(set +o | grep xtrace)
 set +o xtrace
 
 BS_FL_CONTROLLERS_PORT=${BS_FL_CONTROLLERS_PORT:-localhost:80}
@@ -47,4 +47,4 @@
 }
 
 # Restore xtrace
-$XTRACE
+$MY_XTRACE
diff --git a/lib/quantum_thirdparty/ryu b/lib/quantum_thirdparty/ryu
index f11951a..7a01923 100644
--- a/lib/quantum_thirdparty/ryu
+++ b/lib/quantum_thirdparty/ryu
@@ -2,7 +2,7 @@
 # -----------------------
 
 # Save trace setting
-XTRACE=$(set +o | grep xtrace)
+MY_XTRACE=$(set +o | grep xtrace)
 set +o xtrace
 
 
@@ -49,8 +49,16 @@
     echo "${RYU_CONF_CONTENTS}" > $RYU_CONF
 }
 
+# install_ryu can be called multiple times as quantum_pluing/ryu may call
+# this function for quantum-ryu-agent
+# Make this function idempotent and avoid cloning same repo many times
+# with RECLONE=yes
+_RYU_INSTALLED=${_RYU_INSTALLED:-False}
 function install_ryu() {
-    git_clone $RYU_REPO $RYU_DIR $RYU_BRANCH
+    if [[ "$_RYU_INSTALLED" == "False" ]]; then
+        git_clone $RYU_REPO $RYU_DIR $RYU_BRANCH
+        _RYU_INSTALLED=True
+    fi
 }
 
 function start_ryu() {
@@ -62,4 +70,4 @@
 }
 
 # Restore xtrace
-$XTRACE
+$MY_XTRACE
diff --git a/stack.sh b/stack.sh
index 0521ced..c1525bd 100755
--- a/stack.sh
+++ b/stack.sh
@@ -30,9 +30,8 @@
 GetDistro
 
 
-
-# Settings
-# ========
+# Global Settings
+# ===============
 
 # ``stack.sh`` is customizable through setting environment variables.  If you
 # want to override a setting you can set and export it::
@@ -62,33 +61,18 @@
 source $TOP_DIR/stackrc
 
 
-# Proxy Settings
+# Local Settings
 # --------------
 
-# HTTP and HTTPS proxy servers are supported via the usual environment variables [1]
-# ``http_proxy``, ``https_proxy`` and ``no_proxy``. They can be set in
-# ``localrc`` if necessary or on the command line::
-#
-# [1] http://www.w3.org/Daemon/User/Proxies/ProxyClients.html
-#
-#     http_proxy=http://proxy.example.com:3128/ no_proxy=repo.example.net ./stack.sh
-
-if [[ -n "$http_proxy" ]]; then
-    export http_proxy=$http_proxy
-fi
-if [[ -n "$https_proxy" ]]; then
-    export https_proxy=$https_proxy
-fi
-if [[ -n "$no_proxy" ]]; then
-    export no_proxy=$no_proxy
-fi
+# Make sure the proxy config is visible to sub-processes
+export_proxy_variables
 
 # Destination path for installation ``DEST``
 DEST=${DEST:-/opt/stack}
 
 
 # Sanity Check
-# ============
+# ------------
 
 # Clean up last environment var cache
 if [[ -r $TOP_DIR/.stackenv ]]; then
@@ -646,26 +630,9 @@
 # OpenStack uses a fair number of other projects.
 
 # Install package requirements
+# Source it so the entire environment is available
 echo_summary "Installing package prerequisites"
-if is_ubuntu; then
-    install_package $(get_packages $FILES/apts)
-elif is_fedora; then
-    install_package $(get_packages $FILES/rpms)
-elif is_suse; then
-    install_package $(get_packages $FILES/rpms-suse)
-else
-    exit_distro_not_supported "list of packages"
-fi
-
-if [[ $SYSLOG != "False" ]]; then
-    if is_ubuntu || is_fedora; then
-        install_package rsyslog-relp
-    elif is_suse; then
-        install_package rsyslog-module-relp
-    else
-        exit_distro_not_supported "rsyslog-relp installation"
-    fi
-fi
+source $TOP_DIR/tools/install_prereqs.sh
 
 install_rpc_backend
 
@@ -1300,8 +1267,8 @@
     sudo pkill dnsmasq || true
     sudo dnsmasq --conf-file= --port=0 --enable-tftp --tftp-root=/tftpboot \
         --dhcp-boot=pxelinux.0 --bind-interfaces --pid-file=/var/run/dnsmasq.pid \
-        --interface=$BM_DNSMASQ_IFACE --dhcp-range=$BM_DNSMASQ_RANGE
-
+        --interface=$BM_DNSMASQ_IFACE --dhcp-range=$BM_DNSMASQ_RANGE \
+        ${$BM_DNSMASQ_DNS:+--dhcp-option=option:dns-server,$BM_DNSMASQ_DNS}
     # ensure callback daemon is running
     sudo pkill nova-baremetal-deploy-helper || true
     screen_it baremetal "nova-baremetal-deploy-helper"
diff --git a/tools/install_prereqs.sh b/tools/install_prereqs.sh
new file mode 100755
index 0000000..4d151db
--- /dev/null
+++ b/tools/install_prereqs.sh
@@ -0,0 +1,82 @@
+#!/usr/bin/env bash
+
+# **install_prereqs.sh**
+
+# Install system package prerequisites
+#
+# install_prereqs.sh [-f]
+#
+# -f        Force an install run now
+
+if [[ -n "$1" &&  "$1" = "-f" ]]; then
+    FORCE_PREREQ=1
+fi
+
+# If TOP_DIR is set we're being sourced rather than running stand-alone
+# or in a sub-shell
+if [[ -z "$TOP_DIR" ]]; then
+    # Keep track of the devstack directory
+    TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
+
+    # Import common functions
+    source $TOP_DIR/functions
+
+    # Determine what system we are running on.  This provides ``os_VENDOR``,
+    # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
+    # and ``DISTRO``
+    GetDistro
+
+    # Needed to get ``ENABLED_SERVICES``
+    source $TOP_DIR/stackrc
+
+    # Prereq dirs are here
+    FILES=$TOP_DIR/files
+fi
+
+# Minimum wait time
+PREREQ_RERUN_MARKER=${PREREQ_RERUN_MARKER:-$TOP_DIR/.prereqs}
+PREREQ_RERUN_HOURS=${PREREQ_RERUN_HOURS:-2}
+PREREQ_RERUN_SECONDS=$((60*60*$PREREQ_RERUN_HOURS))
+
+NOW=$(date "+%s")
+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..."
+    return 0
+fi
+
+# Make sure the proxy config is visible to sub-processes
+export_proxy_variables
+
+
+# Install Packages
+# ================
+
+# Install package requirements
+if is_ubuntu; then
+    install_package $(get_packages $FILES/apts)
+elif is_fedora; then
+    install_package $(get_packages $FILES/rpms)
+elif is_suse; then
+    install_package $(get_packages $FILES/rpms-suse)
+else
+    exit_distro_not_supported "list of packages"
+fi
+
+if [[ -n "$SYSLOG" && "$SYSLOG" != "False" ]]; then
+    if is_ubuntu || is_fedora; then
+        install_package rsyslog-relp
+    elif is_suse; then
+        install_package rsyslog-module-relp
+    else
+        exit_distro_not_supported "rsyslog-relp installation"
+    fi
+fi
+
+
+# Mark end of run
+# ---------------
+
+date "+%s" >$PREREQ_RERUN_MARKER
+date >>$PREREQ_RERUN_MARKER