From d0469bdc510443a2e7cd5a0dce5eab206a247527 Mon Sep 17 00:00:00 2001 From: Zhiteng Huang Date: Sun, 17 Feb 2013 16:32:04 +0800 Subject: [PATCH] Handle 'infinite' and 'unknown' capacity in CapacityWeigher This patch updates CapacityWeigher to transform 'infinite' and 'unknown' capacity reported by back-ends to float('inf'). They are considered the same for sorting purpose. Change-Id: Ic8f811227c9937c4e09eb8b77457ed7e9231be4e --- cinder/scheduler/weights/capacity.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cinder/scheduler/weights/capacity.py b/cinder/scheduler/weights/capacity.py index 2bb5a0b25..8d37997d4 100644 --- a/cinder/scheduler/weights/capacity.py +++ b/cinder/scheduler/weights/capacity.py @@ -46,5 +46,11 @@ class CapacityWeigher(weights.BaseHostWeigher): def _weigh_object(self, host_state, weight_properties): """Higher weights win. We want spreading to be the default.""" reserved = float(host_state.reserved_percentage) / 100 - free = math.floor(host_state.free_capacity_gb * (1 - reserved)) + free_space = host_state.free_capacity_gb + if free_space == 'infinite' or free_space == 'unknown': + #(zhiteng) 'infinite' and 'unknown' are treated the same + # here, for sorting purpose. + free = float('inf') + else: + free = math.floor(host_state.free_capacity_gb * (1 - reserved)) return free -- 2.45.2