From c3b2c2a9a22bac5cf17813c589444d3abebaa23b Mon Sep 17 00:00:00 2001 From: Wojciech Dec Date: Tue, 16 Aug 2016 19:27:01 +0200 Subject: Adding Mitaka networking-old module with the ODL topology based port binding resolution mechanism from https://review.openstack.org/333186 Change-Id: I10d400aac9bb639c146527f0f93e6925cb74d9de Signed-off-by: Wojciech Dec --- .../networking_odl/ml2/legacy_port_binding.py | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 networking-odl/networking_odl/ml2/legacy_port_binding.py (limited to 'networking-odl/networking_odl/ml2/legacy_port_binding.py') diff --git a/networking-odl/networking_odl/ml2/legacy_port_binding.py b/networking-odl/networking_odl/ml2/legacy_port_binding.py new file mode 100644 index 0000000..7b9b918 --- /dev/null +++ b/networking-odl/networking_odl/ml2/legacy_port_binding.py @@ -0,0 +1,84 @@ +# Copyright (c) 2016 OpenStack Foundation +# All Rights Reserved. +# +# 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. + + +from oslo_log import log + +from neutron.extensions import portbindings +from neutron.plugins.common import constants +from neutron.plugins.ml2 import driver_api +from neutron_lib import constants as n_const + +from networking_odl.ml2 import port_binding + + +LOG = log.getLogger(__name__) + + +class LegacyPortBindingManager(port_binding.PortBindingController): + + def __init__(self): + self.vif_details = {portbindings.CAP_PORT_FILTER: True} + self.supported_vnic_types = [portbindings.VNIC_NORMAL] + + def bind_port(self, port_context): + """Set binding for all valid segments + + """ + vnic_type = port_context.current.get(portbindings.VNIC_TYPE, + portbindings.VNIC_NORMAL) + if vnic_type not in self.supported_vnic_types: + LOG.debug("Refusing to bind due to unsupported vnic_type: %s", + vnic_type) + return + + valid_segment = None + for segment in port_context.segments_to_bind: + if self._check_segment(segment): + valid_segment = segment + break + + if valid_segment: + vif_type = self._get_vif_type(port_context) + LOG.debug("Bind port %(port)s on network %(network)s with valid " + "segment %(segment)s and VIF type %(vif_type)r.", + {'port': port_context.current['id'], + 'network': port_context.network.current['id'], + 'segment': valid_segment, 'vif_type': vif_type}) + + port_context.set_binding( + segment[driver_api.ID], vif_type, + self.vif_details, + status=n_const.PORT_STATUS_ACTIVE) + + def _check_segment(self, segment): + """Verify a segment is valid for the OpenDaylight MechanismDriver. + + Verify the requested segment is supported by ODL and return True or + False to indicate this to callers. + """ + + network_type = segment[driver_api.NETWORK_TYPE] + return network_type in [constants.TYPE_LOCAL, constants.TYPE_GRE, + constants.TYPE_VXLAN, constants.TYPE_VLAN] + + def _get_vif_type(self, port_context): + """Get VIF type string for given PortContext + + Dummy implementation: it always returns following constant. + neutron.extensions.portbindings.VIF_TYPE_OVS + """ + + return portbindings.VIF_TYPE_OVS -- cgit 1.2.3-korg