Coverage for manila/scheduler/base_handler.py: 100%
11 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright (c) 2011-2013 OpenStack Foundation.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
16"""
17A common base for handling extension classes.
19Used by BaseFilterHandler and BaseWeightHandler
20"""
22import inspect
24from stevedore import extension
27class BaseHandler(object):
28 """Base class to handle loading filter and weight classes."""
29 def __init__(self, modifier_class_type, modifier_namespace):
30 self.namespace = modifier_namespace
31 self.modifier_class_type = modifier_class_type
32 self.extension_manager = extension.ExtensionManager(modifier_namespace)
34 def _is_correct_class(self, cls):
35 """Check if an object is the correct type.
37 Return whether an object is a class of the correct type and
38 is not prefixed with an underscore.
39 """
40 return (inspect.isclass(cls) and
41 not cls.__name__.startswith('_') and
42 issubclass(cls, self.modifier_class_type))
44 def get_all_classes(self):
45 # We use a set, as some classes may have an entrypoint of their own,
46 # and also be returned by a function such as 'all_filters' for example
47 return [ext.plugin for ext in self.extension_manager if
48 self._is_correct_class(ext.plugin)]