1
# Copyright (c) 2012 OpenStack, LLC.
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
8
# http://www.apache.org/licenses/LICENSE-2.0
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
16
Capacity Weigher. Weigh hosts by their available capacity.
18
The default is to spread volumes across all hosts evenly. If you prefer
19
stacking, you can set the 'capacity_weight_multiplier' option to a negative
20
number and the weighing has the opposite effect of the default.
25
from cinder import flags
26
from cinder.openstack.common import cfg
27
from cinder.openstack.common.scheduler import weights
30
capacity_weight_opts = [
31
cfg.FloatOpt('capacity_weight_multiplier',
33
help='Multiplier used for weighing volume capacity. '
34
'Negative numbers mean to stack vs spread.'),
38
FLAGS.register_opts(capacity_weight_opts)
41
class CapacityWeigher(weights.BaseHostWeigher):
42
def _weight_multiplier(self):
43
"""Override the weight multiplier."""
44
return FLAGS.capacity_weight_multiplier
46
def _weigh_object(self, host_state, weight_properties):
47
"""Higher weights win. We want spreading to be the default."""
48
reserved = float(host_state.reserved_percentage) / 100
49
free = math.floor(host_state.free_capacity_gb * (1 - reserved))