You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
5.1 KiB

# Copyright (c) 2013 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
# 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 neutron_lib import constants as p_const
from neutron_lib import exceptions as exc
from neutron_lib.objects import exceptions as obj_base
from neutron_lib.plugins.ml2 import api
from oslo_config import cfg
from oslo_log import log
from neutron._i18n import _
from neutron.common import exceptions as n_exc
from neutron.conf.plugins.ml2.drivers import driver_type
from neutron.db import api as db_api
from neutron.objects.plugins.ml2 import flatallocation as flat_obj
from neutron.plugins.ml2.drivers import helpers
LOG = log.getLogger(__name__)
class FlatTypeDriver(helpers.BaseTypeDriver):
"""Manage state for flat networks with ML2.
The FlatTypeDriver implements the 'flat' network_type. Flat
network segments provide connectivity between VMs and other
devices using any connected IEEE 802.1D conformant
physical_network, without the use of VLAN tags, tunneling, or
other segmentation mechanisms. Therefore at most one flat network
segment can exist on each available physical_network.
def __init__(self):
super(FlatTypeDriver, self).__init__()
def _parse_networks(self, entries):
self.flat_networks = entries
if '*' in self.flat_networks:"Arbitrary flat physical_network names allowed")
self.flat_networks = None
elif not self.flat_networks:"Flat networks are disabled")
else:"Allowable flat physical_network names: %s",
def get_type(self):
return p_const.TYPE_FLAT
def initialize(self):"ML2 FlatTypeDriver initialization complete")
def is_partial_segment(self, segment):
return False
def validate_provider_segment(self, segment):
physical_network = segment.get(api.PHYSICAL_NETWORK)
if not physical_network:
msg = _("physical_network required for flat provider network")
raise exc.InvalidInput(error_message=msg)
if self.flat_networks is not None and not self.flat_networks:
msg = _("Flat provider networks are disabled")
raise exc.InvalidInput(error_message=msg)
if self.flat_networks and physical_network not in self.flat_networks:
msg = (_("physical_network '%s' unknown for flat provider network")
% physical_network)
raise exc.InvalidInput(error_message=msg)
for key, value in segment.items():
if value and key not in [api.NETWORK_TYPE,
msg = _("%s prohibited for flat provider network") % key
raise exc.InvalidInput(error_message=msg)
def reserve_provider_segment(self, context, segment):
physical_network = segment[api.PHYSICAL_NETWORK]
LOG.debug("Reserving flat network on physical "
"network %s", physical_network)
alloc = flat_obj.FlatAllocation(
except obj_base.NeutronDbObjectDuplicateEntry:
raise n_exc.FlatNetworkInUse(
segment[api.MTU] = self.get_mtu(alloc.physical_network)
return segment
def allocate_tenant_segment(self, context):
# Tenant flat networks are not supported.
def release_segment(self, context, segment):
physical_network = segment[api.PHYSICAL_NETWORK]
with db_api.context_manager.writer.using(context):
obj = flat_obj.FlatAllocation.get_object(
if obj:
LOG.debug("Releasing flat network on physical network %s",
"No flat network found on physical network %s",
def get_mtu(self, physical_network):
seg_mtu = super(FlatTypeDriver, self).get_mtu()
mtu = []
if seg_mtu > 0:
if physical_network in self.physnet_mtus:
return min(mtu) if mtu else 0