~ubuntu-branches/ubuntu/raring/nova/raring-proposed

« back to all changes in this revision

Viewing changes to nova/scheduler/filters/__init__.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2012-11-23 09:04:58 UTC
  • mfrom: (1.1.66)
  • Revision ID: package-import@ubuntu.com-20121123090458-91565o7aev1i1h71
Tags: 2013.1~g1-0ubuntu1
[ Adam Gandelman ]
* debian/control: Ensure novaclient is upgraded with nova,
  require python-keystoneclient >= 1:2.9.0. (LP: #1073289)
* debian/patches/{ubuntu/*, rbd-security.patch}: Dropped, applied
  upstream.
* debian/control: Add python-testtools to Build-Depends.

[ Chuck Short ]
* New upstream version.
* Refreshed debian/patches/avoid_setuptools_git_dependency.patch.
* debian/rules: FTBFS if missing binaries.
* debian/nova-scheudler.install: Add missing rabbit-queues and
  nova-rpc-zmq-receiver.
* Remove nova-volume since it doesnt exist anymore, transition to cinder-*.
* debian/rules: install apport hook in the right place.
* debian/patches/ubuntu-show-tests.patch: Display test failures.
* debian/control: Add depends on genisoimage
* debian/control: Suggest guestmount.
* debian/control: Suggest websockify. (LP: #1076442)
* debian/nova.conf: Disable nova-volume service.
* debian/control: Depend on xen-system-* rather than the hypervisor.
* debian/control, debian/mans/nova-conductor.8, debian/nova-conductor.init,
  debian/nova-conductor.install, debian/nova-conductor.logrotate
  debian/nova-conductor.manpages, debian/nova-conductor.postrm
  debian/nova-conductor.upstart.in: Add nova-conductor service.
* debian/control: Add python-fixtures as a build deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
Scheduler host filters
18
18
"""
19
19
 
20
 
import os
21
 
import types
22
 
 
23
 
from nova import exception
24
 
from nova.openstack.common import importutils
25
 
 
26
 
 
27
 
class BaseHostFilter(object):
 
20
from nova import filters
 
21
from nova.openstack.common import log as logging
 
22
 
 
23
LOG = logging.getLogger(__name__)
 
24
 
 
25
 
 
26
class BaseHostFilter(filters.BaseFilter):
28
27
    """Base class for host filters."""
 
28
    def _filter_one(self, obj, filter_properties):
 
29
        """Return True if the object passes the filter, otherwise False."""
 
30
        return self.host_passes(obj, filter_properties)
29
31
 
30
32
    def host_passes(self, host_state, filter_properties):
 
33
        """Return True if the HostState passes the filter, otherwise False.
 
34
        Override this in a subclass.
 
35
        """
31
36
        raise NotImplementedError()
32
37
 
33
 
    def _full_name(self):
34
 
        """module.classname of the filter."""
35
 
        return "%s.%s" % (self.__module__, self.__class__.__name__)
36
 
 
37
 
 
38
 
def _is_filter_class(cls):
39
 
    """Return whether a class is a valid Host Filter class."""
40
 
    return type(cls) is types.TypeType and issubclass(cls, BaseHostFilter)
41
 
 
42
 
 
43
 
def _get_filter_classes_from_module(module_name):
44
 
    """Get all filter classes from a module."""
45
 
    classes = []
46
 
    module = importutils.import_module(module_name)
47
 
    for obj_name in dir(module):
48
 
        itm = getattr(module, obj_name)
49
 
        if _is_filter_class(itm):
50
 
            classes.append(itm)
51
 
    return classes
 
38
 
 
39
class HostFilterHandler(filters.BaseFilterHandler):
 
40
    def __init__(self):
 
41
        super(HostFilterHandler, self).__init__(BaseHostFilter)
 
42
 
 
43
 
 
44
def all_filters():
 
45
    """Return a list of filter classes found in this directory.
 
46
 
 
47
    This method is used as the default for available scheduler filters
 
48
    and should return a list of all filter classes available.
 
49
    """
 
50
    return HostFilterHandler().get_all_classes()
52
51
 
53
52
 
54
53
def standard_filters():
55
 
    """Return a list of filter classes found in this directory."""
56
 
    classes = []
57
 
    filters_dir = __path__[0]
58
 
    for dirpath, dirnames, filenames in os.walk(filters_dir):
59
 
        relpath = os.path.relpath(dirpath, filters_dir)
60
 
        if relpath == '.':
61
 
            relpkg = ''
62
 
        else:
63
 
            relpkg = '.%s' % '.'.join(relpath.split(os.sep))
64
 
        for fname in filenames:
65
 
            root, ext = os.path.splitext(fname)
66
 
            if ext != '.py' or root == '__init__':
67
 
                continue
68
 
            module_name = "%s%s.%s" % (__package__, relpkg, root)
69
 
            mod_classes = _get_filter_classes_from_module(module_name)
70
 
            classes.extend(mod_classes)
71
 
    return classes
72
 
 
73
 
 
74
 
def get_filter_classes(filter_class_names):
75
 
    """Get filter classes from class names."""
76
 
    classes = []
77
 
    for cls_name in filter_class_names:
78
 
        obj = importutils.import_class(cls_name)
79
 
        if _is_filter_class(obj):
80
 
            classes.append(obj)
81
 
        elif type(obj) is types.FunctionType:
82
 
            # Get list of classes from a function
83
 
            classes.extend(obj())
84
 
        else:
85
 
            raise exception.ClassNotFound(class_name=cls_name,
86
 
                    exception='Not a valid scheduler filter')
87
 
    return classes
 
54
    """Deprecated.  Configs should change to use all_filters()."""
 
55
    LOG.deprecated(_("Use 'nova.scheduler.filters.all_filters' instead "
 
56
            "of 'nova.scheduler.filters.standard_filters'"))
 
57
    return all_filters()