in hostfactory/host_provider/src/allocation_strategy.py [0:0]
def calculate_vm_dist_weighted(vm_types, requested_slot_count, percentage_weights=[.7, .2, .05, .05]):
'''Apply a simple static percentage distribution to the vm_types'''
percentage_weights = normalize_list(percentage_weights) # Ensure that percentage weights sum to 1
vm_dist = {vm: 0 for vm in vm_types.keys()}
slots_per_vm_type = [floor(requested_slot_count * p) for p in percentage_weights]
if len(slots_per_vm_type) < len(vm_types):
for i in range(len(vm_types) - len(slots_per_vm_type)):
slots_per_vm_type.append(0)
remaining_slots = requested_slot_count
n = 0
for n, p in enumerate(vm_types.items()):
vm, weight = p
if slots_per_vm_type[n] < 1:
continue
if weight <= 0:
continue
slot_count = max(weight, round_down_to_nearest_multiple(slots_per_vm_type[n], weight))
remaining_slots -= slot_count
vm_dist[vm] = slot_count
if remaining_slots <= 0:
break
# Fill in any remaining slots
while remaining_slots > 0:
for n, p in enumerate(vm_types.items()):
vm, weight = p
remaining_slots -= weight
vm_dist[vm] += weight
if remaining_slots <= 0:
break
logging.info("New (weighted) VM SKU distribution targets: %s", vm_dist)
return vm_dist