-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix for Vlan doesn't match issue while adding IP range for the shared network without any IP range #10837
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
Merged
DaanHoogland
merged 2 commits into
apache:4.19
from
shapeblue:shared-network-vlan-doesnt-match-issue-while-adding-ip-range
May 16, 2025
Merged
Fix for Vlan doesn't match issue while adding IP range for the shared network without any IP range #10837
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4407,14 +4407,35 @@ public Vlan createVlanAndPublicIpRange(final CreateVlanIpRangeCmd cmd) throws In | |
| String endIP = cmd.getEndIp(); | ||
| final String newVlanGateway = cmd.getGateway(); | ||
| final String newVlanNetmask = cmd.getNetmask(); | ||
| Long networkId = cmd.getNetworkID(); | ||
| Long physicalNetworkId = cmd.getPhysicalNetworkId(); | ||
|
|
||
| // Verify that network exists | ||
| Network network = null; | ||
| if (networkId != null) { | ||
| network = _networkDao.findById(networkId); | ||
| if (network == null) { | ||
| throw new InvalidParameterValueException("Unable to find network by id " + networkId); | ||
| } else { | ||
| zoneId = network.getDataCenterId(); | ||
| physicalNetworkId = network.getPhysicalNetworkId(); | ||
| } | ||
| } | ||
|
|
||
| String vlanId = cmd.getVlan(); | ||
| if (StringUtils.isBlank(vlanId)) { | ||
| vlanId = Vlan.UNTAGGED; | ||
| if (network != null & network.getTrafficType() == TrafficType.Guest) { | ||
| boolean connectivityWithoutVlan = isConnectivityWithoutVlan(network); | ||
| vlanId = getNetworkVlanId(network, connectivityWithoutVlan); | ||
| } | ||
| } | ||
|
Contributor
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. can be an extra method
Contributor
Author
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. done |
||
|
|
||
| // TODO decide if we should be forgiving or demand a valid and complete URI | ||
| if (!(vlanId == null || "".equals(vlanId) || vlanId.startsWith(BroadcastDomainType.Vlan.scheme()))) { | ||
| vlanId = BroadcastDomainType.Vlan.toUri(vlanId).toString(); | ||
| } | ||
| final Boolean forVirtualNetwork = cmd.isForVirtualNetwork(); | ||
|
sureshanaparti marked this conversation as resolved.
|
||
| Long networkId = cmd.getNetworkID(); | ||
| Long physicalNetworkId = cmd.getPhysicalNetworkId(); | ||
| final String accountName = cmd.getAccountName(); | ||
| final Long projectId = cmd.getProjectId(); | ||
| final Long domainId = cmd.getDomainId(); | ||
|
|
@@ -4487,18 +4508,6 @@ public Vlan createVlanAndPublicIpRange(final CreateVlanIpRangeCmd cmd) throws In | |
| } | ||
| } | ||
|
|
||
| // Verify that network exists | ||
| Network network = null; | ||
| if (networkId != null) { | ||
| network = _networkDao.findById(networkId); | ||
| if (network == null) { | ||
| throw new InvalidParameterValueException("Unable to find network by id " + networkId); | ||
| } else { | ||
| zoneId = network.getDataCenterId(); | ||
| physicalNetworkId = network.getPhysicalNetworkId(); | ||
| } | ||
| } | ||
|
|
||
| // Verify that zone exists | ||
| final DataCenterVO zone = _zoneDao.findById(zoneId); | ||
| if (zone == null) { | ||
|
|
@@ -4847,28 +4856,8 @@ public Vlan createVlanAndPublicIpRange(final long zoneId, final long networkId, | |
| // same as network's vlan | ||
| // 2) if vlan is missing, default it to the guest network's vlan | ||
| if (network.getTrafficType() == TrafficType.Guest) { | ||
| String networkVlanId = null; | ||
| boolean connectivityWithoutVlan = false; | ||
| if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Connectivity)) { | ||
| Map<Capability, String> connectivityCapabilities = _networkModel.getNetworkServiceCapabilities(network.getId(), Service.Connectivity); | ||
| connectivityWithoutVlan = MapUtils.isNotEmpty(connectivityCapabilities) && connectivityCapabilities.containsKey(Capability.NoVlan); | ||
| } | ||
|
|
||
| final URI uri = network.getBroadcastUri(); | ||
| if (connectivityWithoutVlan) { | ||
| networkVlanId = network.getBroadcastDomainType().toUri(network.getUuid()).toString(); | ||
| } else if (uri != null) { | ||
| // Do not search for the VLAN tag when the network doesn't support VLAN | ||
| if (uri.toString().startsWith("vlan")) { | ||
| final String[] vlan = uri.toString().split("vlan:\\/\\/"); | ||
| networkVlanId = vlan[1]; | ||
| // For pvlan | ||
| if (network.getBroadcastDomainType() != BroadcastDomainType.Vlan) { | ||
| networkVlanId = networkVlanId.split("-")[0]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| boolean connectivityWithoutVlan = isConnectivityWithoutVlan(network); | ||
| String networkVlanId = getNetworkVlanId(network, connectivityWithoutVlan); | ||
| if (vlanId != null && !connectivityWithoutVlan) { | ||
| // if vlan is specified, throw an error if it's not equal to | ||
| // network's vlanId | ||
|
|
@@ -5000,6 +4989,36 @@ public Vlan createVlanAndPublicIpRange(final long zoneId, final long networkId, | |
| return vlan; | ||
| } | ||
|
|
||
| private boolean isConnectivityWithoutVlan(Network network) { | ||
| boolean connectivityWithoutVlan = false; | ||
| if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Connectivity)) { | ||
| Map<Capability, String> connectivityCapabilities = _networkModel.getNetworkServiceCapabilities(network.getId(), Service.Connectivity); | ||
| connectivityWithoutVlan = MapUtils.isNotEmpty(connectivityCapabilities) && connectivityCapabilities.containsKey(Capability.NoVlan); | ||
| } | ||
| return connectivityWithoutVlan; | ||
| } | ||
|
|
||
| private String getNetworkVlanId(Network network, boolean connectivityWithoutVlan) { | ||
| String networkVlanId = null; | ||
| if (connectivityWithoutVlan) { | ||
| return network.getBroadcastDomainType().toUri(network.getUuid()).toString(); | ||
| } | ||
|
|
||
| final URI uri = network.getBroadcastUri(); | ||
| if (uri != null) { | ||
| // Do not search for the VLAN tag when the network doesn't support VLAN | ||
| if (uri.toString().startsWith("vlan")) { | ||
| final String[] vlan = uri.toString().split("vlan:\\/\\/"); | ||
| networkVlanId = vlan[1]; | ||
| // For pvlan | ||
| if (network.getBroadcastDomainType() != BroadcastDomainType.Vlan) { | ||
| networkVlanId = networkVlanId.split("-")[0]; | ||
| } | ||
| } | ||
| } | ||
| return networkVlanId; | ||
| } | ||
|
|
||
| private void checkZoneVlanIpOverlap(DataCenterVO zone, Network network, String newCidr, String vlanId, String vlanGateway, String vlanNetmask, String startIP, String endIP) { | ||
| // Throw an exception if this subnet overlaps with subnet on other VLAN, | ||
| // if this is ip range extension, gateway, network mask should be same and ip range should not overlap | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be a seperate method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done