openstack weight 类主要对计算节点进行称重,最终根据各项指标返回主机的权值,
一个weight类的示例,返回未使用的虚拟CPU的数量:
class MyWeigher(weights.BaseHostWeigher):
minval = 0
maxval = None
def _weigh_object(self, host_state, weight_properties):
unused_vcpus = host_state.vcpus_total - host_state.vcpus_used
return unused_vcpus
def weight_multiplier(self):
return weight_multiplier
称重的过程主要有以下5步:
The procedure of weight action for one weight class:
1、execute _weigh_object method in weight class, get a weight list which contains metrics of every compute node. Take RamWeigher for example, the return value is:
图在下面
2、normalize:
1)、get the minval and maxval value, these values can be got as the default configuration, if there is no default configuraion, can be get by this:
minval = min(weigths); maxval = max(weights);
If minval is equal to maxval set the weight list to all zero then return.
2)、execute the following expression for every element in weight list:
i = ( i - minval ) / ( maxval - minval ).
get a new weight list.
3、accumulation:
compute_node.weight += weigher.weight_multiplier( ) * weight
the weight value is obtained from the weight list, for each compute node execute the above expression.
4、sort (reverse)
5、select one compute from the N best hosts, which is specified by the parameter “scheduler_host_subset_size”