enable apache2 server as front end for swift

1.install apache and wsgi module
2.config apache2 vhost and wsgi files for proxy,
account, container and object server.
3.refactor apache functions from horizon and swift
into lib/apache

Change-Id: I3a5d1e511c5dca1e6d01a1adca8fda0a43d4f632
Implements: blueprint enable-apache-frontend-for-swift
diff --git a/lib/horizon b/lib/horizon
index b537484..b06ea1c 100644
--- a/lib/horizon
+++ b/lib/horizon
@@ -4,6 +4,7 @@
 
 # Dependencies:
 # ``functions`` file
+# ``apache`` file
 # ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
 # <list other global vars that are assumed to be defined>
 
@@ -33,23 +34,6 @@
 # The example file in Horizon repo is used by default.
 HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example}
 
-# Allow overriding the default Apache user and group, default to
-# current user and his default group.
-APACHE_USER=${APACHE_USER:-$USER}
-APACHE_GROUP=${APACHE_GROUP:-$(id -gn $APACHE_USER)}
-
-# Set up service name and configuration path
-if is_ubuntu; then
-    APACHE_NAME=apache2
-    APACHE_CONF=sites-available/horizon
-elif is_fedora; then
-    APACHE_NAME=httpd
-    APACHE_CONF=conf.d/horizon.conf
-elif is_suse; then
-    APACHE_NAME=apache2
-    APACHE_CONF=vhosts.d/horizon.conf
-fi
-
 
 # Functions
 # ---------
@@ -119,11 +103,12 @@
     sudo mkdir -p $HORIZON_DIR/.blackhole
 
     HORIZON_REQUIRE=''
+    local horizon_conf=/etc/$APACHE_NAME/$APACHE_CONF_DIR/horizon
     if is_ubuntu; then
         # Clean up the old config name
         sudo rm -f /etc/apache2/sites-enabled/000-default
         # Be a good citizen and use the distro tools here
-        sudo touch /etc/$APACHE_NAME/$APACHE_CONF
+        sudo touch $horizon_conf
         sudo a2ensite horizon
         # WSGI isn't enabled by default, enable it
         sudo a2enmod wsgi
@@ -153,23 +138,13 @@
         s,%APACHE_NAME%,$APACHE_NAME,g;
         s,%DEST%,$DEST,g;
         s,%HORIZON_REQUIRE%,$HORIZON_REQUIRE,g;
-    \" $FILES/apache-horizon.template >/etc/$APACHE_NAME/$APACHE_CONF"
+    \" $FILES/apache-horizon.template >$horizon_conf"
 }
 
 # install_horizon() - Collect source and prepare
 function install_horizon() {
     # Apache installation, because we mark it NOPRIME
-    if is_ubuntu; then
-        # Install apache2, which is NOPRIME'd
-        install_package apache2 libapache2-mod-wsgi
-    elif is_fedora; then
-        sudo rm -f /etc/httpd/conf.d/000-*
-        install_package httpd mod_wsgi
-    elif is_suse; then
-        install_package apache2 apache2-mod_wsgi
-    else
-        exit_distro_not_supported "apache installation"
-    fi
+    install_apache_wsgi
 
     # NOTE(sdague) quantal changed the name of the node binary
     if is_ubuntu; then
@@ -185,17 +160,13 @@
 
 # start_horizon() - Start running processes, including screen
 function start_horizon() {
-    restart_service $APACHE_NAME
+    restart_apache_server
     screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
 }
 
 # stop_horizon() - Stop running processes (non-screen)
 function stop_horizon() {
-    if [ -n "$APACHE_NAME" ]; then
-        stop_service $APACHE_NAME
-    else
-        exit_distro_not_supported "apache configuration"
-    fi
+    stop_apache_server
 }