summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-05-04 21:10:10 +0000
committerGerrit Code Review <review@openstack.org>2012-05-04 21:10:10 +0000
commit5effc8d2e87d5014b6e5fdb1a5068d38ae4385f3 (patch)
tree671a312d18bf07422c86330eb59f4d85dc832eff
parent9d1bc8b29b9b51d7e8048b3b66e8124f9363b593 (diff)
parent7b29e6973f56094a24f796cd05690f5c4211c970 (diff)
downloadnova-5effc8d2e87d5014b6e5fdb1a5068d38ae4385f3.tar.gz
nova-5effc8d2e87d5014b6e5fdb1a5068d38ae4385f3.tar.xz
nova-5effc8d2e87d5014b6e5fdb1a5068d38ae4385f3.zip
Merge "Clean up weighted_sum logic."
-rw-r--r--nova/scheduler/least_cost.py35
1 files changed, 8 insertions, 27 deletions
diff --git a/nova/scheduler/least_cost.py b/nova/scheduler/least_cost.py
index 70dc180e8..f10e2c4b4 100644
--- a/nova/scheduler/least_cost.py
+++ b/nova/scheduler/least_cost.py
@@ -97,30 +97,11 @@ def weighted_sum(weighted_fns, host_states, weighing_properties):
candidate.
"""
- # Make a grid of functions results.
- # One row per host. One column per function.
- scores = []
- for weight, fn in weighted_fns:
- scores.append([fn(host_state, weighing_properties)
- for host_state in host_states])
-
- # Adjust the weights in the grid by the functions weight adjustment
- # and sum them up to get a final list of weights.
- adjusted_scores = []
- for (weight, fn), row in zip(weighted_fns, scores):
- adjusted_scores.append([weight * score for score in row])
-
- # Now, sum down the columns to get the final score. Column per host.
- final_scores = [0.0] * len(host_states)
- for row in adjusted_scores:
- for idx, col in enumerate(row):
- final_scores[idx] += col
-
- # Super-impose the host_state into the scores so
- # we don't lose it when we sort.
- final_scores = [(final_scores[idx], host_state)
- for idx, host_state in enumerate(host_states)]
-
- final_scores = sorted(final_scores)
- weight, host_state = final_scores[0] # Lowest score is the winner!
- return WeightedHost(weight, host_state=host_state)
+ min_score, best_host = None, None
+ for host_state in host_states:
+ score = sum(weight * fn(host_state, weighing_properties)
+ for weight, fn in weighted_fns)
+ if min_score is None or score < min_score:
+ min_score, best_host = score, host_state
+
+ return WeightedHost(min_score, host_state=best_host)