Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / pecan_wsgi / hooks / body_validation.py
1 # Copyright (c) 2015 Mirantis, Inc.
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 pecan import hooks
17
18 from neutron.api.v2 import attributes as v2_attributes
19 from neutron.api.v2 import base as v2_base
20
21
22 class BodyValidationHook(hooks.PecanHook):
23
24     priority = 120
25
26     def before(self, state):
27         if state.request.method not in ('POST', 'PUT'):
28             return
29         resource = state.request.context.get('resource')
30         collection = state.request.context.get('collection')
31         neutron_context = state.request.context['neutron_context']
32         is_create = state.request.method == 'POST'
33         if not resource:
34             return
35         # Prepare data to be passed to the plugin from request body
36         data = v2_base.Controller.prepare_request_body(
37             neutron_context,
38             state.request.json,
39             is_create,
40             resource,
41             v2_attributes.get_collection_info(collection),
42             allow_bulk=is_create)
43         if collection in data:
44             state.request.context['resources'] = [item[resource] for item in
45                                                   data[collection]]
46         else:
47             state.request.context['resources'] = [data[resource]]