~ubuntu-branches/ubuntu/raring/cinder/raring-updates

« back to all changes in this revision

Viewing changes to cinder/openstack/common/scheduler/filters/__init__.py

Tags: upstream-2013.1~g2
ImportĀ upstreamĀ versionĀ 2013.1~g2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2011 OpenStack, LLC.
 
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.
 
15
 
 
16
"""
 
17
Scheduler host filters
 
18
"""
 
19
 
 
20
from cinder.openstack.common import log as logging
 
21
from cinder.openstack.common.scheduler import filter
 
22
 
 
23
LOG = logging.getLogger(__name__)
 
24
 
 
25
 
 
26
class BaseHostFilter(filter.BaseFilter):
 
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)
 
31
 
 
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
        """
 
36
        raise NotImplementedError()
 
37
 
 
38
 
 
39
class HostFilterHandler(filter.BaseFilterHandler):
 
40
    def __init__(self, namespace):
 
41
        super(HostFilterHandler, self).__init__(BaseHostFilter, namespace)