--- /dev/null
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+#
+# Copyright 2013 OpenStack Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+
+"""Remove cisco_vlan_bindings table
+
+Revision ID: b7a8863760e
+Revises: 3cabb850f4a5
+Create Date: 2013-07-03 19:15:19.143175
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'b7a8863760e'
+down_revision = '3cabb850f4a5'
+
+# Change to ['*'] if this migration applies to all plugins
+
+migration_for_plugins = [
+ 'quantum.plugins.cisco.network_plugin.PluginV2'
+]
+
+from alembic import op
+import sqlalchemy as sa
+
+
+from quantum.db import migration
+
+
+def upgrade(active_plugin=None, options=None):
+ if not migration.should_run(active_plugin, migration_for_plugins):
+ return
+
+ op.drop_table('cisco_vlan_bindings')
+
+
+def downgrade(active_plugin=None, options=None):
+ if not migration.should_run(active_plugin, migration_for_plugins):
+ return
+
+ op.create_table(
+ 'cisco_vlan_bindings',
+ sa.Column('vlan_id', sa.Integer(display_width=11), nullable=False),
+ sa.Column('vlan_name', sa.String(length=255), nullable=True),
+ sa.Column('network_id', sa.String(length=255), nullable=False),
+ sa.PrimaryKeyConstraint('vlan_id')
+ )
from sqlalchemy.orm import exc
-from quantum.common import exceptions as q_exc
from quantum.db import api as db
from quantum.openstack.common import log as logging
from quantum.plugins.cisco.common import cisco_exceptions as c_exc
filter_by(vlan_used=True).all())
-def get_all_vlan_bindings():
- """Lists all the vlan to network associations."""
- LOG.debug(_("get_all_vlan_bindings() called"))
- session = db.get_session()
- return session.query(network_models_v2.Vlan_Binding).all()
-
-
-def get_vlan_binding(netid):
- """Lists the vlan given a network_id."""
- LOG.debug(_("get_vlan_binding() called"))
- session = db.get_session()
- try:
- binding = (session.query(network_models_v2.Vlan_Binding).
- filter_by(network_id=netid).one())
- return binding
- except exc.NoResultFound:
- raise q_exc.NetworkNotFound(net_id=netid)
-
-
-def add_vlan_binding(vlanid, vlanname, netid):
- """Adds a vlan to network association."""
- LOG.debug(_("add_vlan_binding() called"))
- session = db.get_session()
- try:
- binding = (session.query(network_models_v2.Vlan_Binding).
- filter_by(vlan_id=vlanid).one())
- raise c_exc.NetworkVlanBindingAlreadyExists(vlan_id=vlanid,
- network_id=netid)
- except exc.NoResultFound:
- binding = network_models_v2.Vlan_Binding(vlanid, vlanname, netid)
- session.add(binding)
- session.flush()
- return binding
-
-
-def remove_vlan_binding(netid):
- """Removes a vlan to network association."""
- LOG.debug(_("remove_vlan_binding() called"))
- session = db.get_session()
- try:
- binding = (session.query(network_models_v2.Vlan_Binding).
- filter_by(network_id=netid).one())
- session.delete(binding)
- session.flush()
- return binding
- except exc.NoResultFound:
- pass
-
-
-def update_vlan_binding(netid, newvlanid=None, newvlanname=None):
- """Updates a vlan to network association."""
- LOG.debug(_("update_vlan_binding() called"))
- session = db.get_session()
- try:
- binding = (session.query(network_models_v2.Vlan_Binding).
- filter_by(network_id=netid).one())
- if newvlanid:
- binding["vlan_id"] = newvlanid
- if newvlanname:
- binding["vlan_name"] = newvlanname
- session.merge(binding)
- session.flush()
- return binding
- except exc.NoResultFound:
- raise q_exc.NetworkNotFound(net_id=netid)
-
-
def get_all_qoss(tenant_id):
"""Lists all the qos to tenant associations."""
LOG.debug(_("get_all_qoss() called"))
return "<VlanID(%d,%s)>" % (self.vlan_id, self.vlan_used)
-class Vlan_Binding(model_base.BASEV2, L2NetworkBase):
- """Represents a binding of vlan_id to network_id."""
- __tablename__ = 'cisco_vlan_bindings'
-
- vlan_id = Column(Integer, primary_key=True)
- vlan_name = Column(String(255))
- network_id = Column(String(255),
- nullable=False)
-
- def __init__(self, vlan_id, vlan_name, network_id):
- self.vlan_id = vlan_id
- self.vlan_name = vlan_name
- self.network_id = network_id
-
- def __repr__(self):
- return "<VlanBinding(%d,%s,%s)>" % (self.vlan_id,
- self.vlan_name,
- self.network_id)
-
-
class QoS(model_base.BASEV2, L2NetworkBase):
"""Represents QoS for a tenant."""
from quantum.plugins.cisco.common import cisco_credentials_v2 as cred
from quantum.plugins.cisco.common import cisco_exceptions as cisco_exc
from quantum.plugins.cisco.common import config as conf
-from quantum.plugins.cisco.db import network_db_v2 as cdb
from quantum.plugins.cisco.db import nexus_db_v2 as nxos_db
from quantum.plugins.cisco.l2device_plugin_base import L2DevicePluginBase
"""
LOG.debug(_("NexusPlugin:unplug_interface() called"))
- def _get_vlan_id_for_network(self, tenant_id, network_id, context,
- base_plugin_ref):
- """Obtain the VLAN ID given the Network ID."""
- vlan = cdb.get_vlan_binding(network_id)
- return vlan.vlan_id
-
def _get_network(self, tenant_id, network_id, context, base_plugin_ref):
"""Get the Network ID."""
network = base_plugin_ref._get_network(context, network_id)