]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Adds sqlalchemy support for ovs_quantum_plugin.
authorGhe Rivero <ghe@debian.org>
Wed, 16 Nov 2011 10:34:03 +0000 (11:34 +0100)
committerGhe Rivero <ghe@debian.org>
Tue, 13 Dec 2011 08:15:59 +0000 (09:15 +0100)
Fixes bug 890672

Allow to use any database as backend (supported by sqlalchemy).
Need to change ovs_quantum_plugin.ini and add variable sql_connection under DATABASE entry using specific sqlalchemy url schema (same as nova confs)

Change-Id: Ic490b09aad84c7f24d68064c18a8c1b33774cb05

etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini
quantum/plugins/openvswitch/README
quantum/plugins/openvswitch/agent/ovs_quantum_agent.py
quantum/plugins/openvswitch/agent/xenserver_install.sh
quantum/plugins/openvswitch/ovs_quantum_plugin.py
quantum/plugins/openvswitch/pip-requires

index e6dc431e09e4c1be649c181c33deac88e266352d..42cebb78d77fa5b68c3f50d664cc9f695355fb44 100644 (file)
@@ -1,9 +1,7 @@
 [DATABASE]
-name = ovs_quantum
-user = root
-pass = nova
-host = 127.0.0.1
-port = 3306
+# This line MUST be changed to actually run the plugin.
+# Example: sql_connection = mysql://root:nova@127.0.0.1:3336/ovs_quantum
+sql_connection = sqlite://
 
 [OVS]
 integration-bridge = br-int
index be18063c8fa38312b1b97a094fea08c2c49fd6f5..9ffdc76bafdab2e42a679c6ca9187b08eeb601d4 100644 (file)
@@ -55,10 +55,16 @@ provider = quantum.plugins.openvswitch.ovs_quantum_plugin.OVSQuantumPlugin
 
 # -- Database config.
 
-The Open vSwitch quantum service requires access to a mysql database in order
-to store configuration and mappings that will be used by the agent.  Here is
-how to set up the database on the host that you will be running the quantum
-service on.
+The Open vSwitch quantum service requires access to a mysql database or any
+other database engine supported by sqlalchemy in order to store configuration
+and mappings that will be used by the agent.
+
+A new database, "ovs_quantum", should be created, and servers running the
+ovs quantum agent must be able to communicate with the host running the
+quantum service.
+
+Here is how to set up the database using MySQL on the host that you will be
+running the quantum service on.
 
 MySQL should be installed on the host, and all plugins and clients
 must be configured with access to the database.
@@ -86,6 +92,9 @@ mysql> FLUSH PRIVILEGES;
   will be included in the agent distribution tarball (see below) and
   the agent will use the credentials here to access the database.
 
+  The credentials must be specified using sqlalchemy url as
+  sql_connection = mysql://user:pass@127.0.0.1/ovs_quantum
+
 # -- XenServer Agent configuration
 
 - Create the agent distribution tarball
index afeb6b404645e07dcbf4997e558590b1845c713f..de39ad9bda8eeef3c701058ec0e77996f42ad740 100755 (executable)
@@ -20,8 +20,6 @@
 
 import ConfigParser
 import logging as LOG
-import MySQLdb
-import os
 import sys
 import time
 import signal
@@ -29,6 +27,8 @@ import signal
 from optparse import OptionParser
 from subprocess import *
 
+from sqlalchemy.ext.sqlsoup import SqlSoup
+
 
 # A class to represent a VIF (i.e., a port that has 'iface-id' and 'vif-mac'
 # attributes set).
@@ -186,27 +186,28 @@ class OVSQuantumAgent:
         # switch all traffic using L2 learning
         self.int_br.add_flow(priority=1, actions="normal")
 
-    def daemon_loop(self, conn):
+    def daemon_loop(self, db):
         self.local_vlan_map = {}
         old_local_bindings = {}
         old_vif_ports = {}
 
         while True:
-            cursor = conn.cursor()
-            cursor.execute("SELECT * FROM ports where state = 'ACTIVE'")
-            rows = cursor.fetchall()
-            cursor.close()
+
             all_bindings = {}
-            for r in rows:
-                all_bindings[r[2]] = r[1]
+            try:
+                ports = db.ports.all()
+            except:
+                ports = []
+            for port in ports:
+                all_bindings[port.interface_id] = port.network_id
 
-            cursor = conn.cursor()
-            cursor.execute("SELECT * FROM vlan_bindings")
-            rows = cursor.fetchall()
-            cursor.close()
             vlan_bindings = {}
-            for r in rows:
-                vlan_bindings[r[1]] = r[0]
+            try:
+                vlan_binds = db.vlan_bindings.all()
+            except:
+                vlan_binds = []
+            for bind in vlan_binds:
+                vlan_bindings[bind.network_id] = bind.vlan_id
 
             new_vif_ports = {}
             new_local_bindings = {}
@@ -276,19 +277,12 @@ if __name__ == "__main__":
 
     integ_br = config.get("OVS", "integration-bridge")
 
-    db_name = config.get("DATABASE", "name")
-    db_user = config.get("DATABASE", "user")
-    db_pass = config.get("DATABASE", "pass")
-    db_host = config.get("DATABASE", "host")
-    conn = None
-    try:
-        LOG.info("Connecting to database \"%s\" on %s" % (db_name, db_host))
-        conn = MySQLdb.connect(host=db_host, user=db_user,
-          passwd=db_pass, db=db_name)
-        plugin = OVSQuantumAgent(integ_br)
-        plugin.daemon_loop(conn)
-    finally:
-        if conn:
-            conn.close()
+    options = {"sql_connection": config.get("DATABASE", "sql_connection")}
+    db = SqlSoup(options["sql_connection"])
+
+    LOG.info("Connecting to database \"%s\" on %s" %
+             (db.engine.url.database, db.engine.url.host))
+    plugin = OVSQuantumAgent(integ_br)
+    plugin.daemon_loop(db)
 
     sys.exit(0)
index e0820d26f98354abb274f53dee9612273a403c6b..e49c47503f05d37f8b72f262a5f745d452e12744 100755 (executable)
@@ -7,12 +7,12 @@ if [ ! -d /etc/xapi.d/plugins ]; then
        exit 1
 fi
 
-# Make sure we have mysql-python
-rpm -qa | grep MySQL-python >/dev/null 2>&1
+# Make sure we have sqlalchemy-python
+rpm -qa | grep sqlalchemy-python >/dev/null 2>&1
 if [ $? -ne 0 ]; then
-       echo "MySQL-python not found"
-    echo "Please enable the centos repositories and install mysql-python:"
-    echo "yum --enablerepo=base -y install MySQL-python"
+        echo "sqlalchemy-python not found"
+    echo "Please enable the centos repositories and install sqlalchemy-python:"
+    echo "yum --enablerepo=base -y install sqlalchemy-python"
     exit 1
 fi
 
index d823d9ef3dbe435cae475959df33110e4e5264d9..3b882e5f95647672b86a1e2011c1bdb6c9b4ee74 100644 (file)
@@ -85,12 +85,7 @@ class OVSQuantumPlugin(QuantumPluginBase):
         config.read(configfile)
         LOG.debug("Config: %s" % config)
 
-        DB_NAME = config.get("DATABASE", "name")
-        DB_USER = config.get("DATABASE", "user")
-        DB_PASS = config.get("DATABASE", "pass")
-        DB_HOST = config.get("DATABASE", "host")
-        options = {"sql_connection": "mysql://%s:%s@%s/%s" % (DB_USER,
-          DB_PASS, DB_HOST, DB_NAME)}
+        options = {"sql_connection": config.get("DATABASE", "sql_connection")}
         db.configure_db(options)
 
         self.vmap = VlanMap()
index e93bda8ef91b398dbf034be716a930e6095e65ac..e35201d56afcccb7c68aeeddfb8e0c72662c0d0d 100644 (file)
@@ -1 +1 @@
-mysql-python
+SQLAlchemy
\ No newline at end of file