~ubuntuone-pqm-team/python-keystoneclient/trunk

« back to all changes in this revision

Viewing changes to keystoneclient/v3/limits.py

  • Committer: Douglas Mendizábal
  • Author(s): OpenStack Release Bot
  • Date: 2022-03-04 16:43:46 UTC
  • Revision ID: git-v1:8d8c31e5008326520206804fbdabf96993ab0c45
Update master for stable/xena

Add file to the reno documentation build to show release notes for
stable/xena.

Use pbr instruction to increment the minor version number
automatically so that master versions are higher than the versions on
stable/xena.

Sem-Ver: feature
Change-Id: Id7127c22dd9865c8ac08a1239f0ba483b9dacddc

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
13
from keystoneclient import base
 
14
 
 
15
 
 
16
class Limit(base.Resource):
 
17
    """Represents a project limit.
 
18
 
 
19
    Attributes:
 
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
 
27
 
 
28
    """
 
29
 
 
30
    pass
 
31
 
 
32
 
 
33
class LimitManager(base.CrudManager):
 
34
    """Manager class for project limits."""
 
35
 
 
36
    resource_class = Limit
 
37
    collection_key = 'limits'
 
38
    key = 'limit'
 
39
 
 
40
    def create(self, project, service, resource_name, resource_limit,
 
41
               description=None, region=None, **kwargs):
 
42
        """Create a project-specific limit.
 
43
 
 
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`
 
56
 
 
57
        :returns: a reference of the created limit
 
58
        :rtype: :class:`keystoneclient.v3.limits.Limit`
 
59
 
 
60
        """
 
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),
 
68
            **kwargs
 
69
        )
 
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,
 
74
                                          self.resource_class(
 
75
                                              self, limit))
 
76
 
 
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.
 
80
 
 
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
 
88
 
 
89
        :returns: a reference of the updated limit.
 
90
        :rtype: :class:`keystoneclient.v3.limits.Limit`
 
91
 
 
92
        """
 
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,
 
100
            **kwargs
 
101
        )
 
102
 
 
103
    def get(self, limit):
 
104
        """Retrieve a project limit.
 
105
 
 
106
        :param limit:
 
107
            the project-specific limit to be retrieved.
 
108
        :type limit:
 
109
            str or :class:`keystoneclient.v3.limit.Limit`
 
110
 
 
111
        :returns: a project-specific limit
 
112
        :rtype: :class:`keystoneclient.v3.limit.Limit`
 
113
 
 
114
        """
 
115
        return super(LimitManager, self).get(limit_id=base.getid(limit))
 
116
 
 
117
    def list(self, service=None, region=None, resource_name=None, **kwargs):
 
118
        """List project-specific limits.
 
119
 
 
120
        Any parameter provided will be passed to the server as a filter
 
121
 
 
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
 
128
 
 
129
        :returns: a list of project-specific limits.
 
130
        :rtype: list of :class:`keystoneclient.v3.limits.Limit`
 
131
 
 
132
        """
 
133
        return super(LimitManager, self).list(
 
134
            service_id=base.getid(service),
 
135
            region_id=base.getid(region),
 
136
            resource_name=resource_name,
 
137
            **kwargs
 
138
        )
 
139
 
 
140
    def delete(self, limit):
 
141
        """Delete a project-specific limit.
 
142
 
 
143
        :param limit: the project-specific limit to be deleted.
 
144
        :type limit: str or :class:`keystoneclient.v3.limit.Limit`
 
145
 
 
146
        :returns: Response object with 204 status
 
147
        :rtype: :class:`requests.models.Response`
 
148
 
 
149
        """
 
150
        return super(LimitManager, self).delete(limit_id=base.getid(limit))