Merge "Remove unused option for ceilometer."
diff --git a/exercises/floating_ips.sh b/exercises/floating_ips.sh
index b4e1c42..ad11a6b 100755
--- a/exercises/floating_ips.sh
+++ b/exercises/floating_ips.sh
@@ -48,7 +48,7 @@
 SECGROUP=${SECGROUP:-test_secgroup}
 
 # Default floating IP pool name
-DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-nova}
+DEFAULT_FLOATING_POOL=${DEFAULT_FLOATING_POOL:-public}
 
 # Additional floating IP pool and range
 TEST_FLOATING_POOL=${TEST_FLOATING_POOL:-test}
diff --git a/files/apts/keystone b/files/apts/keystone
index ce536bf..c98409f 100644
--- a/files/apts/keystone
+++ b/files/apts/keystone
@@ -13,4 +13,3 @@
 python-routes
 libldap2-dev
 libsasl2-dev
-python-bcrypt
diff --git a/files/apts/trema b/files/apts/trema
new file mode 100644
index 0000000..e33ccd3
--- /dev/null
+++ b/files/apts/trema
@@ -0,0 +1,15 @@
+# Trema
+gcc
+make
+ruby1.8
+rubygems1.8
+ruby1.8-dev
+libpcap-dev
+libsqlite3-dev
+
+# Sliceable Switch
+sqlite3
+libdbi-perl
+libdbd-sqlite3-perl
+apache2
+libjson-perl
diff --git a/files/rpms-suse/keystone b/files/rpms-suse/keystone
index b3c876a..7d9a7bf 100644
--- a/files/rpms-suse/keystone
+++ b/files/rpms-suse/keystone
@@ -12,6 +12,5 @@
 python-greenlet
 python-lxml
 python-mysql
-python-py-bcrypt
 python-pysqlite
 sqlite3
diff --git a/functions b/functions
index edc4bf9..445af5f 100644
--- a/functions
+++ b/functions
@@ -408,6 +408,9 @@
         else
             DISTRO="sle${os_RELEASE}sp${os_UPDATE}"
         fi
+    elif [[ "$os_VENDOR" =~ (Red Hat) || "$os_VENDOR" =~ (CentOS) ]]; then
+        # Drop the . release as we assume it's compatible
+        DISTRO="rhel${os_RELEASE::1}"
     else
         # Catch-all for now is Vendor + Release + Update
         DISTRO="$os_VENDOR-$os_RELEASE.$os_UPDATE"
@@ -440,7 +443,6 @@
     [ "$os_VENDOR" = "Fedora" ] || [ "$os_VENDOR" = "Red Hat" ] || [ "$os_VENDOR" = "CentOS" ]
 }
 
-
 # Determine if current distribution is a SUSE-based distribution
 # (openSUSE, SLE).
 # is_suse
diff --git a/lib/baremetal b/lib/baremetal
index 24cce9f..17a967f 100644
--- a/lib/baremetal
+++ b/lib/baremetal
@@ -427,7 +427,7 @@
        "$mac_1" \
        | grep ' id ' | get_field 2 )
     [ $? -eq 0 ] || [ "$id" ] || die "Error adding baremetal node"
-    id2=$(nova baremetal-add-interface "$id" "$mac_2" )
+    id2=$(nova baremetal-interface-add "$id" "$mac_2" )
     [ $? -eq 0 ] || [ "$id2" ] || die "Error adding interface to barmetal node $id"
 }
 
diff --git a/lib/cinder b/lib/cinder
index 710d942..deace68 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -365,7 +365,10 @@
 function install_cinder() {
     git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
     setup_develop $CINDER_DIR
+}
 
+# install_cinderclient() - Collect source and prepare
+function install_cinderclient() {
     git_clone $CINDERCLIENT_REPO $CINDERCLIENT_DIR $CINDERCLIENT_BRANCH
     setup_develop $CINDERCLIENT_DIR
 }
diff --git a/lib/nova b/lib/nova
index 91fe028..8d045b5 100644
--- a/lib/nova
+++ b/lib/nova
@@ -169,11 +169,6 @@
     sudo rm -rf $NOVA_STATE_PATH $NOVA_AUTH_CACHE_DIR
 }
 
-# configure_novaclient() - Set config files, create data dirs, etc
-function configure_novaclient() {
-    setup_develop $NOVACLIENT_DIR
-}
-
 # configure_nova_rootwrap() - configure Nova's rootwrap
 function configure_nova_rootwrap() {
     # Deploy new rootwrap filters files (owned by root).
@@ -204,8 +199,6 @@
 
 # configure_nova() - Set config files, create data dirs, etc
 function configure_nova() {
-    setup_develop $NOVA_DIR
-
     # Put config files in ``/etc/nova`` for everyone to find
     if [[ ! -d $NOVA_CONF_DIR ]]; then
         sudo mkdir -p $NOVA_CONF_DIR
@@ -597,6 +590,7 @@
 # install_novaclient() - Collect source and prepare
 function install_novaclient() {
     git_clone $NOVACLIENT_REPO $NOVACLIENT_DIR $NOVACLIENT_BRANCH
+    setup_develop $NOVACLIENT_DIR
 }
 
 # install_nova() - Collect source and prepare
@@ -627,6 +621,7 @@
     fi
 
     git_clone $NOVA_REPO $NOVA_DIR $NOVA_BRANCH
+    setup_develop $NOVA_DIR
 }
 
 # start_nova_api() - Start the API process ahead of other things
diff --git a/lib/quantum b/lib/quantum
index 61b89f7..e2a0d53 100644
--- a/lib/quantum
+++ b/lib/quantum
@@ -11,8 +11,6 @@
 # install_quantumclient
 # install_quantum_agent_packages
 # install_quantum_third_party
-# setup_quantum
-# setup_quantumclient
 # configure_quantum
 # init_quantum
 # configure_quantum_third_party
@@ -94,6 +92,9 @@
 Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
 # The name of the default q-l3 router
 Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
+# List of config file names in addition to the main plugin config file
+# See _configure_quantum_common() for details about setting it up
+declare -a Q_PLUGIN_EXTRA_CONF_FILES
 
 if is_service_enabled quantum; then
     Q_RR_CONF_FILE=$QUANTUM_CONF_DIR/rootwrap.conf
@@ -179,7 +180,7 @@
 # Agent loadbalancer service plugin functions
 # -------------------------------------------
 # Hardcoding for 1 service plugin for now
-source $TOP_DIR/lib/quantum_plugins/agent_loadbalancer
+source $TOP_DIR/lib/quantum_plugins/services/agent_loadbalancer
 
 # Use security group or not
 if has_quantum_plugin_security_group; then
@@ -343,11 +344,13 @@
 # install_quantum() - Collect source and prepare
 function install_quantum() {
     git_clone $QUANTUM_REPO $QUANTUM_DIR $QUANTUM_BRANCH
+    setup_develop $QUANTUM_DIR
 }
 
 # install_quantumclient() - Collect source and prepare
 function install_quantumclient() {
     git_clone $QUANTUMCLIENT_REPO $QUANTUMCLIENT_DIR $QUANTUMCLIENT_BRANCH
+    setup_develop $QUANTUMCLIENT_DIR
 }
 
 # install_quantum_agent_packages() - Collect source and prepare
@@ -356,18 +359,16 @@
     quantum_plugin_install_agent_packages
 }
 
-function setup_quantum() {
-    setup_develop $QUANTUM_DIR
-}
-
-function setup_quantumclient() {
-    setup_develop $QUANTUMCLIENT_DIR
-}
-
 # Start running processes, including screen
 function start_quantum_service_and_check() {
+    # build config-file options
+    local cfg_file
+    local CFG_FILE_OPTIONS="--config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
+    for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
+         CFG_FILE_OPTIONS+=" --config-file /$cfg_file"
+    done
     # Start the Quantum service
-    screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server --config-file $QUANTUM_CONF --config-file /$Q_PLUGIN_CONF_FILE"
+    screen_it q-svc "cd $QUANTUM_DIR && python $QUANTUM_DIR/bin/quantum-server $CFG_FILE_OPTIONS"
     echo "Waiting for Quantum to start..."
     if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= wget -q -O- http://$Q_HOST:$Q_PORT; do sleep 1; done"; then
       die $LINENO "Quantum did not start"
@@ -413,8 +414,11 @@
 
     cp $QUANTUM_DIR/etc/quantum.conf $QUANTUM_CONF
 
-    # set plugin-specific variables
-    # Q_PLUGIN_CONF_PATH, Q_PLUGIN_CONF_FILENAME, Q_DB_NAME, Q_PLUGIN_CLASS
+    # Set plugin-specific variables Q_DB_NAME, Q_PLUGIN_CLASS.
+    # For main plugin config file, set Q_PLUGIN_CONF_PATH, Q_PLUGIN_CONF_FILENAME.
+    # For addition plugin config files, set Q_PLUGIN_EXTRA_CONF_PATH,
+    # Q_PLUGIN_EXTRA_CONF_FILES.  For example:
+    #    Q_PLUGIN_EXTRA_CONF_FILES=(file1, file2)
     quantum_plugin_configure_common
 
     if [[ $Q_PLUGIN_CONF_PATH == '' || $Q_PLUGIN_CONF_FILENAME == '' || $Q_PLUGIN_CLASS == '' ]]; then
@@ -429,6 +433,22 @@
     iniset /$Q_PLUGIN_CONF_FILE DATABASE sql_connection `database_connection_url $Q_DB_NAME`
     iniset $QUANTUM_CONF DEFAULT state_path $DATA_DIR/quantum
 
+    # If addition config files are set, make sure their path name is set as well
+    if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
+        die $LINENO "Quantum additional plugin config not set.. exiting"
+    fi
+
+    # If additional config files exist, copy them over to quantum configuration
+    # directory
+    if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
+        mkdir -p /$Q_PLUGIN_EXTRA_CONF_PATH
+        local f
+        for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
+            Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
+            cp $QUANTUM_DIR/${Q_PLUGIN_EXTRA_CONF_FILES[$f]} /${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
+        done
+    fi
+
     _quantum_setup_rootwrap
 }
 
diff --git a/lib/quantum_plugins/nec b/lib/quantum_plugins/nec
new file mode 100644
index 0000000..f61f50b
--- /dev/null
+++ b/lib/quantum_plugins/nec
@@ -0,0 +1,122 @@
+# Quantum NEC OpenFlow plugin
+# ---------------------------
+
+# Save trace setting
+MY_XTRACE=$(set +o | grep xtrace)
+set +o xtrace
+
+# Configuration parameters
+OFC_HOST=${OFC_HOST:-127.0.0.1}
+OFC_PORT=${OFC_PORT:-8888}
+
+OFC_API_HOST=${OFC_API_HOST:-$OFC_HOST}
+OFC_API_PORT=${OFC_API_PORT:-$OFC_PORT}
+OFC_OFP_HOST=${OFC_OFP_HOST:-$OFC_HOST}
+OFC_OFP_PORT=${OFC_OFP_PORT:-6633}
+OFC_DRIVER=${OFC_DRIVER:-trema}
+OFC_RETRY_MAX=${OFC_RETRY_MAX:-0}
+OFC_RETRY_INTERVAL=${OFC_RETRY_INTERVAL:-1}
+
+OVS_BRIDGE=${OVS_BRIDGE:-br-int}
+
+# Main logic
+# ---------------------------
+
+source $TOP_DIR/lib/quantum_plugins/ovs_base
+
+function quantum_plugin_create_nova_conf() {
+    _quantum_ovs_base_configure_nova_vif_driver
+}
+
+function quantum_plugin_install_agent_packages() {
+    # SKIP_OVS_INSTALL is useful when we want to use Open vSwitch whose
+    # version is different from the version provided by the distribution.
+    if [[ "$SKIP_OVS_INSTALL" = "True" ]]; then
+        echo "You need to install Open vSwitch manually."
+        return
+    fi
+    _quantum_ovs_base_install_agent_packages
+}
+
+function quantum_plugin_configure_common() {
+    Q_PLUGIN_CONF_PATH=etc/quantum/plugins/nec
+    Q_PLUGIN_CONF_FILENAME=nec.ini
+    Q_DB_NAME="quantum_nec"
+    Q_PLUGIN_CLASS="quantum.plugins.nec.nec_plugin.NECPluginV2"
+}
+
+function quantum_plugin_configure_debug_command() {
+    _quantum_ovs_base_configure_debug_command
+}
+
+function quantum_plugin_configure_dhcp_agent() {
+    :
+}
+
+function quantum_plugin_configure_l3_agent() {
+    _quantum_ovs_base_configure_l3_agent
+}
+
+function quantum_plugin_configure_plugin_agent() {
+    if [[ "$SKIP_OVS_BRIDGE_SETUP" = "True" ]]; then
+        return
+    fi
+    # Set up integration bridge
+    _quantum_ovs_base_setup_bridge $OVS_BRIDGE
+    sudo ovs-vsctl --no-wait set-controller $OVS_BRIDGE tcp:$OFC_OFP_HOST:$OFC_OFP_PORT
+    # Generate datapath ID from HOST_IP
+    local dpid=$(printf "0x%07d%03d%03d%03d\n" ${HOST_IP//./ })
+    sudo ovs-vsctl --no-wait set Bridge $OVS_BRIDGE other-config:datapath-id=$dpid
+    sudo ovs-vsctl --no-wait set-fail-mode $OVS_BRIDGE secure
+    if [ -n "$OVS_INTERFACE" ]; then
+        sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_BRIDGE $OVS_INTERFACE
+    fi
+    _quantum_setup_ovs_tunnels $OVS_BRIDGE
+    AGENT_BINARY="$QUANTUM_DIR/bin/quantum-nec-agent"
+
+    _quantum_ovs_base_configure_firewall_driver
+}
+
+function quantum_plugin_configure_service() {
+    iniset $QUANTUM_CONF DEFAULT api_extensions_path quantum/plugins/nec/extensions/
+    iniset /$Q_PLUGIN_CONF_FILE OFC host $OFC_API_HOST
+    iniset /$Q_PLUGIN_CONF_FILE OFC port $OFC_API_PORT
+    iniset /$Q_PLUGIN_CONF_FILE OFC driver $OFC_DRIVER
+    iniset /$Q_PLUGIN_CONF_FILE OFC api_retry_max OFC_RETRY_MAX
+    iniset /$Q_PLUGIN_CONF_FILE OFC api_retry_interval OFC_RETRY_INTERVAL
+}
+
+function quantum_plugin_setup_interface_driver() {
+    local conf_file=$1
+    iniset $conf_file DEFAULT interface_driver quantum.agent.linux.interface.OVSInterfaceDriver
+    iniset $conf_file DEFAULT ovs_use_veth True
+}
+
+# Utility functions
+# ---------------------------
+
+# Setup OVS tunnel manually
+function _quantum_setup_ovs_tunnels() {
+    local bridge=$1
+    local id=0
+    GRE_LOCAL_IP=${GRE_LOCAL_IP:-$HOST_IP}
+    if [ -n "$GRE_REMOTE_IPS" ]; then
+         for ip in ${GRE_REMOTE_IPS//:/ }
+         do
+             if [[ "$ip" == "$GRE_LOCAL_IP" ]]; then
+                 continue
+             fi
+             sudo ovs-vsctl --no-wait add-port $bridge gre$id -- \
+                 set Interface gre$id type=gre options:remote_ip=$ip
+             id=`expr $id + 1`
+         done
+    fi
+}
+
+function has_quantum_plugin_security_group() {
+    # 0 means True here
+    return 0
+}
+
+# Restore xtrace
+$MY_XTRACE
diff --git a/lib/quantum_plugins/agent_loadbalancer b/lib/quantum_plugins/services/agent_loadbalancer
similarity index 60%
rename from lib/quantum_plugins/agent_loadbalancer
rename to lib/quantum_plugins/services/agent_loadbalancer
index 87e7aaa..b6528b0 100644
--- a/lib/quantum_plugins/agent_loadbalancer
+++ b/lib/quantum_plugins/services/agent_loadbalancer
@@ -7,6 +7,7 @@
 
 
 AGENT_LBAAS_BINARY="$QUANTUM_DIR/bin/quantum-lbaas-agent"
+AGENT_LBAAS_PLUGIN=quantum.plugins.services.agent_loadbalancer.plugin.LoadBalancerPlugin
 
 function quantum_agent_lbaas_install_agent_packages() {
     if is_ubuntu || is_fedora; then
@@ -19,9 +20,9 @@
 
 function quantum_agent_lbaas_configure_common() {
     if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
-        Q_SERVICE_PLUGIN_CLASSES="quantum.plugins.services.agent_loadbalancer.plugin.LoadBalancerPlugin"
+        Q_SERVICE_PLUGIN_CLASSES=$AGENT_LBAAS_PLUGIN
     else
-        Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,quantum.plugins.services.agent_loadbalancer.plugin.LoadBalancerPlugin"
+        Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$AGENT_LBAAS_PLUGIN"
     fi
 }
 
@@ -31,13 +32,9 @@
 
     LBAAS_AGENT_CONF_FILENAME="$LBAAS_AGENT_CONF_PATH/lbaas_agent.ini"
 
-    cp $QUANTUM_DIR/etc/lbaas_agent.ini /$LBAAS_AGENT_CONF_FILENAME
+    cp $QUANTUM_DIR/etc/lbaas_agent.ini $LBAAS_AGENT_CONF_FILENAME
 
-    if [[ $Q_PLUGIN == 'linuxbridge' || $Q_PLUGIN == 'brocade' ]]; then
-        iniset $LBAAS_AGENT_CONF_FILENAME DEFAULT interface_driver "quantum.agent.linux.interface.BridgeInterfaceDriver"
-    else
-        iniset $LBAAS_AGENT_CONF_FILENAME DEFAULT interface_driver "quantum.agent.linux.interface.OVSInterfaceDriver"
-    fi
+    quantum_plugin_setup_interface_driver $LBAAS_AGENT_CONF_FILENAME
 
     if is_fedora; then
         iniset $LBAAS_AGENT_CONF_FILENAME DEFAULT user_group "nobody"
diff --git a/lib/quantum_thirdparty/trema b/lib/quantum_thirdparty/trema
new file mode 100644
index 0000000..09dc46b
--- /dev/null
+++ b/lib/quantum_thirdparty/trema
@@ -0,0 +1,113 @@
+# Trema Sliceable Switch
+# ----------------------
+
+# Trema is a Full-Stack OpenFlow Framework in Ruby and C
+# https://github.com/trema/trema
+#
+# Trema Sliceable Switch is an OpenFlow controller which provides
+# virtual layer-2 network slices.
+# https://github.com/trema/apps/wiki
+
+# Trema Sliceable Switch (OpenFlow Controller)
+TREMA_APPS_REPO=${TREMA_APPS_REPO:-https://github.com/trema/apps.git}
+TREMA_APPS_BRANCH=${TREMA_APPS_BRANCH:-master}
+
+# Save trace setting
+MY_XTRACE=$(set +o | grep xtrace)
+set +o xtrace
+
+TREMA_DIR=${TREMA_DIR:-$DEST/trema}
+TREMA_SS_DIR="$TREMA_DIR/apps/sliceable_switch"
+
+TREMA_DATA_DIR=${TREMA_DATA_DIR:-$DATA_DIR/trema}
+TREMA_SS_ETC_DIR=$TREMA_DATA_DIR/sliceable_switch/etc
+TREMA_SS_DB_DIR=$TREMA_DATA_DIR/sliceable_switch/db
+TREMA_SS_SCRIPT_DIR=$TREMA_DATA_DIR/sliceable_switch/script
+TREMA_TMP_DIR=$TREMA_DATA_DIR/trema
+
+TREMA_LOG_LEVEL=${TREMA_LOG_LEVEL:-info}
+
+TREMA_SS_CONFIG=$TREMA_SS_ETC_DIR/sliceable.conf
+TREMA_SS_APACHE_CONFIG=/etc/apache2/sites-available/sliceable_switch
+
+# configure_trema - Set config files, create data dirs, etc
+function configure_trema() {
+    # prepare dir
+    for d in $TREMA_SS_ETC_DIR $TREMA_SS_DB_DIR $TREMA_SS_SCRIPT_DIR; do
+        sudo mkdir -p $d
+        sudo chown -R `whoami` $d
+    done
+    sudo mkdir -p $TREMA_TMP_DIR
+}
+
+# init_trema - Initialize databases, etc.
+function init_trema() {
+    local _pwd=$(pwd)
+
+    # Initialize databases for Sliceable Switch
+    cd $TREMA_SS_DIR
+    rm -f filter.db slice.db
+    ./create_tables.sh
+    mv filter.db slice.db $TREMA_SS_DB_DIR
+    # Make sure that apache cgi has write access to the databases
+    sudo chown -R www-data.www-data $TREMA_SS_DB_DIR
+    cd $_pwd
+
+    # Setup HTTP Server for sliceable_switch
+    cp $TREMA_SS_DIR/{Slice.pm,Filter.pm,config.cgi} $TREMA_SS_SCRIPT_DIR
+    sed -i -e "s|/home/sliceable_switch/db|$TREMA_SS_DB_DIR|" \
+        $TREMA_SS_SCRIPT_DIR/config.cgi
+
+    sudo cp $TREMA_SS_DIR/apache/sliceable_switch $TREMA_SS_APACHE_CONFIG
+    sudo sed -i -e "s|/home/sliceable_switch/script|$TREMA_SS_SCRIPT_DIR|" \
+        $TREMA_SS_APACHE_CONFIG
+    sudo a2enmod rewrite actions
+    sudo a2ensite sliceable_switch
+
+    cp $TREMA_SS_DIR/sliceable_switch_null.conf $TREMA_SS_CONFIG
+    sed -i -e "s|^\$apps_dir.*$|\$apps_dir = \"$TREMA_DIR/apps\"|" \
+           -e "s|^\$db_dir.*$|\$db_dir = \"$TREMA_SS_DB_DIR\"|" \
+           $TREMA_SS_CONFIG
+}
+
+function gem_install() {
+    [[ "$OFFLINE" = "True" ]] && return
+    [ -n "$RUBYGEMS_CMD" ] || get_gem_command
+
+    local pkg=$1
+    $RUBYGEMS_CMD list | grep "^${pkg} " && return
+    sudo $RUBYGEMS_CMD install $pkg
+}
+
+function get_gem_command() {
+    # Trema requires ruby 1.8, so gem1.8 is checked first
+    RUBYGEMS_CMD=$(which gem1.8 || which gem)
+    if [ -z "$RUBYGEMS_CMD" ]; then
+        echo "Warning: ruby gems command not found."
+    fi
+}
+
+function install_trema() {
+    # Trema
+    gem_install trema
+    # Sliceable Switch
+    git_clone $TREMA_APPS_REPO $TREMA_DIR/apps $TREMA_APPS_BRANCH
+    make -C $TREMA_DIR/apps/topology
+    make -C $TREMA_DIR/apps/flow_manager
+    make -C $TREMA_DIR/apps/sliceable_switch
+}
+
+function start_trema() {
+    # APACHE_NAME is defined in init_horizon (in lib/horizon)
+    restart_service $APACHE_NAME
+
+    sudo LOGGING_LEVEL=$TREMA_LOG_LEVEL TREMA_TMP=$TREMA_TMP_DIR \
+        trema run -d -c $TREMA_SS_CONFIG
+}
+
+function stop_trema() {
+    sudo TREMA_TMP=$TREMA_TMP_DIR trema killall
+}
+
+# Restore xtrace
+$MY_XTRACE
diff --git a/lib/swift b/lib/swift
index 3e7ee20..eb57477 100644
--- a/lib/swift
+++ b/lib/swift
@@ -106,8 +106,6 @@
     local swift_node_config
     local swift_log_dir
 
-    setup_develop $SWIFT_DIR
-
     # Make sure to kill all swift processes first
     swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true
 
@@ -281,11 +279,6 @@
         tee /etc/rsyslog.d/10-swift.conf
 }
 
-# configure_swiftclient() - Set config files, create data dirs, etc
-function configure_swiftclient() {
-    setup_develop $SWIFTCLIENT_DIR
-}
-
 # create_swift_disk - Create Swift backing disk
 function create_swift_disk() {
     local node_number
@@ -374,13 +367,14 @@
 
 function install_swift() {
     git_clone $SWIFT_REPO $SWIFT_DIR $SWIFT_BRANCH
+    setup_develop $SWIFT_DIR
 }
 
 function install_swiftclient() {
     git_clone $SWIFTCLIENT_REPO $SWIFTCLIENT_DIR $SWIFTCLIENT_BRANCH
+    setup_develop $SWIFTCLIENT_DIR
 }
 
-
 # start_swift() - Start running processes, including screen
 function start_swift() {
     # (re)start rsyslog
diff --git a/openrc b/openrc
index 3ef44fd..8af2854 100644
--- a/openrc
+++ b/openrc
@@ -27,8 +27,8 @@
 source $RC_DIR/stackrc
 
 # Load the last env variables if available
-if [[ -r $TOP_DIR/.stackenv ]]; then
-    source $TOP_DIR/.stackenv
+if [[ -r $RC_DIR/.stackenv ]]; then
+    source $RC_DIR/.stackenv
 fi
 
 # Get some necessary configuration
diff --git a/stack.sh b/stack.sh
index e665450..62309dc 100755
--- a/stack.sh
+++ b/stack.sh
@@ -556,118 +556,99 @@
 fi
 
 
-# Check Out Source
-# ----------------
+# Check Out and Install Source
+# ----------------------------
 
 echo_summary "Installing OpenStack project source"
 
-# Grab clients first
+# Install clients libraries
 install_keystoneclient
 install_glanceclient
+install_cinderclient
 install_novaclient
-# Check out the client libs that are used most
-git_clone $OPENSTACKCLIENT_REPO $OPENSTACKCLIENT_DIR $OPENSTACKCLIENT_BRANCH
+if is_service_enabled swift glance; then
+    install_swiftclient
+fi
+if is_service_enabled quantum nova; then
+    install_quantumclient
+fi
 
-# glance, swift middleware and nova api needs keystone middleware
-if is_service_enabled key g-api n-api s-proxy; then
-    # unified auth system (manages accounts/tokens)
+git_clone $OPENSTACKCLIENT_REPO $OPENSTACKCLIENT_DIR $OPENSTACKCLIENT_BRANCH
+setup_develop $OPENSTACKCLIENT_DIR
+
+if is_service_enabled key; then
     install_keystone
+    configure_keystone
 fi
 
 if is_service_enabled s-proxy; then
-    install_swiftclient
     install_swift
+    configure_swift
+
     if is_service_enabled swift3; then
         # swift3 middleware to provide S3 emulation to Swift
         git_clone $SWIFT3_REPO $SWIFT3_DIR $SWIFT3_BRANCH
+        setup_develop $SWIFT3_DIR
     fi
 fi
 
 if is_service_enabled g-api n-api; then
     # image catalog service
     install_glance
+    configure_glance
 fi
+
+if is_service_enabled cinder; then
+    install_cinder
+    configure_cinder
+fi
+
+if is_service_enabled quantum; then
+    install_quantum
+    install_quantum_third_party
+fi
+
 if is_service_enabled nova; then
     # compute service
     install_nova
+    cleanup_nova
+    configure_nova
 fi
+
 if is_service_enabled n-novnc; then
     # a websockets/html5 or flash powered VNC console for vm instances
     git_clone $NOVNC_REPO $NOVNC_DIR $NOVNC_BRANCH
 fi
+
 if is_service_enabled n-spice; then
     # a websockets/html5 or flash powered SPICE console for vm instances
     git_clone $SPICE_REPO $SPICE_DIR $SPICE_BRANCH
 fi
+
 if is_service_enabled horizon; then
     # dashboard
     install_horizon
+    configure_horizon
 fi
-if is_service_enabled quantum; then
-    install_quantum
-    install_quantumclient
-    install_quantum_third_party
-fi
-if is_service_enabled heat; then
-    install_heat
-    install_heatclient
-fi
-if is_service_enabled cinder; then
-    install_cinder
-fi
+
 if is_service_enabled ceilometer; then
     install_ceilometerclient
     install_ceilometer
 fi
 
-
-# Initialization
-# ==============
-
-echo_summary "Configuring OpenStack projects"
-
-# Set up our checkouts so they are installed in the python path
-configure_novaclient
-setup_develop $OPENSTACKCLIENT_DIR
-
-if is_service_enabled key g-api n-api s-proxy; then
-    configure_keystone
-fi
-
-if is_service_enabled s-proxy; then
-    configure_swift
-    configure_swiftclient
-    if is_service_enabled swift3; then
-        setup_develop $SWIFT3_DIR
-    fi
-fi
-
-if is_service_enabled g-api n-api; then
-    configure_glance
-fi
-
-if is_service_enabled nova; then
-    # First clean up old instances
-    cleanup_nova
-    configure_nova
-fi
-
-if is_service_enabled horizon; then
-    configure_horizon
-fi
-
-if is_service_enabled quantum; then
-    setup_quantumclient
-    setup_quantum
-fi
-
 if is_service_enabled heat; then
+    install_heat
+    install_heatclient
     configure_heat
     configure_heatclient
 fi
 
-if is_service_enabled cinder; then
-    configure_cinder
+if is_service_enabled tls-proxy; then
+    configure_CA
+    init_CA
+    init_cert
+    # Add name to /etc/hosts
+    # don't be naive and add to existing line!
 fi
 
 if [[ $TRACK_DEPENDS = True ]] ; then
@@ -679,14 +660,6 @@
     exit 0
 fi
 
-if is_service_enabled tls-proxy; then
-    configure_CA
-    init_CA
-    init_cert
-    # Add name to /etc/hosts
-    # don't be naive and add to existing line!
-fi
-
 
 # Syslog
 # ------
diff --git a/stackrc b/stackrc
index 5a4c580..7c4fa68 100644
--- a/stackrc
+++ b/stackrc
@@ -217,7 +217,7 @@
 
 # Common network names
 PRIVATE_NETWORK_NAME=${PRIVATE_NETWORK_NAME:-"private"}
-PUBLIC_NETWORK_NAME=${PUBLIC_NETWORK_NAME:-"nova"}
+PUBLIC_NETWORK_NAME=${PUBLIC_NETWORK_NAME:-"public"}
 
 # Compatibility until it's eradicated from CI
 USE_SCREEN=${SCREEN_DEV:-$USE_SCREEN}