List only those hosts matching source host arch in multi-arch zones (#10369)

* List only those hosts matching source host arch in multi-arch zones

* remove duplicate import due to merge conflict

* filter only if suitable hosts aren't empty

* get cpu archs only if there are suitable hosts
This commit is contained in:
Pearl Dsilva 2025-02-19 08:43:41 -05:00 committed by GitHub
parent ee32f4cfe8
commit 4b432c82ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,6 +44,7 @@ import javax.crypto.spec.SecretKeySpec;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.cpu.CPU;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
@ -1612,6 +1613,14 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
logger.debug("Hosts having capacity and suitable for migration: {}", suitableHosts);
}
// Only list hosts of the same architecture as the source Host in a multi-arch zone
if (!suitableHosts.isEmpty()) {
List<CPU.CPUArch> clusterArchs = ApiDBUtils.listZoneClustersArchs(vm.getDataCenterId());
if (CollectionUtils.isNotEmpty(clusterArchs) && clusterArchs.size() > 1) {
suitableHosts = suitableHosts.stream().filter(h -> h.getArch() == srcHost.getArch()).collect(Collectors.toList());
}
}
return new Ternary<>(otherHosts, suitableHosts, requiresStorageMotion);
}