From 2ebb6d4d5c4d470f99b58fa3ae96156e3c993c42 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Thu, 30 Sep 2021 14:05:24 +0000 Subject: [PATCH] Rehome ``QuotaDriverAPI`` class This class is the API to create a Neutron Quota engine driver. Any other project is able to create its own Neutron Quota engine driver. Change-Id: Ia96f1f87d7bf30ffdfa1f9bac23845675b6539fd --- neutron_lib/db/quota_api.py | 169 ++++++++++++++++++ ...aDriverAPI_abc_class-1d02d0823a8886a1.yaml | 5 + 2 files changed, 174 insertions(+) create mode 100644 neutron_lib/db/quota_api.py create mode 100644 releasenotes/notes/add_QuotaDriverAPI_abc_class-1d02d0823a8886a1.yaml diff --git a/neutron_lib/db/quota_api.py b/neutron_lib/db/quota_api.py new file mode 100644 index 000000000..e6efdc2de --- /dev/null +++ b/neutron_lib/db/quota_api.py @@ -0,0 +1,169 @@ +# Copyright (c) 2021 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import abc + + +class QuotaDriverAPI(object, metaclass=abc.ABCMeta): + + @staticmethod + @abc.abstractmethod + def get_default_quotas(context, resources, project_id): + """Retrieve the default quotas for the list of resources and project. + + :param context: The request context, for access checks. + :param resources: A dictionary of the registered resource keys. + :param project_id: The ID of the project to return default quotas for. + :return: dict from resource name to dict of name and limit + """ + + @staticmethod + @abc.abstractmethod + def get_project_quotas(context, resources, project_id): + """Retrieve the quotas for the given list of resources and project + + :param context: The request context, for access checks. + :param resources: A dictionary of the registered resource keys. + :param project_id: The ID of the project to return quotas for. + :return: dict from resource name to dict of name and limit + """ + + @staticmethod + @abc.abstractmethod + def get_detailed_project_quotas(context, resources, project_id): + """Retrieve detailed quotas for the given list of resources and project + + :param context: The request context, for access checks. + :param resources: A dictionary of the registered resource keys. + :param project_id: The ID of the project to return quotas for. + :return dict: mapping resource name in dict to its corresponding limit + used and reserved. Reserved currently returns default + value of 0 + """ + + @staticmethod + @abc.abstractmethod + def delete_project_quota(context, project_id): + """Delete the quota entries for a given project_id. + + After deletion, this project will use default quota values in conf. + Raise a "not found" error if the quota for the given project was + never defined. + + :param context: The request context, for access checks. + :param project_id: The ID of the project to return quotas for. + """ + + @staticmethod + @abc.abstractmethod + def get_all_quotas(context, resources): + """Given a list of resources, retrieve the quotas for the all tenants. + + :param context: The request context, for access checks. + :param resources: A dictionary of the registered resource keys. + :return: quotas list of dict of project_id:, resourcekey1: + resourcekey2: ... + """ + + @staticmethod + @abc.abstractmethod + def update_quota_limit(context, project_id, resource, limit): + """Update the quota limit for a resource in a project + + :param context: The request context, for access checks. + :param project_id: The ID of the project to update the quota. + :param resource: the resource to update the quota. + :param limit: new resource quota limit. + """ + + @staticmethod + @abc.abstractmethod + def make_reservation(context, project_id, resources, deltas, plugin): + """Make multiple resource reservations for a given project + + :param context: The request context, for access checks. + :param resources: A dictionary of the registered resource keys. + :param project_id: The ID of the project to make the reservations for. + :return: ``ReservationInfo`` object. + """ + + @staticmethod + @abc.abstractmethod + def commit_reservation(context, reservation_id): + """Commit a reservation register + + :param context: The request context, for access checks. + :param reservation_id: ID of the reservation register to commit. + """ + + @staticmethod + @abc.abstractmethod + def cancel_reservation(context, reservation_id): + """Cancel a reservation register + + :param context: The request context, for access checks. + :param reservation_id: ID of the reservation register to cancel. + """ + + @staticmethod + @abc.abstractmethod + def limit_check(context, project_id, resources, values): + """Check simple quota limits. + + For limits--those quotas for which there is no usage + synchronization function--this method checks that a set of + proposed values are permitted by the limit restriction. + + If any of the proposed values is over the defined quota, an + OverQuota exception will be raised with the sorted list of the + resources which are too high. Otherwise, the method returns + nothing. + + :param context: The request context, for access checks. + :param project_id: The ID of the project to make the reservations for. + :param resources: A dictionary of the registered resource. + :param values: A dictionary of the values to check against the + quota. + """ + + @staticmethod + @abc.abstractmethod + def get_resource_usage(context, project_id, resources, resource_name): + """Return the resource current usage + + :param context: The request context, for access checks. + :param project_id: The ID of the project to make the reservations for. + :param resources: A dictionary of the registered resources. + :param resource_name: The name of the resource to retrieve the usage. + :return: The current resource usage. + """ + + @staticmethod + @abc.abstractmethod + def quota_limit_check(context, project_id, resources, deltas): + """Check the current resource usage against a set of deltas. + + This method will check if the provided resource deltas could be + assigned depending on the current resource usage and the quota limits. + If the resource deltas plus the resource usage fit under the quota + limit, the method will pass. If not, a ``OverQuota`` will be raised. + + :param context: The request context, for access checks. + :param project_id: The ID of the project to make the reservations for. + :param resources: A dictionary of the registered resource. + :param deltas: A dictionary of the values to check against the + quota limits. + :return: None if passed; ``OverQuota`` if quota limits are exceeded, + ``InvalidQuotaValue`` if delta values are invalid. + """ diff --git a/releasenotes/notes/add_QuotaDriverAPI_abc_class-1d02d0823a8886a1.yaml b/releasenotes/notes/add_QuotaDriverAPI_abc_class-1d02d0823a8886a1.yaml new file mode 100644 index 000000000..82feaa33d --- /dev/null +++ b/releasenotes/notes/add_QuotaDriverAPI_abc_class-1d02d0823a8886a1.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Added ``QuotaDriverAPI`` abstract class. This class is the API to create + any Neutron Quota engine driver.