Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / extensions / vlantransparent.py
1 # Copyright (c) 2015 Cisco Systems, Inc.  All rights reserved.
2 #
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
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
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
13 #    under the License.
14
15 from oslo_config import cfg
16 from oslo_log import log as logging
17
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
22
23 LOG = logging.getLogger(__name__)
24
25
26 class VlanTransparencyDriverError(nexception.NeutronException):
27     """Vlan Transparency not supported by all mechanism drivers."""
28     message = _("Backend does not support VLAN Transparency.")
29
30
31 VLANTRANSPARENT = 'vlan_transparent'
32 EXTENDED_ATTRIBUTES_2_0 = {
33     'networks': {
34         VLANTRANSPARENT: {'allow_post': True, 'allow_put': False,
35                           'convert_to': attributes.convert_to_boolean,
36                           'default': attributes.ATTR_NOT_SPECIFIED,
37                           'is_visible': True},
38     },
39 }
40
41
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.'))
47
48
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']))
53             else False)
54
55
56 class Vlantransparent(extensions.ExtensionDescriptor):
57     """Extension class supporting vlan transparent networks."""
58
59     @classmethod
60     def get_name(cls):
61         return "Vlantransparent"
62
63     @classmethod
64     def get_alias(cls):
65         return "vlan-transparent"
66
67     @classmethod
68     def get_description(cls):
69         return "Provides Vlan Transparent Networks"
70
71     @classmethod
72     def get_updated(cls):
73         return "2015-03-23T09:00:00-00:00"
74
75     def get_extended_resources(self, version):
76         if version == "2.0":
77             return EXTENDED_ATTRIBUTES_2_0
78         else:
79             return {}