Skip to content

Commit

Permalink
Move oslo-incubator's scheduler module to cinder
Browse files Browse the repository at this point in the history
oslo-incubator is ending its life and we should move remaining
dependencies from there to cinder namespace. This commit does so with
openstack.common.scheduler. Apart from that tests from oslo-incubator
repository are added.

Change-Id: I10d88c120c9c847826986483065f5493e91f89d6
Closes-Bug: 1519337
  • Loading branch information
Michał Dulko committed Nov 24, 2015
1 parent cbd26a4 commit fab6b4e
Show file tree
Hide file tree
Showing 32 changed files with 1,079 additions and 136 deletions.
Empty file.
38 changes: 0 additions & 38 deletions cinder/openstack/common/scheduler/filters/__init__.py

This file was deleted.

45 changes: 0 additions & 45 deletions cinder/openstack/common/scheduler/weights/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import logging

from cinder.openstack.common._i18n import _LI
from cinder.openstack.common.scheduler import base_handler
from cinder.scheduler import base_handler

LOG = logging.getLogger(__name__)

Expand All @@ -28,6 +28,7 @@ class BaseFilter(object):
"""Base class for all filter classes."""
def _filter_one(self, obj, filter_properties):
"""Return True if it passes the filter, False otherwise.
Override this in a subclass.
"""
return True
Expand All @@ -48,9 +49,10 @@ def filter_all(self, filter_obj_list, filter_properties):
run_filter_once_per_request = False

def run_filter_for_index(self, index):
"""Return True if the filter needs to be run for the "index-th"
instance in a request. Only need to override this if a filter
needs anything other than "first only" or "all" behaviour.
"""Return True if the filter needs to be run for n-th instances.
Only need to override this if a filter needs anything other than
"first only" or "all" behaviour.
"""
return not (self.run_filter_once_per_request and index > 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def __init__(self, modifier_class_type, modifier_namespace):
self.extension_manager = extension.ExtensionManager(modifier_namespace)

def _is_correct_class(self, cls):
"""Return whether an object is a class of the correct type and
is not prefixed with an underscore.
"""Return whether an object is a class of the correct type.
(or is not prefixed with an underscore)
"""
return (inspect.isclass(cls) and
not cls.__name__.startswith('_') and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import six

from cinder.openstack.common.scheduler import base_handler
from cinder.scheduler import base_handler


def normalize(weight_list, minval=None, maxval=None):
Expand Down Expand Up @@ -87,9 +87,7 @@ def weight_multiplier(self):

@abc.abstractmethod
def _weigh_object(self, obj, weight_properties):
"""Override in a subclass to specify a weight for a specific
object.
"""
"""Override in a subclass to specify a weight for a specific object."""

def weigh_objects(self, weighed_obj_list, weight_properties):
"""Weigh multiple objects.
Expand Down
39 changes: 39 additions & 0 deletions cinder/scheduler/filters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) 2011 OpenStack Foundation.
# All Rights Reserved.
#
# 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.

"""
Scheduler host filters
"""

from cinder.scheduler import base_filter


class BaseHostFilter(base_filter.BaseFilter):
"""Base class for host filters."""
def _filter_one(self, obj, filter_properties):
"""Return True if the object passes the filter, otherwise False."""
return self.host_passes(obj, filter_properties)

def host_passes(self, host_state, filter_properties):
"""Return True if the HostState passes the filter, otherwise False.
Override this in a subclass.
"""
raise NotImplementedError()


class HostFilterHandler(base_filter.BaseFilterHandler):
def __init__(self, namespace):
super(HostFilterHandler, self).__init__(BaseHostFilter, namespace)
2 changes: 1 addition & 1 deletion cinder/scheduler/filters/affinity_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from oslo_log import log as logging
from oslo_utils import uuidutils

from cinder.openstack.common.scheduler import filters
from cinder.scheduler import filters
from cinder.volume import api as volume

LOG = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from cinder.openstack.common.scheduler import filters
from cinder.scheduler import filters


class AvailabilityZoneFilter(filters.BaseHostFilter):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import six

from cinder.openstack.common.scheduler import filters
from cinder.openstack.common.scheduler.filters import extra_specs_ops
from cinder.scheduler import filters
from cinder.scheduler.filters import extra_specs_ops

LOG = logging.getLogger(__name__)

Expand All @@ -27,7 +27,9 @@ class CapabilitiesFilter(filters.BaseHostFilter):
"""HostFilter to work with resource (instance & volume) type records."""

def _satisfies_extra_specs(self, capabilities, resource_type):
"""Check that the capabilities provided by the services satisfy
"""Check if capabilities satisfy resource type requirements.
Check that the capabilities provided by the services satisfy
the extra specs associated with the resource type.
"""
extra_specs = resource_type.get('extra_specs', [])
Expand Down
2 changes: 1 addition & 1 deletion cinder/scheduler/filters/capacity_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from oslo_log import log as logging

from cinder.i18n import _LE, _LW
from cinder.openstack.common.scheduler import filters
from cinder.scheduler import filters


LOG = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion cinder/scheduler/filters/driver_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import six

from cinder.i18n import _LW
from cinder.openstack.common.scheduler import filters
from cinder.scheduler.evaluator import evaluator
from cinder.scheduler import filters


LOG = logging.getLogger(__name__)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import logging

from cinder.openstack.common.scheduler import filters
from cinder.scheduler import filters

LOG = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion cinder/scheduler/filters/instance_locality_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from cinder.compute import nova
from cinder import exception
from cinder.i18n import _, _LW
from cinder.openstack.common.scheduler import filters
from cinder.scheduler import filters
from cinder.volume import utils as volume_utils


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
from oslo_serialization import jsonutils
import six

from cinder.openstack.common.scheduler import filters
from cinder.scheduler import filters


class JsonFilter(filters.BaseHostFilter):
"""Host Filter to allow simple JSON-based grammar for
selecting hosts.
"""
"""Host Filter to allow simple JSON-based grammar for selecting hosts."""
def _op_compare(self, args, op):
"""Returns True if the specified operator can successfully
"""Compare first item of args with the rest using specified operator.
Returns True if the specified operator can successfully
compare the first item in the args with all the rest. Will
return False if only one item is in the list.
"""
Expand Down Expand Up @@ -88,7 +88,9 @@ def _and(self, args):
}

def _parse_string(self, string, host_state):
"""Strings prefixed with $ are capability lookups in the
"""Parse capability lookup strings.
Strings prefixed with $ are capability lookups in the
form '$variable' where 'variable' is an attribute in the
HostState class. If $variable is a dictionary, you may
use: $variable.dictkey
Expand Down Expand Up @@ -126,9 +128,7 @@ def _process_filter(self, query, host_state):
return result

def host_passes(self, host_state, filter_properties):
"""Return a list of hosts that can fulfill the requirements
specified in the query.
"""
"""Return a list of hosts that can fulfill query requirements."""
# TODO(zhiteng) Add description for filter_properties structure
# and scheduler_hints.
try:
Expand Down
6 changes: 3 additions & 3 deletions cinder/scheduler/host_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

from cinder import context as cinder_context
from cinder import exception
from cinder.i18n import _LI, _LW
from cinder import objects
from cinder.openstack.common.scheduler import filters
from cinder.openstack.common.scheduler import weights
from cinder import utils
from cinder.i18n import _LI, _LW
from cinder.scheduler import filters
from cinder.scheduler import weights
from cinder.volume import utils as vol_utils


Expand Down
44 changes: 44 additions & 0 deletions cinder/scheduler/weights/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) 2011 OpenStack Foundation.
# All Rights Reserved.
#
# 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.

"""
Scheduler host weights
"""

from cinder.scheduler import base_weight


class WeighedHost(base_weight.WeighedObject):
def to_dict(self):
return {
'weight': self.weight,
'host': self.obj.host,
}

def __repr__(self):
return ("WeighedHost [host: %s, weight: %s]" %
(self.obj.host, self.weight))


class BaseHostWeigher(base_weight.BaseWeigher):
"""Base class for host weights."""
pass


class HostWeightHandler(base_weight.BaseWeightHandler):
object_class = WeighedHost

def __init__(self, namespace):
super(HostWeightHandler, self).__init__(BaseHostWeigher, namespace)
2 changes: 1 addition & 1 deletion cinder/scheduler/weights/capacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

from oslo_config import cfg

from cinder.openstack.common.scheduler import weights
from cinder.scheduler import weights


capacity_weight_opts = [
Expand Down
2 changes: 1 addition & 1 deletion cinder/scheduler/weights/chance.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import random

from cinder.openstack.common.scheduler import weights
from cinder.scheduler import weights


class ChanceWeigher(weights.BaseHostWeigher):
Expand Down
2 changes: 1 addition & 1 deletion cinder/scheduler/weights/goodness.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import six

from cinder.i18n import _LW
from cinder.openstack.common.scheduler import weights
from cinder.scheduler.evaluator import evaluator
from cinder.scheduler import weights


LOG = logging.getLogger(__name__)
Expand Down
Loading

0 comments on commit fab6b4e

Please sign in to comment.