Weigh nodes by their ports quantity

The default is to preferably choose nodes with less ports.
If you prefer choosing more ports nodes, you can set the
'port_weight_multiplier' option to a positive number and
the weighing has the opposite effect of the default.

Change-Id: Ic936301a83658ebba5fb9a689505acb5a090aa71
This commit is contained in:
Zhenguo Niu 2017-02-03 13:03:09 +08:00
parent 28124994b8
commit 9e7797e78f
3 changed files with 49 additions and 1 deletions

View File

@ -41,7 +41,9 @@ opts = [
help=_('Which filter class names to use for filtering nodes '
'when not specified in the request.')),
cfg.ListOpt('scheduler_default_weighers',
default=[],
default=[
'PortWeigher',
],
help=_('Which weigher class names to use for weighing '
'nodes.')),
cfg.StrOpt('scheduler_weight_handler',
@ -49,6 +51,9 @@ opts = [
'OrderedNodeWeightHandler',
help=_('Which handler to use for selecting the node after '
'weighing')),
cfg.FloatOpt('port_weight_multiplier',
default=-1.0,
help=_('Node ports quantity weight multipler ratio.')),
]

View File

@ -0,0 +1,41 @@
# Copyright 2017 Huawei Technologies Co.,LTD.
# 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.
"""
Port Weigher. Weigh nodes by their ports quantity.
The default is to preferably choose nodes with less ports. If you prefer
choosing more ports nodes, you can set the 'port_weight_multiplier' option
to a positive number and the weighing has the opposite effect of the default.
"""
from oslo_config import cfg
from mogan.engine.scheduler import weights
CONF = cfg.CONF
class PortWeigher(weights.BaseNodeWeigher):
minval = 0
def weight_multiplier(self):
"""Override the weight multiplier."""
return CONF.scheduler.port_weight_multiplier
def _weigh_object(self, node_state, weight_properties):
"""Higher weights win. We want to choose less ports node to be the
default.
"""
return len(node_state.ports)

View File

@ -31,6 +31,8 @@ mogan.engine.scheduler.filters =
CapabilitiesFilter = mogan.engine.scheduler.filters.capabilities_filter:CapabilitiesFilter
PortsFilter = mogan.engine.scheduler.filters.ports_filter:PortsFilter
JsonFilter = mogan.engine.scheduler.filters.json_filter:JsonFilter
mogan.engine.scheduler.weights =
PortWeigher = mogan.engine.scheduler.weights.port:PortWeigher
oslo.config.opts =
mogan = mogan.conf.opts:list_opts