"Fossies" - the Fresh Open Source Software Archive

Member "keystone-17.0.0/keystone/limit/models/base.py" (13 May 2020, 1891 Bytes) of package /linux/misc/openstack/keystone-17.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "base.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 16.0.1_vs_17.0.0.

    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 import abc
   13 
   14 import stevedore
   15 
   16 import keystone.conf
   17 from keystone.i18n import _
   18 
   19 CONF = keystone.conf.CONF
   20 
   21 
   22 def load_driver(driver_name, *args):
   23     namespace = 'keystone.unified_limit.model'
   24     try:
   25         driver_manager = stevedore.DriverManager(namespace,
   26                                                  driver_name,
   27                                                  invoke_on_load=True,
   28                                                  invoke_args=args)
   29         return driver_manager.driver
   30     except stevedore.exception.NoMatches:
   31         msg = (_('Unable to find %(name)r driver in %(namespace)r.'))
   32         raise ImportError(msg % {'name': driver_name, 'namespace': namespace})
   33 
   34 
   35 class ModelBase(object, metaclass=abc.ABCMeta):
   36     """Interface for a limit model driver."""
   37 
   38     NAME = None
   39     DESCRIPTION = None
   40     MAX_PROJECT_TREE_DEPTH = None
   41 
   42     def check_limit(self, limits):
   43         """Check the new creating or updating limits if satisfy the model.
   44 
   45         :param limits: A list of the limit references to be checked.
   46         :type limits: A list of the limits. Each limit is a dictionary
   47                       reference containing all limit attributes.
   48 
   49         :raises keystone.exception.InvalidLimit: If any of the input limits
   50             doesn't satisfy the limit model.
   51 
   52         """
   53         raise NotImplementedError()