Skip to content

Commit a3d4ee3

Browse files
author
Alena Prokharchyk
committed
VPC: CS-15598 - update ipVO object after getting system ip as a part of elastic LB
Conflicts: server/src/com/cloud/network/NetworkManagerImpl.java server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
1 parent 4a7149e commit a3d4ee3

2 files changed

Lines changed: 28 additions & 29 deletions

File tree

‎server/src/com/cloud/network/NetworkManagerImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7230,7 +7230,8 @@ public IpAddress associateIP(long ipId, Long networkId, Long vpcId) throws Insuf
72307230
}
72317231

72327232
if (network.getVpcId() != null) {
7233-
throw new InvalidParameterValueException("Specify vpcId to associate ip address to VPC");
7233+
throw new InvalidParameterValueException("Can't assign ip to the network directly when network belongs" +
7234+
" to VPC.Specify vpcId to associate ip address to VPC");
72347235
}
72357236
return associateIPToGuestNetwork(ipId, networkId);
72367237
}

‎server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java‎

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -718,48 +718,46 @@ public LoadBalancer createLoadBalancerRule(CreateLoadBalancerRuleCmd lb, boolean
718718
IPAddressVO ipVO = null;
719719
if (ipAddrId != null) {
720720
ipVO = _ipAddressDao.findById(ipAddrId);
721-
722-
// Validate ip address
723-
if (ipVO == null) {
724-
throw new InvalidParameterValueException("Unable to create load balance rule; ip id=" + ipAddrId + "" +
725-
" doesn't exist in the system");
726-
} else if (ipVO.isOneToOneNat()) {
727-
throw new NetworkRuleConflictException("Can't do load balance on ip address: " + ipVO.getAddress());
728-
}
729721
}
722+
723+
Network network = _networkMgr.getNetwork(lb.getNetworkId());
730724

731725
// FIXME: breaking the dependency on ELB manager. This breaks functionality of ELB using virtual router
732726
// Bug CS-15411 opened to document this
733727
//LoadBalancer result = _elbMgr.handleCreateLoadBalancerRule(lb, lbOwner, lb.getNetworkId());
734728
LoadBalancer result = null;
735729
if (result == null) {
736730
IpAddress systemIp = null;
737-
Network guestNetwork = _networkMgr.getNetwork(lb.getNetworkId());
738-
NetworkOffering off = _configMgr.getNetworkOffering(guestNetwork.getNetworkOfferingId());
739-
if (off.getElasticLb() && ipVO == null) {
731+
NetworkOffering off = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
732+
if (off.getElasticLb() && ipVO == null && network.getVpcId() == null) {
740733
systemIp = _networkMgr.assignSystemIp(lb.getNetworkId(), lbOwner, true, false);
741734
lb.setSourceIpAddressId(systemIp.getId());
735+
ipVO = _ipAddressDao.findById(systemIp.getId());
736+
}
737+
738+
// Validate ip address
739+
if (ipVO == null) {
740+
throw new InvalidParameterValueException("Unable to create load balance rule; can't find/allocate source IP");
741+
} else if (ipVO.isOneToOneNat()) {
742+
throw new NetworkRuleConflictException("Can't do load balance on ip address: " + ipVO.getAddress());
742743
}
743744

744745
boolean performedIpAssoc = false;
745746
try {
746-
Network network = _networkMgr.getNetwork(lb.getNetworkId());
747-
if (ipVO != null) {
748-
if (ipVO.getAssociatedWithNetworkId() == null) {
749-
boolean assignToVpcNtwk = network.getVpcId() != null
750-
&& ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
751-
if (assignToVpcNtwk) {
752-
//set networkId just for verification purposes
753-
ipVO.setAssociatedWithNetworkId(lb.getNetworkId());
754-
_networkMgr.checkIpForService(ipVO, Service.Lb, lb.getNetworkId());
755-
756-
s_logger.debug("The ip is not associated with the VPC network id="+ lb.getNetworkId() + " so assigning");
757-
ipVO = _networkMgr.associateIPToGuestNetwork(ipAddrId, lb.getNetworkId());
758-
performedIpAssoc = true;
759-
}
760-
} else {
761-
_networkMgr.checkIpForService(ipVO, Service.Lb, null);
762-
}
747+
if (ipVO.getAssociatedWithNetworkId() == null) {
748+
boolean assignToVpcNtwk = network.getVpcId() != null
749+
&& ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
750+
if (assignToVpcNtwk) {
751+
//set networkId just for verification purposes
752+
ipVO.setAssociatedWithNetworkId(lb.getNetworkId());
753+
_networkMgr.checkIpForService(ipVO, Service.Lb, lb.getNetworkId());
754+
755+
s_logger.debug("The ip is not associated with the VPC network id="+ lb.getNetworkId() + " so assigning");
756+
ipVO = _networkMgr.associateIPToGuestNetwork(ipAddrId, lb.getNetworkId());
757+
performedIpAssoc = true;
758+
}
759+
} else {
760+
_networkMgr.checkIpForService(ipVO, Service.Lb, null);
763761
}
764762

765763
if (ipVO.getAssociatedWithNetworkId() == null) {

0 commit comments

Comments
 (0)