lib/quantum: refactor quantum plugins and third party

As quantum plugin support is coming like floodlight, nvp and nec,
it's worth while to refactor quantum plugin logic so that each plugin can
be modified/enhanced intervening with other quantum plugin.
And new plugin support can be added easily (hopefully) without modifying
core logic.

Change-Id: Ic5ab5b993272fdd3b4e779823323777a845ee681
diff --git a/lib/quantum_thirdparty/README.md b/lib/quantum_thirdparty/README.md
new file mode 100644
index 0000000..3b5837d
--- /dev/null
+++ b/lib/quantum_thirdparty/README.md
@@ -0,0 +1,36 @@
+Quantum third party specific files
+==================================
+Some Quantum plugins require third party programs to function.
+The files under the directory, ``lib/quantum_thirdparty/``, will be used
+when their service are enabled.
+Third party program specific configuration variables should be in this file.
+
+* filename: ``<third_party>``
+  * The corresponding file name should be same to service name, ``<third_party>``.
+
+functions
+---------
+``lib/quantum`` calls the following functions when the ``<third_party>`` is enabled
+
+functions to be implemented
+* ``configure_<third_party>``:
+  set config files, create data dirs, etc
+  e.g.
+  sudo python setup.py deploy
+  iniset $XXXX_CONF...
+
+* ``init_<third_party>``:
+  initialize databases, etc
+
+* ``install_<third_party>``:
+  collect source and prepare
+  e.g.
+  git clone xxx
+
+* ``start_<third_party>``:
+  start running processes, including screen
+  e.g.
+  screen_it XXXX "cd $XXXXY_DIR && $XXXX_DIR/bin/XXXX-bin"
+
+* ``stop_<third_party>``:
+  stop running processes (non-screen)
diff --git a/lib/quantum_thirdparty/bigswitch_floodlight b/lib/quantum_thirdparty/bigswitch_floodlight
new file mode 100644
index 0000000..77aeb61
--- /dev/null
+++ b/lib/quantum_thirdparty/bigswitch_floodlight
@@ -0,0 +1,50 @@
+# Big Switch/FloodLight  OpenFlow Controller
+# ------------------------------------------
+
+# Save trace setting
+XTRACE=$(set +o | grep xtrace)
+set +o xtrace
+
+BS_FL_CONTROLLERS_PORT=${BS_FL_CONTROLLERS_PORT:-localhost:80}
+BS_FL_OF_PORT=${BS_FL_OF_PORT:-6633}
+OVS_BRIDGE=${OVS_BRIDGE:-br-int}
+
+function configure_bigswitch_floodlight() {
+    :
+}
+
+function init_bigswitch_floodlight() {
+    install_quantum_agent_packages
+
+    echo -n "Installing OVS managed by the openflow controllers:"
+    echo ${BS_FL_CONTROLLERS_PORT}
+
+    # Create local OVS bridge and configure it
+    sudo ovs-vsctl --no-wait -- --if-exists del-br ${OVS_BRIDGE}
+    sudo ovs-vsctl --no-wait add-br ${OVS_BRIDGE}
+    sudo ovs-vsctl --no-wait br-set-external-id ${OVS_BRIDGE} bridge-id ${OVS_BRIDGE}
+
+    ctrls=
+    for ctrl in `echo ${BS_FL_CONTROLLERS_PORT} | tr ',' ' '`
+    do
+        ctrl=${ctrl%:*}
+        ctrls="${ctrls} tcp:${ctrl}:${BS_FL_OF_PORT}"
+    done
+    echo "Adding Network conttrollers: " ${ctrls}
+    sudo ovs-vsctl --no-wait set-controller ${OVS_BRIDGE} ${ctrls}
+}
+
+function install_bigswitch_floodlight() {
+    :
+}
+
+function start_bigswitch_floodlight() {
+    :
+}
+
+function stop_bigswitch_floodlight() {
+    :
+}
+
+# Restore xtrace
+$XTRACE
diff --git a/lib/quantum_thirdparty/ryu b/lib/quantum_thirdparty/ryu
new file mode 100644
index 0000000..f11951a
--- /dev/null
+++ b/lib/quantum_thirdparty/ryu
@@ -0,0 +1,65 @@
+# Ryu OpenFlow Controller
+# -----------------------
+
+# Save trace setting
+XTRACE=$(set +o | grep xtrace)
+set +o xtrace
+
+
+RYU_DIR=$DEST/ryu
+# Ryu API Host
+RYU_API_HOST=${RYU_API_HOST:-127.0.0.1}
+# Ryu API Port
+RYU_API_PORT=${RYU_API_PORT:-8080}
+# Ryu OFP Host
+RYU_OFP_HOST=${RYU_OFP_HOST:-127.0.0.1}
+# Ryu OFP Port
+RYU_OFP_PORT=${RYU_OFP_PORT:-6633}
+# Ryu Applications
+RYU_APPS=${RYU_APPS:-ryu.app.simple_isolation,ryu.app.rest}
+# Ryu configuration
+RYU_CONF_CONTENTS=${RYU_CONF_CONTENTS:-"
+--app_lists=$RYU_APPS
+--wsapi_host=$RYU_API_HOST
+--wsapi_port=$RYU_API_PORT
+--ofp_listen_host=$RYU_OFP_HOST
+--ofp_tcp_listen_port=$RYU_OFP_PORT
+--quantum_url=http://$Q_HOST:$Q_PORT
+--quantum_admin_username=$Q_ADMIN_USERNAME
+--quantum_admin_password=$SERVICE_PASSWORD
+--quantum_admin_tenant_name=$SERVICE_TENANT_NAME
+--quantum_admin_auth_url=$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v2.0
+--quantum_auth_strategy=$Q_AUTH_STRATEGY
+--quantum_controller_addr=tcp:$RYU_OFP_HOST:$RYU_OFP_PORT
+"}
+
+function configure_ryu() {
+    setup_develop $RYU_DIR
+}
+
+function init_ryu() {
+    RYU_CONF_DIR=/etc/ryu
+    if [[ ! -d $RYU_CONF_DIR ]]; then
+        sudo mkdir -p $RYU_CONF_DIR
+    fi
+    sudo chown $STACK_USER $RYU_CONF_DIR
+    RYU_CONF=$RYU_CONF_DIR/ryu.conf
+    sudo rm -rf $RYU_CONF
+
+    echo "${RYU_CONF_CONTENTS}" > $RYU_CONF
+}
+
+function install_ryu() {
+    git_clone $RYU_REPO $RYU_DIR $RYU_BRANCH
+}
+
+function start_ryu() {
+    screen_it ryu "cd $RYU_DIR && $RYU_DIR/bin/ryu-manager --flagfile $RYU_CONF"
+}
+
+function stop_ryu() {
+    :
+}
+
+# Restore xtrace
+$XTRACE