| 1 |
# Copyright (c) 2013 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_lib.api import converters |
| 17 |
from neutron_lib.api.definitions import network |
| 18 |
from neutron_lib.api import validators |
| 19 |
from neutron_lib.api.validators import multiprovidernet as mp_validator |
| 20 |
from neutron_lib import constants |
| 21 |
from neutron_lib.exceptions import multiprovidernet as mp_exc |
| 22 |
|
| 23 |
|
| 24 |
def check_duplicate_segments(segments, is_partial_func=None): |
| 25 |
"""Helper function checking duplicate segments. |
| 26 |
|
| 27 |
If is_partial_funcs is specified and not None, then |
| 28 |
SegmentsContainDuplicateEntry is raised if two segments are identical and |
| 29 |
non partially defined (is_partial_func(segment) == False). |
| 30 |
Otherwise SegmentsContainDuplicateEntry is raised if two segment are |
| 31 |
identical. |
| 32 |
""" |
| 33 |
if is_partial_func is not None: |
| 34 |
segments = [s for s in segments if not is_partial_func(s)] |
| 35 |
fully_specifieds = [tuple(sorted(s.items())) for s in segments] |
| 36 |
if len(set(fully_specifieds)) != len(fully_specifieds): |
| 37 |
raise mp_exc.SegmentsContainDuplicateEntry() |
| 38 |
|
| 39 |
|
| 40 |
validators.add_validator( |
| 41 |
'network_segments', mp_validator.convert_and_validate_segments) |
| 42 |
|
| 43 |
SEGMENTS = 'segments' |
| 44 |
|
| 45 |
ALIAS = 'multi-provider' |
| 46 |
IS_SHIM_EXTENSION = False |
| 47 |
IS_STANDARD_ATTR_EXTENSION = False |
| 48 |
NAME = 'Multi Provider Network' |
| 49 |
API_PREFIX = '' |
| 50 |
DESCRIPTION = ("Expose mapping of virtual networks to multiple physical " |
| 51 |
"networks") |
| 52 |
UPDATED_TIMESTAMP = '2013-06-27T10:00:00-00:00' |
| 53 |
RESOURCE_NAME = network.RESOURCE_NAME |
| 54 |
COLLECTION_NAME = network.COLLECTION_NAME |
| 55 |
RESOURCE_ATTRIBUTE_MAP = { |
| 56 |
COLLECTION_NAME: { |
| 57 |
SEGMENTS: { |
| 58 |
'allow_post': True, 'allow_put': True, |
| 59 |
'validate': {'type:network_segments': None}, |
| 60 |
'convert_list_to': converters.convert_kvp_list_to_dict, |
| 61 |
'default': constants.ATTR_NOT_SPECIFIED, |
| 62 |
'enforce_policy': True, |
| 63 |
'is_visible': True |
| 64 |
}, |
| 65 |
} |
| 66 |
} |
| 67 |
SUB_RESOURCE_ATTRIBUTE_MAP = {} |
| 68 |
ACTION_MAP = {} |
| 69 |
REQUIRED_EXTENSIONS = [] |
| 70 |
OPTIONAL_EXTENSIONS = [] |
| 71 |
ACTION_STATUS = {} |