Allow different VLANs have ovveride subnet for shared network

This commit is contained in:
Anthony Xu 2014-02-03 15:02:36 -08:00
parent 66989a9364
commit 657d9e4789
1 changed files with 39 additions and 24 deletions

View File

@ -2864,40 +2864,55 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
String otherVlanGateway = vlan.getVlanGateway();
String otherVlanNetmask = vlan.getVlanNetmask();
// Continue if it's not IPv4
if (otherVlanGateway == null || otherVlanNetmask == null) {
if ( otherVlanGateway == null || otherVlanNetmask == null ) {
continue;
}
if (vlan.getNetworkId() == null) {
if ( vlan.getNetworkId() == null ) {
continue;
}
String otherCidr = NetUtils.getCidrFromGatewayAndNetmask(otherVlanGateway, otherVlanNetmask);
if (!NetUtils.isNetworksOverlap(newCidr, otherCidr)) {
if( !NetUtils.isNetworksOverlap(newCidr, otherCidr)) {
continue;
}
// from here, subnet overlaps
if (!NetUtils.isSameIsolationId(vlanId, vlan.getVlanTag())) {
throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " in zone " + zone.getName()
+ " has overlapped with the subnet. Please specify a different gateway/netmask.");
}
if (vlan.getNetworkId() != networkId) {
throw new InvalidParameterValueException("This subnet is overlapped with subnet in other network " + vlan.getNetworkId() + " in zone " + zone.getName()
+ " . Please specify a different gateway/netmask.");
if ( !vlanId.equals(vlan.getVlanTag()) ) {
boolean overlapped = false;
if( network.getTrafficType() == TrafficType.Public ) {
overlapped = true;
} else {
Long nwId = vlan.getNetworkId();
if ( nwId != null ) {
Network nw = _networkModel.getNetwork(nwId);
if ( nw != null && nw.getTrafficType() == TrafficType.Public ) {
overlapped = true;
}
}
}
String[] otherVlanIpRange = vlan.getIpRange().split("\\-");
String otherVlanStartIP = otherVlanIpRange[0];
String otherVlanEndIP = null;
if (otherVlanIpRange.length > 1) {
otherVlanEndIP = otherVlanIpRange[1];
}
}
if ( overlapped ) {
throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag()
+ " in zone " + zone.getName()
+ " has overlapped with the subnet. Please specify a different gateway/netmask.");
}
} else {
//extend IP range
if (!vlanGateway.equals(otherVlanGateway) || !vlanNetmask.equals(vlan.getVlanNetmask())) {
throw new InvalidParameterValueException("The IP range has already been added with gateway " + otherVlanGateway + " ,and netmask " + otherVlanNetmask
+ ", Please specify the gateway/netmask if you want to extend ip range");
}
if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) {
throw new InvalidParameterValueException("The IP range already has IPs that overlap with the new range." + " Please specify a different start IP/end IP.");
String[] otherVlanIpRange = vlan.getIpRange().split("\\-");
String otherVlanStartIP = otherVlanIpRange[0];
String otherVlanEndIP = null;
if (otherVlanIpRange.length > 1) {
otherVlanEndIP = otherVlanIpRange[1];
}
// extend IP range
if (!vlanGateway.equals(otherVlanGateway) || !vlanNetmask.equals(vlan.getVlanNetmask())) {
throw new InvalidParameterValueException("The IP range has already been added with gateway "
+ otherVlanGateway + " ,and netmask " + otherVlanNetmask
+ ", Please specify the gateway/netmask if you want to extend ip range" );
}
if (NetUtils.ipRangesOverlap(startIP, endIP, otherVlanStartIP, otherVlanEndIP)) {
throw new InvalidParameterValueException("The IP range already has IPs that overlap with the new range." +
" Please specify a different start IP/end IP.");
}
}
}
}