-
Couldn't load subscription status.
- Fork 1.2k
Enforce distinct hostnames network #10212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,12 @@ public interface UserVmManager extends UserVmService { | |
| "If set to true, tags specified in `resource.limit.host.tags` are also included in vm.strict.host.tags.", | ||
| true); | ||
|
|
||
| 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"); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please help me understand what's the purpose of this global setting, if VM names have to be unique within a network domain? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, the network domain can be same for networks in different domain, account, etc. If a user a launches a VM with the same name in these networks, there can be conflict. This global setting allows the user to set scope for what all networks we need to check when creating a vm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vishesh92 can you please add "project" and "vpc" to the scope There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For project, we specify account_id as the project id. So, this is covered by the account scope. Adding project will make the check complicated. |
||
| static final int MAX_USER_DATA_LENGTH_BYTES = 2048; | ||
|
|
||
| public static final String CKS_NODE = "cksnode"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4691,23 +4691,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()); | ||
vishesh92 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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())); | ||
vishesh92 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| 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()); | ||
vishesh92 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
vishesh92 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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()); | ||
vishesh92 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| List<Long> accountIds = networkList.stream().map(Network::getAccountId).collect(Collectors.toList()); | ||
vishesh92 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| finalNetworkList = _networkDao.listByNetworkDomainsAndAccountIds(uniqueNtwkDomains, accountIds); | ||
| break; | ||
| default: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| Set<Long> vpcIds = networkList.stream().map(Network::getVpcId).filter(Objects::nonNull).collect(Collectors.toSet()); | ||
| finalNetworkList = new ArrayList<>(networkList); | ||
| for (Long vpcId : vpcIds) { | ||
| finalNetworkList.addAll(_networkDao.listByVpc(vpcId)); | ||
| } | ||
| break; | ||
| } | ||
| return finalNetworkList; | ||
| } | ||
|
|
||
| private Map<String, Set<Long>> getNetworkIdPerNetworkDomain(List<NetworkVO> networkList) { | ||
| Map<String, Set<Long>> ntwkDomains = new HashMap<>(); | ||
|
|
||
| List<NetworkVO> updatedNetworkList = getNetworksForCheckUniqueHostName(networkList); | ||
| for (Network network : updatedNetworkList) { | ||
| String ntwkDomain = network.getNetworkDomain(); | ||
| Set<Long> ntwkIds; | ||
| if (!ntwkDomains.containsKey(ntwkDomain)) { | ||
| List<Long> ntwkIds = new ArrayList<Long>(); | ||
| ntwkIds.add(network.getId()); | ||
| ntwkDomains.put(ntwkDomain, ntwkIds); | ||
| ntwkIds = new HashSet<>(); | ||
| } else { | ||
| List<Long> ntwkIds = ntwkDomains.get(ntwkDomain); | ||
| ntwkIds.add(network.getId()); | ||
| ntwkDomains.put(ntwkDomain, ntwkIds); | ||
| ntwkIds = ntwkDomains.get(ntwkDomain); | ||
| } | ||
| ntwkIds.add(network.getId()); | ||
| ntwkDomains.put(ntwkDomain, ntwkIds); | ||
| } | ||
| return ntwkDomains; | ||
| } | ||
|
|
||
| for (Entry<String, List<Long>> ntwkDomain : ntwkDomains.entrySet()) { | ||
| private void checkIfHostNameUniqueInNtwkDomain(String hostName, List<NetworkVO> networkList) { | ||
| // Check that hostName is unique | ||
vishesh92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Map<String, Set<Long>> ntwkDomains = getNetworkIdPerNetworkDomain(networkList); | ||
| for (Entry<String, Set<Long>> ntwkDomain : ntwkDomains.entrySet()) { | ||
| for (Long ntwkId : ntwkDomain.getValue()) { | ||
| // * get all vms hostNames in the network | ||
| List<String> hostNames = _vmInstanceDao.listDistinctHostNames(ntwkId); | ||
|
|
@@ -9244,7 +9296,7 @@ public ConfigKey<?>[] getConfigKeys() { | |
| return new ConfigKey<?>[] {EnableDynamicallyScaleVm, AllowDiskOfferingChangeDuringScaleVm, AllowUserExpungeRecoverVm, VmIpFetchWaitInterval, VmIpFetchTrialMax, | ||
| VmIpFetchThreadPoolMax, VmIpFetchTaskWorkers, AllowDeployVmIfGivenHostFails, EnableAdditionalVmConfig, DisplayVMOVFProperties, | ||
| KvmAdditionalConfigAllowList, XenServerAdditionalConfigAllowList, VmwareAdditionalConfigAllowList, DestroyRootVolumeOnVmDestruction, | ||
| EnforceStrictResourceLimitHostTagCheck, StrictHostTags, AllowUserForceStopVm}; | ||
| EnforceStrictResourceLimitHostTagCheck, StrictHostTags, AllowUserForceStopVm, VmDistinctHostNameScope}; | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.