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
5
# http://www.apache.org/licenses/LICENSE-2.0
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
13
from keystoneclient import base
16
class Limit(base.Resource):
17
"""Represents a project limit.
20
* id: a UUID that identifies the project limit
21
* service_id: a UUID that identifies the service for the limit
22
* region_id: a UUID that identifies the region for the limit
23
* project_id: a UUID that identifies the project for the limit
24
* resource_name: the name of the resource to limit
25
* resource_limit: the limit to apply to the project
26
* description: a description for the project limit
33
class LimitManager(base.CrudManager):
34
"""Manager class for project limits."""
36
resource_class = Limit
37
collection_key = 'limits'
40
def create(self, project, service, resource_name, resource_limit,
41
description=None, region=None, **kwargs):
42
"""Create a project-specific limit.
44
:param project: the project to create a limit for.
45
:type project: str or :class:`keystoneclient.v3.projects.Project`
46
:param service: the service that owns the resource to limit.
47
:type service: str or :class:`keystoneclient.v3.services.Service`
48
:param resource_name: the name of the resource to limit
49
:type resource_name: str
50
:param resource_limit: the quantity of the limit
51
:type resource_limit: int
52
:param description: a description of the limit
53
:type description: str
54
:param region: region the limit applies to
55
:type region: str or :class:`keystoneclient.v3.regions.Region`
57
:returns: a reference of the created limit
58
:rtype: :class:`keystoneclient.v3.limits.Limit`
61
limit_data = base.filter_none(
62
project_id=base.getid(project),
63
service_id=base.getid(service),
64
resource_name=resource_name,
65
resource_limit=resource_limit,
66
description=description,
67
region_id=base.getid(region),
70
body = {self.collection_key: [limit_data]}
71
resp, body = self.client.post('/limits', body=body)
72
limit = body[self.collection_key].pop()
73
return self._prepare_return_value(resp,
77
def update(self, limit, project=None, service=None, resource_name=None,
78
resource_limit=None, description=None, **kwargs):
79
"""Update a project-specific limit.
81
:param limit: a limit to update
82
:param project: the project ID of the limit to update
83
:type project: str or :class:`keystoneclient.v3.projects.Project`
84
:param resource_limit: the limit of the limit's resource to update
85
:type: resource_limit: int
86
:param description: a description of the limit
87
:type description: str
89
:returns: a reference of the updated limit.
90
:rtype: :class:`keystoneclient.v3.limits.Limit`
93
return super(LimitManager, self).update(
94
limit_id=base.getid(limit),
95
project_id=base.getid(project),
96
service_id=base.getid(service),
97
resource_name=resource_name,
98
resource_limit=resource_limit,
99
description=description,
103
def get(self, limit):
104
"""Retrieve a project limit.
107
the project-specific limit to be retrieved.
109
str or :class:`keystoneclient.v3.limit.Limit`
111
:returns: a project-specific limit
112
:rtype: :class:`keystoneclient.v3.limit.Limit`
115
return super(LimitManager, self).get(limit_id=base.getid(limit))
117
def list(self, service=None, region=None, resource_name=None, **kwargs):
118
"""List project-specific limits.
120
Any parameter provided will be passed to the server as a filter
122
:param service: service to filter limits by
123
:type service: UUID or :class:`keystoneclient.v3.services.Service`
124
:param region: region to filter limits by
125
:type region: UUID or :class:`keystoneclient.v3.regions.Region`
126
:param resource_name: the name of the resource to filter limits by
127
:type resource_name: str
129
:returns: a list of project-specific limits.
130
:rtype: list of :class:`keystoneclient.v3.limits.Limit`
133
return super(LimitManager, self).list(
134
service_id=base.getid(service),
135
region_id=base.getid(region),
136
resource_name=resource_name,
140
def delete(self, limit):
141
"""Delete a project-specific limit.
143
:param limit: the project-specific limit to be deleted.
144
:type limit: str or :class:`keystoneclient.v3.limit.Limit`
146
:returns: Response object with 204 status
147
:rtype: :class:`requests.models.Response`
150
return super(LimitManager, self).delete(limit_id=base.getid(limit))