1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5#      http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from openstack import resource
14
15
16class Limit(resource.Resource):
17    resource_key = 'limit'
18    resources_key = 'limits'
19    base_path = '/limits'
20
21    # capabilities
22    allow_create = True
23    allow_fetch = True
24    allow_commit = True
25    allow_delete = True
26    allow_list = True
27    commit_method = 'PATCH'
28    commit_jsonpatch = True
29
30    _query_mapping = resource.QueryParameters(
31        'service_id', 'region_id', 'resource_name', 'project_id')
32
33    # Properties
34    #: User-facing description of the registered_limit. *Type: string*
35    description = resource.Body('description')
36    #: The links for the registered_limit resource.
37    links = resource.Body('links')
38    #: ID of service. *Type: string*
39    service_id = resource.Body('service_id')
40    #: ID of region, if any. *Type: string*
41    region_id = resource.Body('region_id')
42    #: The resource name. *Type: string*
43    resource_name = resource.Body('resource_name')
44    #: The resource limit value. *Type: int*
45    resource_limit = resource.Body('resource_limit')
46    #: ID of project. *Type: string*
47    project_id = resource.Body('project_id')
48
49    def _prepare_request_body(self, patch, prepend_key):
50        body = self._body.dirty
51        if prepend_key and self.resource_key is not None:
52            if patch:
53                body = {self.resource_key: body}
54            else:
55                # Keystone support bunch create for unified limit. So the
56                # request body for creating limit is a list instead of dict.
57                body = {self.resources_key: [body]}
58        return body
59