CLOUDSTACK-1219, CLOUDSTACK-1220: Fix IPv6 error messages

This commit is contained in:
Sheng Yang 2013-02-14 16:19:17 -08:00
parent cf7ac9d6c4
commit ca5c6d5d14
6 changed files with 50 additions and 17 deletions

View File

@ -255,4 +255,6 @@ public interface NetworkModel {
boolean isIP6AddressAvailableInVlan(long vlanId); boolean isIP6AddressAvailableInVlan(long vlanId);
void checkIp6Parameters(String startIPv6, String endIPv6, String ip6Gateway, String ip6Cidr) throws InvalidParameterValueException; void checkIp6Parameters(String startIPv6, String endIPv6, String ip6Gateway, String ip6Cidr) throws InvalidParameterValueException;
void checkRequestedIpAddresses(long networkId, String ip4, String ip6) throws InvalidParameterValueException;
} }

View File

@ -80,7 +80,7 @@ public class Ipv6AddressManagerImpl extends ManagerBase implements Ipv6AddressMa
} }
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId); List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
if (vlans == null) { if (vlans == null) {
s_logger.debug("Cannot find related vlan or too many vlan attached to network " + networkId); s_logger.debug("Cannot find related vlan attached to network " + networkId);
return null; return null;
} }
String ip = null; String ip = null;
@ -109,7 +109,7 @@ public class Ipv6AddressManagerImpl extends ManagerBase implements Ipv6AddressMa
} }
} }
if (ip == null) { if (ip == null) {
throw new InsufficientAddressCapacityException("Cannot find a usable IP in the network " + network.getName() + " after network.ipv6.search.retry.max = " + _ipv6RetryMax + " times retry!", throw new InsufficientAddressCapacityException("Cannot find a usable IP in the network " + network.getName() + " after " + _ipv6RetryMax + "(network.ipv6.search.retry.max) times retry!",
DataCenter.class, network.getDataCenterId()); DataCenter.class, network.getDataCenterId());
} }
} else { } else {

View File

@ -1923,4 +1923,36 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
throw new InvalidParameterValueException("The cidr size of IPv6 network must be no less than 64 bits!"); throw new InvalidParameterValueException("The cidr size of IPv6 network must be no less than 64 bits!");
} }
} }
@Override
public void checkRequestedIpAddresses(long networkId, String ip4, String ip6) throws InvalidParameterValueException {
if (ip4 != null) {
if (!NetUtils.isValidIp(ip4)) {
throw new InvalidParameterValueException("Invalid specified IPv4 address " + ip4);
}
//Other checks for ipv4 are done in assignPublicIpAddress()
}
if (ip6 != null) {
if (!NetUtils.isValidIpv6(ip6)) {
throw new InvalidParameterValueException("Invalid specified IPv6 address " + ip6);
}
if (_ipv6Dao.findByNetworkIdAndIp(networkId, ip6) != null) {
throw new InvalidParameterValueException("The requested IP is already taken!");
}
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
if (vlans == null) {
throw new CloudRuntimeException("Cannot find related vlan attached to network " + networkId);
}
Vlan ipVlan = null;
for (Vlan vlan : vlans) {
if (NetUtils.isIp6InRange(ip6, vlan.getIp6Range())) {
ipVlan = vlan;
break;
}
}
if (ipVlan == null) {
throw new InvalidParameterValueException("Requested IPv6 is not in the predefined range!");
}
}
}
} }

View File

@ -3299,7 +3299,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
if (requestedIpPair == null) { if (requestedIpPair == null) {
requestedIpPair = new IpAddresses(null, null); requestedIpPair = new IpAddresses(null, null);
} else { } else {
checkRequestedIpAddresses(requestedIpPair.getIp4Address(), requestedIpPair.getIp6Address()); _networkModel.checkRequestedIpAddresses(network.getId(), requestedIpPair.getIp4Address(), requestedIpPair.getIp6Address());
} }
NicProfile profile = new NicProfile(requestedIpPair.getIp4Address(), requestedIpPair.getIp6Address()); NicProfile profile = new NicProfile(requestedIpPair.getIp4Address(), requestedIpPair.getIp6Address());
@ -3308,7 +3308,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
defaultNetworkNumber++; defaultNetworkNumber++;
// if user requested specific ip for default network, add it // if user requested specific ip for default network, add it
if (defaultIps.getIp4Address() != null || defaultIps.getIp6Address() != null) { if (defaultIps.getIp4Address() != null || defaultIps.getIp6Address() != null) {
checkRequestedIpAddresses(defaultIps.getIp4Address(), defaultIps.getIp6Address()); _networkModel.checkRequestedIpAddresses(network.getId(), defaultIps.getIp4Address(), defaultIps.getIp6Address());
profile = new NicProfile(defaultIps.getIp4Address(), defaultIps.getIp6Address()); profile = new NicProfile(defaultIps.getIp4Address(), defaultIps.getIp6Address());
} }
@ -3486,19 +3486,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
return vm; return vm;
} }
private void checkRequestedIpAddresses(String ip4, String ip6) throws InvalidParameterValueException {
if (ip4 != null) {
if (!NetUtils.isValidIp(ip4)) {
throw new InvalidParameterValueException("Invalid specified IPv4 address " + ip4);
}
}
if (ip6 != null) {
if (!NetUtils.isValidIpv6(ip6)) {
throw new InvalidParameterValueException("Invalid specified IPv6 address " + ip6);
}
}
}
private void validateUserData(String userData) { private void validateUserData(String userData) {
byte[] decodedUserData = null; byte[] decodedUserData = null;
if (userData != null) { if (userData != null) {

View File

@ -829,4 +829,10 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override
public void checkRequestedIpAddresses(long networkId, String ip4, String ip6)
throws InvalidParameterValueException {
// TODO Auto-generated method stub
}
} }

View File

@ -842,4 +842,10 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override
public void checkRequestedIpAddresses(long networkId, String ip4, String ip6)
throws InvalidParameterValueException {
// TODO Auto-generated method stub
}
} }