VPC: CS-15598 - update ipVO object after getting system ip as a part of elastic LB

This commit is contained in:
Alena Prokharchyk 2012-07-16 11:00:06 -07:00
parent 5a1bca8213
commit 0575b83ec0
2 changed files with 27 additions and 27 deletions

View File

@ -7197,7 +7197,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
if (network.getVpcId() != null) {
throw new InvalidParameterValueException("Specify vpcId to associate ip address to VPC", null);
throw new InvalidParameterValueException("Can't assign ip to the network directly when network belongs" +
" to VPC.Specify vpcId to associate ip address to VPC", null);
}
return associateIPToGuestNetwork(ipId, networkId);
}

View File

@ -728,44 +728,43 @@ public class LoadBalancingRulesManagerImpl<Type> implements LoadBalancingRulesMa
IPAddressVO ipVO = null;
if (ipAddrId != null) {
ipVO = _ipAddressDao.findById(ipAddrId);
// Validate ip address
if (ipVO == null) {
throw new InvalidParameterValueException("Unable to create load balance rule; source ip doesn't exist in the system", null);
} else if (ipVO.isOneToOneNat()) {
throw new NetworkRuleConflictException("Can't do load balance on ip address: " + ipVO.getAddress());
}
}
Network network = _networkMgr.getNetwork(lb.getNetworkId());
LoadBalancer result = _elbMgr.handleCreateLoadBalancerRule(lb, lbOwner, lb.getNetworkId());
boolean performedIpAssoc = false;
if (result == null) {
IpAddress systemIp = null;
Network guestNetwork = _networkMgr.getNetwork(lb.getNetworkId());
NetworkOffering off = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId());
if (off.getElasticLb() && ipVO == null) {
NetworkOffering off = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
if (off.getElasticLb() && ipVO == null && network.getVpcId() == null) {
systemIp = _networkMgr.assignSystemIp(lb.getNetworkId(), lbOwner, true, false);
lb.setSourceIpAddressId(systemIp.getId());
ipVO = _ipAddressDao.findById(systemIp.getId());
}
// Validate ip address
if (ipVO == null) {
throw new InvalidParameterValueException("Unable to create load balance rule; can't find/allocate source IP", null);
} else if (ipVO.isOneToOneNat()) {
throw new NetworkRuleConflictException("Can't do load balance on ip address: " + ipVO.getAddress());
}
try {
Network network = _networkMgr.getNetwork(lb.getNetworkId());
if (ipVO != null) {
if (ipVO.getAssociatedWithNetworkId() == null) {
boolean assignToVpcNtwk = network.getVpcId() != null
&& ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
if (assignToVpcNtwk) {
//set networkId just for verification purposes
ipVO.setAssociatedWithNetworkId(lb.getNetworkId());
_networkMgr.checkIpForService(ipVO, Service.Lb, lb.getNetworkId());
if (ipVO.getAssociatedWithNetworkId() == null) {
boolean assignToVpcNtwk = network.getVpcId() != null
&& ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
if (assignToVpcNtwk) {
//set networkId just for verification purposes
ipVO.setAssociatedWithNetworkId(lb.getNetworkId());
_networkMgr.checkIpForService(ipVO, Service.Lb, lb.getNetworkId());
s_logger.debug("The ip is not associated with the VPC network id="+ lb.getNetworkId() + " so assigning");
ipVO = _networkMgr.associateIPToGuestNetwork(ipAddrId, lb.getNetworkId());
performedIpAssoc = true;
}
} else {
_networkMgr.checkIpForService(ipVO, Service.Lb, null);
}
s_logger.debug("The ip is not associated with the VPC network id="+ lb.getNetworkId() + " so assigning");
ipVO = _networkMgr.associateIPToGuestNetwork(ipAddrId, lb.getNetworkId());
performedIpAssoc = true;
}
} else {
_networkMgr.checkIpForService(ipVO, Service.Lb, null);
}
if (ipVO.getAssociatedWithNetworkId() == null) {