Merge "Set BigSwitch plugin to use existing host database model"

This commit is contained in:
Jenkins 2013-08-19 16:17:15 +00:00 committed by Gerrit Code Review
commit e3489b3b53
4 changed files with 74 additions and 21 deletions

View File

@ -32,6 +32,7 @@ down_revision = 'f489cf14a79c'
migration_for_plugins = [
'neutron.plugins.openvswitch.ovs_neutron_plugin.OVSNeutronPluginV2',
'neutron.plugins.linuxbridge.lb_neutron_plugin.LinuxBridgePluginV2',
'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2',
'neutron.plugins.nicira.NeutronPlugin.NvpPluginV2',
]

View File

@ -0,0 +1,59 @@
# 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 bigswitch port tracking table
Revision ID: 86cf4d88bd3
Revises: 569e98a8132b
Create Date: 2013-08-13 21:59:04.373496
"""
# revision identifiers, used by Alembic.
revision = '86cf4d88bd3'
down_revision = '569e98a8132b'
# Change to ['*'] if this migration applies to all plugins
migration_for_plugins = [
'neutron.plugins.bigswitch.plugin.NeutronRestProxyV2'
]
from alembic import op
import sqlalchemy as sa
from neutron.db import migration
def upgrade(active_plugins=None, options=None):
if not migration.should_run(active_plugins, migration_for_plugins):
return
op.drop_table('portlocations')
def downgrade(active_plugins=None, options=None):
if not migration.should_run(active_plugins, migration_for_plugins):
return
op.create_table('portlocations',
sa.Column('port_id', sa.String(length=255),
primary_key=True, nullable=False),
sa.Column('host_id',
sa.String(length=255), nullable=False)
)

View File

@ -15,36 +15,29 @@
# License for the specific language governing permissions and limitations
# under the License.
import sqlalchemy as sa
from neutron.api.v2 import attributes
from neutron.db import model_base
from neutron.db import portbindings_db
from neutron.openstack.common import log as logging
LOG = logging.getLogger(__name__)
class PortLocation(model_base.BASEV2):
port_id = sa.Column(sa.String(255), primary_key=True)
host_id = sa.Column(sa.String(255), nullable=False)
def get_port_hostid(context, port_id):
with context.session.begin(subtransactions=True):
query = context.session.query(PortLocation)
query = context.session.query(portbindings_db.PortBindingPort)
res = query.filter_by(port_id=port_id).first()
if not res:
return False
return res.host_id
return res.host
def put_port_hostid(context, port_id, host_id):
if not attributes.is_attr_set(host_id):
def put_port_hostid(context, port_id, host):
if not attributes.is_attr_set(host):
LOG.warning(_("No host_id in port request to track port location."))
return
if port_id == '':
LOG.warning(_("Received an empty port ID for host '%s'"), host_id)
LOG.warning(_("Received an empty port ID for host '%s'"), host)
return
with context.session.begin(subtransactions=True):
location = PortLocation(port_id=port_id, host_id=host_id)
location = portbindings_db.PortBindingPort(port_id=port_id, host=host)
context.session.merge(location)

View File

@ -560,11 +560,11 @@ class NeutronRestProxyV2(db_base_plugin_v2.NeutronDbPluginV2,
# Update DB
port["port"]["admin_state_up"] = False
if (portbindings.HOST_ID in port['port']
and 'device_id' in port['port']):
porttracker_db.put_port_hostid(context, port['port']['device_id'],
port['port'][portbindings.HOST_ID])
new_port = super(NeutronRestProxyV2, self).create_port(context, port)
if (portbindings.HOST_ID in port['port']
and 'id' in new_port):
porttracker_db.put_port_hostid(context, new_port['id'],
port['port'][portbindings.HOST_ID])
net = super(NeutronRestProxyV2,
self).get_network(context, new_port["network_id"])
@ -657,8 +657,8 @@ class NeutronRestProxyV2(db_base_plugin_v2.NeutronDbPluginV2,
new_port = super(NeutronRestProxyV2, self).update_port(context,
port_id, port)
if (portbindings.HOST_ID in port['port']
and 'device_id' in port['port']):
porttracker_db.put_port_hostid(context, port['port']['device_id'],
and 'id' in new_port):
porttracker_db.put_port_hostid(context, new_port['id'],
port['port'][portbindings.HOST_ID])
# update on networl ctrl
try:
@ -1335,7 +1335,7 @@ class NeutronRestProxyV2(db_base_plugin_v2.NeutronDbPluginV2,
cfg_vif_type)
cfg_vif_type = portbindings.VIF_TYPE_OVS
hostid = porttracker_db.get_port_hostid(context,
port.get("device_id"))
port['id'])
if hostid:
override = self._check_hostvif_override(hostid)
if override: