Debian Codegraph @

neutron_lib/db/quota_api.py

raw
1 # Copyright (c) 2021 Red Hat, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 import abc
16
17
18 class QuotaDriverAPI(metaclass=abc.ABCMeta):
19
20 @staticmethod
21 @abc.abstractmethod
22 def get_default_quotas(context, resources, project_id):
23 """Retrieve the default quotas for the list of resources and project.
24
25 :param context: The request context, for access checks.
26 :param resources: A dictionary of the registered resource keys.
27 :param project_id: The ID of the project to return default quotas for.
28 :return: dict from resource name to dict of name and limit
29 """
30
31 @staticmethod
32 @abc.abstractmethod
33 def get_project_quotas(context, resources, project_id):
34 """Retrieve the quotas for the given list of resources and project
35
36 :param context: The request context, for access checks.
37 :param resources: A dictionary of the registered resource keys.
38 :param project_id: The ID of the project to return quotas for.
39 :return: dict from resource name to dict of name and limit
40 """
41
42 @staticmethod
43 @abc.abstractmethod
44 def get_detailed_project_quotas(context, resources, project_id):
45 """Retrieve detailed quotas for the given list of resources and project
46
47 :param context: The request context, for access checks.
48 :param resources: A dictionary of the registered resource keys.
49 :param project_id: The ID of the project to return quotas for.
50 :return dict: mapping resource name in dict to its corresponding limit
51 used and reserved. Reserved currently returns default
52 value of 0
53 """
54
55 @staticmethod
56 @abc.abstractmethod
57 def delete_project_quota(context, project_id):
58 """Delete the quota entries for a given project_id.
59
60 After deletion, this project will use default quota values in conf.
61 Raise a "not found" error if the quota for the given project was
62 never defined.
63
64 :param context: The request context, for access checks.
65 :param project_id: The ID of the project to return quotas for.
66 """
67
68 @staticmethod
69 @abc.abstractmethod
70 def get_all_quotas(context, resources):
71 """Given a list of resources, retrieve the quotas for the all tenants.
72
73 :param context: The request context, for access checks.
74 :param resources: A dictionary of the registered resource keys.
75 :return: quotas list of dict of project_id:, resourcekey1:
76 resourcekey2: ...
77 """
78
79 @staticmethod
80 @abc.abstractmethod
81 def update_quota_limit(context, project_id, resource, limit):
82 """Update the quota limit for a resource in a project
83
84 :param context: The request context, for access checks.
85 :param project_id: The ID of the project to update the quota.
86 :param resource: the resource to update the quota.
87 :param limit: new resource quota limit.
88 """
89
90 @staticmethod
91 @abc.abstractmethod
92 def make_reservation(context, project_id, resources, deltas, plugin):
93 """Make multiple resource reservations for a given project
94
95 :param context: The request context, for access checks.
96 :param resources: A dictionary of the registered resource keys.
97 :param project_id: The ID of the project to make the reservations for.
98 :return: ``ReservationInfo`` object.
99 """
100
101 @staticmethod
102 @abc.abstractmethod
103 def commit_reservation(context, reservation_id):
104 """Commit a reservation register
105
106 :param context: The request context, for access checks.
107 :param reservation_id: ID of the reservation register to commit.
108 """
109
110 @staticmethod
111 @abc.abstractmethod
112 def cancel_reservation(context, reservation_id):
113 """Cancel a reservation register
114
115 :param context: The request context, for access checks.
116 :param reservation_id: ID of the reservation register to cancel.
117 """
118
119 @staticmethod
120 @abc.abstractmethod
121 def limit_check(context, project_id, resources, values):
122 """Check simple quota limits.
123
124 For limits--those quotas for which there is no usage
125 synchronization function--this method checks that a set of
126 proposed values are permitted by the limit restriction.
127
128 If any of the proposed values is over the defined quota, an
129 OverQuota exception will be raised with the sorted list of the
130 resources which are too high. Otherwise, the method returns
131 nothing.
132
133 :param context: The request context, for access checks.
134 :param project_id: The ID of the project to make the reservations for.
135 :param resources: A dictionary of the registered resource.
136 :param values: A dictionary of the values to check against the
137 quota.
138 """
139
140 @staticmethod
141 @abc.abstractmethod
142 def get_resource_usage(context, project_id, resources, resource_name):
143 """Return the resource current usage
144
145 :param context: The request context, for access checks.
146 :param project_id: The ID of the project to make the reservations for.
147 :param resources: A dictionary of the registered resources.
148 :param resource_name: The name of the resource to retrieve the usage.
149 :return: The current resource usage.
150 """
151
152 @staticmethod
153 @abc.abstractmethod
154 def quota_limit_check(context, project_id, resources, deltas):
155 """Check the current resource usage against a set of deltas.
156
157 This method will check if the provided resource deltas could be
158 assigned depending on the current resource usage and the quota limits.
159 If the resource deltas plus the resource usage fit under the quota
160 limit, the method will pass. If not, a ``OverQuota`` will be raised.
161
162 :param context: The request context, for access checks.
163 :param project_id: The ID of the project to make the reservations for.
164 :param resources: A dictionary of the registered resource.
165 :param deltas: A dictionary of the values to check against the
166 quota limits.
167 :return: None if passed; ``OverQuota`` if quota limits are exceeded,
168 ``InvalidQuotaValue`` if delta values are invalid.
169 """
170
171 @staticmethod
172 @abc.abstractmethod
173 def get_workers():
174 """Return the quota driver workers to be spawned during initialization
175
176 This method returns the quota driver workers that needs to be spawned
177 during the plugin initialization. For example, ``DbQuotaNoLockDriver``
178 requires a ``PeriodicWorker`` to clean up the expired reservations left
179 in the database.
180
181 :return: list of ``worker.BaseWorker`` or derived instances.
182 """