def calculate_vm_dist_capacity()

in hostfactory/host_provider/src/allocation_strategy.py [0:0]


def calculate_vm_dist_capacity(vm_types, total_slot_count):
    vm_dist = {}
    slots_per_vm_type = total_slot_count // len(vm_types) # balanced distribution

    remaining_slots = total_slot_count
    vm_dist = {vm: 0 for vm in vm_types.keys()}
    for n, (vm, weight) in enumerate(vm_types.items()):        
        vm_dist[vm] = round_down_to_nearest_multiple(slots_per_vm_type, weight)
        remaining_slots -= vm_dist[vm]
        if remaining_slots <= 0:
            break

    if remaining_slots > 0:
        for n, (vm, weight) in enumerate(vm_types.items()):
            vm_dist[vm] += weight
            remaining_slots -= weight
            if remaining_slots <= 0:
                break

    logging.info("New (capacity) VM SKU distribution targets: %s", vm_dist)
    return vm_dist