vishesh92 commented on code in PR #10212: URL: https://github.com/apache/cloudstack/pull/10212#discussion_r2300261509
########## server/src/main/java/com/cloud/vm/UserVmManagerImpl.java: ########## @@ -4429,23 +4429,75 @@ protected void verifyIfHypervisorSupportsRootdiskSizeOverride(HypervisorType hyp } } - private void checkIfHostNameUniqueInNtwkDomain(String hostName, List<? extends Network> networkList) { - // Check that hostName is unique in the network domain - Map<String, List<Long>> ntwkDomains = new HashMap<String, List<Long>>(); + private List<NetworkVO> getNetworksWithSameNetworkDomainInDomains(List<NetworkVO> networkList, boolean checkSubDomains) { + List<String> uniqueNtwkDomains = networkList.stream().map(NetworkVO::getNetworkDomain).collect(Collectors.toList()); + List<Long> domainIdList = new ArrayList<>(); for (Network network : networkList) { + domainIdList.add(network.getDomainId()); + } + Set<Long> finalDomainIdList = new HashSet<>(domainIdList); + if (checkSubDomains) { + for (Long domainId : domainIdList) { + DomainVO domain = _domainDao.findById(domainId); + List<Long> childDomainIds = _domainDao.getDomainChildrenIds(domain.getPath()); + finalDomainIdList.addAll(childDomainIds); + } + } + return _networkDao.listByNetworkDomainsAndDomainIds(uniqueNtwkDomains, finalDomainIdList.stream().collect(Collectors.toList())); + } + + private List<NetworkVO> getNetworksForCheckUniqueHostName(List<NetworkVO> networkList) { + List<NetworkVO> finalNetworkList; + List<String> uniqueNtwkDomains; + switch (VmDistinctHostNameScope.value()) { + case "global": + uniqueNtwkDomains = networkList.stream().map(NetworkVO::getNetworkDomain).collect(Collectors.toList()); + finalNetworkList = _networkDao.listByNetworkDomains(uniqueNtwkDomains); + break; + case "domain": + finalNetworkList = getNetworksWithSameNetworkDomainInDomains(networkList, false); + break; + case "subdomain": + finalNetworkList = getNetworksWithSameNetworkDomainInDomains(networkList, true); + break; + case "account": + uniqueNtwkDomains = networkList.stream().map(NetworkVO::getNetworkDomain).collect(Collectors.toList()); + List<Long> accountIds = networkList.stream().map(Network::getAccountId).collect(Collectors.toList()); + finalNetworkList = _networkDao.listByNetworkDomainsAndAccountIds(uniqueNtwkDomains, accountIds); + break; + default: Review Comment: finalNetworkList = new ArrayList<>(networkList); We set the final networklist to network list. And we fetch all networks for the VPCs to the final network list. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org