Merge "BGP service - take logical port info from Neutron DB"

This commit is contained in:
Zuul 2018-02-25 10:31:22 +00:00 committed by Gerrit Code Review
commit e90c9ab773
2 changed files with 11 additions and 13 deletions

View File

@ -98,7 +98,7 @@ def _build_dhcp_params(port):
return ret
def _build_port_binding(port):
def build_port_binding(port):
profile = port.get(portbindings.PROFILE)
if profile:
port_key = profile.get(df_const.DF_BINDING_PROFILE_PORT_KEY)
@ -142,5 +142,5 @@ def logical_port_from_neutron_port(port):
binding_vnic_type=port.get(portbindings.VNIC_TYPE),
qos_policy=port.get('qos_policy_id'),
dhcp_params=_build_dhcp_params(port),
binding=_build_port_binding(port),
binding=build_port_binding(port),
)

View File

@ -17,6 +17,7 @@ from neutron_lib.callbacks import registry
from neutron_lib.callbacks import resources
from neutron_lib import constants as n_const
from neutron_lib import context as n_context
from neutron_lib.plugins import directory
from neutron_lib.services import base as service_base
from oslo_log import log as logging
@ -25,6 +26,7 @@ from dragonflow.db.models import bgp
from dragonflow.db.models import core
from dragonflow.db.models import l2
from dragonflow.db.neutron import lockedobjects_db as lock_db
from dragonflow.neutron.db.models import l2 as neutron_l2
from dragonflow.neutron.services import mixins
@ -68,7 +70,6 @@ class DFBgpPlugin(service_base.ServicePluginBase,
def __init__(self):
super(DFBgpPlugin, self).__init__()
self._nb_api = None
self._register_callbacks()
def get_plugin_name(self):
@ -102,14 +103,12 @@ class DFBgpPlugin(service_base.ServicePluginBase,
def floatingip_update_callback(self, resource, event, trigger, **kwargs):
context = kwargs['context']
port_id = kwargs['fixed_port_id']
floating_ip_address = kwargs['floating_ip_address']
floating_ip_address = str(kwargs['floating_ip_address'])
dest = floating_ip_address + '/32'
if port_id:
# Associate floatingip
project_id = _get_project_id_from_context(context)
external_ip = self._get_external_ip_of_lport(port_id,
project_id)
external_ip = self._get_external_ip_of_lport(context, port_id)
if not external_ip:
return
@ -128,14 +127,13 @@ class DFBgpPlugin(service_base.ServicePluginBase,
for speaker in bgp_speakers:
fip_handler(context, speaker.id, speaker.project_id, fip_data)
def _get_external_ip_of_lport(self, lport_id, topic):
"""Get the accessible external ip of chassis where lport resides in"""
lport = self.nb_api.get(l2.LogicalPort(id=lport_id, topic=topic))
binding = lport.binding
def _get_external_ip_of_lport(self, context, port_id):
"""Get the accessible external ip of the chassis where lport resides"""
port = directory.get_plugin().get_port(context, port_id)
binding = neutron_l2.build_port_binding(port)
if not binding:
LOG.warning(
'Logical port %s has not been bound to any host yet', lport_id)
'Logical port %s has not been bound to any host yet', port_id)
return
if binding.type == l2.BINDING_VTEP: