1 # Copyright (c) 2012 OpenStack Foundation.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
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
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)
27 # Common definitions for maximum string field length
28 NETWORK_TYPE_MAX_LEN = 32
29 PHYSICAL_NETWORK_MAX_LEN = 64
31 EXTENDED_ATTRIBUTES_2_0 = {
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,
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,
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,
53 def _raise_if_updates_provider_attributes(attrs):
54 """Raise exception if provider attributes are present.
56 This method is used for plugins that do not support
57 updating provider networks.
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)
64 class Providernet(extensions.ExtensionDescriptor):
65 """Extension class supporting provider networks.
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.
73 With admin rights, network dictionaries returned will also include
79 return "Provider Network"
86 def get_description(cls):
87 return "Expose mapping of virtual networks to physical networks"
91 return "2012-09-07T10:00:00-00:00"
93 def get_extended_resources(self, version):
95 return EXTENDED_ATTRIBUTES_2_0