is ' 'the corresponding ratio. So for "name1=1.0, '
'name2=-1.0" The final weight would be '
'name1.value * 1.0 + name2.value * -1.0.'),
cfg.BoolOpt('required',
default=True,
help='How to treat the unavailable metrics. When a '
'metric is NOT available for a host, if it is set '
'to be True, it would raise an exception, so it '
'is recommended to use the scheduler filter '
'MetricFilter to filter out those hosts. If it is '
'set to be False, the unavailable metric would be '
'treated as a negative factor in weighing '
'process, the returned value would be set by '
'the option weight_of_unavailable.'),
cfg.FloatOpt('weight_of_unavailable',
default=float(-10000.0),
help='The final weight value to be returned if '
'required is set to False and any one of the '
'metrics set by weight_setting is unavailable.'),
]
CONF = cfg.CONF
CONF.register_opts(metrics_weight_opts, group='metrics')
**** CubicPower OpenStack Study ****
class MetricsWeigher(weights.BaseHostWeigher):
**** CubicPower OpenStack Study ****
def __init__(self):
self._parse_setting()
**** CubicPower OpenStack Study ****
def _parse_setting(self):
self.setting = utils.parse_options(CONF.metrics.weight_setting,
sep='=',
converter=float,
name="metrics.weight_setting")
**** CubicPower OpenStack Study ****
def weight_multiplier(self):
"""Override the weight multiplier."""
return CONF.metrics.weight_multiplier
**** CubicPower OpenStack Study ****
def _weigh_object(self, host_state, weight_properties):
value = 0.0
for (name, ratio) in self.setting:
try:
value += host_state.metrics[name].value * ratio
except KeyError:
if CONF.metrics.required:
raise exception.ComputeHostMetricNotFound(
host=host_state.host,
node=host_state.nodename,
name=name)
else:
# We treat the unavailable metric as the most negative
# factor, i.e. set the value to make this obj would be
# at the end of the ordered weighed obj list
# Do nothing if ratio or weight_multiplier is 0.
if ratio * self.weight_multiplier() != 0:
return CONF.metrics.weight_of_unavailable
return value