Debian Codegraph @

neutron_lib/api/validators/multiprovidernet.py

raw
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 webob import exc
17
18 from neutron_lib._i18n import _
19 from neutron_lib.api import converters
20 from neutron_lib.api.definitions import provider_net as pnet
21 from neutron_lib import constants
22
23
24 def convert_and_validate_segments(segments, valid_values=None):
25 for segment in segments:
26 segment.setdefault(pnet.NETWORK_TYPE, constants.ATTR_NOT_SPECIFIED)
27 segment.setdefault(pnet.PHYSICAL_NETWORK, constants.ATTR_NOT_SPECIFIED)
28 segmentation_id = segment.get(pnet.SEGMENTATION_ID)
29 if segmentation_id:
30 segment[pnet.SEGMENTATION_ID] = converters.convert_to_int(
31 segmentation_id)
32 else:
33 segment[pnet.SEGMENTATION_ID] = constants.ATTR_NOT_SPECIFIED
34 if len(segment) != 3:
35 msg = (_("Unrecognized attribute(s) '%s'") %
36 ', '.join(set(segment.keys()) -
37 {pnet.NETWORK_TYPE, pnet.PHYSICAL_NETWORK,
38 pnet.SEGMENTATION_ID}))
39 raise exc.HTTPBadRequest(msg)