harikrishna-patnala commented on code in PR #10212: URL: https://github.com/apache/cloudstack/pull/10212#discussion_r2299848009
########## server/src/main/java/com/cloud/vm/UserVmManager.java: ########## @@ -59,6 +59,12 @@ public interface UserVmManager extends UserVmService { "Destroys the VM's root volume when the VM is destroyed.", true, ConfigKey.Scope.Domain); + ConfigKey<String> VmDistinctHostNameScope = new ConfigKey<>(String.class, "vm.distinct.hostname.scope", ConfigKey.CATEGORY_ADVANCED, + "network", + "Scope of resources to check while checking if the hostname is unique. Possible values are global, domain, subdomain, account, network.", + true, ConfigKey.Scope.Global, null, "VM distinct hostname scope", null, null, null, ConfigKey.Kind.Select, + "global,domain,subdomain,account,network"); + Review Comment: @vishesh92 can you please add "project" and "vpc" to the scope ########## 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: presuming the default section is for scope network, how this will behave for isolated or L2 networks ? I see you are checking only for VPCs -- 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