def _allocation_strategy()

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


    def _allocation_strategy(self, template_id, slot_count, vm_sizes, vm_dist):
        allocation_results = []
        check_allocate = None
        self.logger.warning(f"Allocating {slot_count} slots for template_id {template_id} using distribution {vm_dist}")
        for n,vmsize in enumerate(vm_sizes):
            vm_slot_count = vm_dist[vmsize]
            self.logger.debug(f"Allocating {vm_slot_count} slots of {vmsize}")
            if vm_slot_count > 0:
                check_allocate = self.node_mgr.allocate({"node.vm_size": vmsize, "weight": 1, 
                                                         "template_id": template_id, 
                                                         "capacity-failure-backoff": self.capacity_limit_timeout},
                                                        slot_count=vm_slot_count, allow_existing=False)
                if not check_allocate.nodes:
                    self.logger.debug("0 new nodes allocated for %s", vmsize)
                    break
                else:
                    allocation_results.extend(check_allocate.nodes)
        allocated_count = sum([x.resources["weight"] for x in self.node_mgr.get_new_nodes()])
        remaining_count = slot_count - allocated_count
        self.logger.debug("Allocated %s remaining %s", allocated_count, remaining_count)
        # Allocate remaining slots with any available vm size
        if remaining_count > 0:
            self.logger.warning("Allocating remaining: %s slots", remaining_count)
            check_allocate = self.node_mgr.allocate({"weight": 1, 
                                                     "template_id": template_id, 
                                                     "capacity-failure-backoff": self.capacity_limit_timeout},
                                                    slot_count=remaining_count, allow_existing=False) 
            if check_allocate.nodes:
                allocation_results.extend(check_allocate.nodes)
        return allocation_results