1 # Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
15 from oslo_config import cfg
16 from oslo_log import log as logging
18 from neutron._i18n import _, _LI
19 from neutron.api import extensions
20 from neutron.api.v2 import attributes
21 from neutron.common import exceptions as nexception
23 LOG = logging.getLogger(__name__)
26 class VlanTransparencyDriverError(nexception.NeutronException):
27 """Vlan Transparency not supported by all mechanism drivers."""
28 message = _("Backend does not support VLAN Transparency.")
31 VLANTRANSPARENT = 'vlan_transparent'
32 EXTENDED_ATTRIBUTES_2_0 = {
34 VLANTRANSPARENT: {'allow_post': True, 'allow_put': False,
35 'convert_to': attributes.convert_to_boolean,
36 'default': attributes.ATTR_NOT_SPECIFIED,
42 def disable_extension_by_config(aliases):
43 if not cfg.CONF.vlan_transparent:
44 if 'vlan-transparent' in aliases:
45 aliases.remove('vlan-transparent')
46 LOG.info(_LI('Disabled vlantransparent extension.'))
49 def get_vlan_transparent(network):
50 return (network['vlan_transparent']
51 if ('vlan_transparent' in network and
52 attributes.is_attr_set(network['vlan_transparent']))
56 class Vlantransparent(extensions.ExtensionDescriptor):
57 """Extension class supporting vlan transparent networks."""
61 return "Vlantransparent"
65 return "vlan-transparent"
68 def get_description(cls):
69 return "Provides Vlan Transparent Networks"
73 return "2015-03-23T09:00:00-00:00"
75 def get_extended_resources(self, version):
77 return EXTENDED_ATTRIBUTES_2_0