Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / extensions / providernet.py
1 # Copyright (c) 2012 OpenStack Foundation.
2 # All rights reserved.
3 #
4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
5 #    not use this file except in compliance with the License. You may obtain
6 #    a copy of the License at
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 #    License for the specific language governing permissions and limitations
14 #    under the License.
15
16 from neutron._i18n import _
17 from neutron.api import extensions
18 from neutron.api.v2 import attributes
19 from neutron.common import exceptions as n_exc
20
21
22 NETWORK_TYPE = 'provider:network_type'
23 PHYSICAL_NETWORK = 'provider:physical_network'
24 SEGMENTATION_ID = 'provider:segmentation_id'
25 ATTRIBUTES = (NETWORK_TYPE, PHYSICAL_NETWORK, SEGMENTATION_ID)
26
27 # Common definitions for maximum string field length
28 NETWORK_TYPE_MAX_LEN = 32
29 PHYSICAL_NETWORK_MAX_LEN = 64
30
31 EXTENDED_ATTRIBUTES_2_0 = {
32     'networks': {
33         NETWORK_TYPE: {'allow_post': True, 'allow_put': True,
34                        'validate': {'type:string': NETWORK_TYPE_MAX_LEN},
35                        'default': attributes.ATTR_NOT_SPECIFIED,
36                        'enforce_policy': True,
37                        'is_visible': True},
38         PHYSICAL_NETWORK: {'allow_post': True, 'allow_put': True,
39                            'validate': {'type:string':
40                                         PHYSICAL_NETWORK_MAX_LEN},
41                            'default': attributes.ATTR_NOT_SPECIFIED,
42                            'enforce_policy': True,
43                            'is_visible': True},
44         SEGMENTATION_ID: {'allow_post': True, 'allow_put': True,
45                           'convert_to': attributes.convert_to_int,
46                           'enforce_policy': True,
47                           'default': attributes.ATTR_NOT_SPECIFIED,
48                           'is_visible': True},
49     }
50 }
51
52
53 def _raise_if_updates_provider_attributes(attrs):
54     """Raise exception if provider attributes are present.
55
56     This method is used for plugins that do not support
57     updating provider networks.
58     """
59     if any(attributes.is_attr_set(attrs.get(a)) for a in ATTRIBUTES):
60         msg = _("Plugin does not support updating provider attributes")
61         raise n_exc.InvalidInput(error_message=msg)
62
63
64 class Providernet(extensions.ExtensionDescriptor):
65     """Extension class supporting provider networks.
66
67     This class is used by neutron's extension framework to make
68     metadata about the provider network extension available to
69     clients. No new resources are defined by this extension. Instead,
70     the existing network resource's request and response messages are
71     extended with attributes in the provider namespace.
72
73     With admin rights, network dictionaries returned will also include
74     provider attributes.
75     """
76
77     @classmethod
78     def get_name(cls):
79         return "Provider Network"
80
81     @classmethod
82     def get_alias(cls):
83         return "provider"
84
85     @classmethod
86     def get_description(cls):
87         return "Expose mapping of virtual networks to physical networks"
88
89     @classmethod
90     def get_updated(cls):
91         return "2012-09-07T10:00:00-00:00"
92
93     def get_extended_resources(self, version):
94         if version == "2.0":
95             return EXTENDED_ATTRIBUTES_2_0
96         else:
97             return {}