mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
CLOUDSTACK-9779 : Releasing secondary guest IP fails with error VM nic Ip x.x.x.x is mapped to load balancing rule
This commit is contained in:
parent
f0dd5994b4
commit
feb5fa901e
@ -29,4 +29,6 @@ public interface LoadBalancerDao extends GenericDao<LoadBalancerVO, Long> {
|
||||
|
||||
List<LoadBalancerVO> listInTransitionStateByNetworkIdAndScheme(long networkId, Scheme scheme);
|
||||
|
||||
boolean isLoadBalancerRulesMappedToVmGuestIp(long instanceId, String instanceIp, long networkId);
|
||||
|
||||
}
|
||||
|
||||
@ -20,6 +20,8 @@ import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.utils.db.JoinBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.network.rules.FirewallRule.State;
|
||||
@ -36,6 +38,8 @@ public class LoadBalancerDaoImpl extends GenericDaoBase<LoadBalancerVO, Long> im
|
||||
|
||||
@Inject
|
||||
protected FirewallRulesCidrsDao _portForwardingRulesCidrsDao;
|
||||
@Inject
|
||||
LoadBalancerVMMapDao _loadBalancerVMMapDao;
|
||||
|
||||
protected LoadBalancerDaoImpl() {
|
||||
ListByIp = createSearchBuilder();
|
||||
@ -75,4 +79,40 @@ public class LoadBalancerDaoImpl extends GenericDaoBase<LoadBalancerVO, Long> im
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoadBalancerRulesMappedToVmGuestIp(long instanceId, String instanceIp, long networkId)
|
||||
{
|
||||
SearchBuilder<LoadBalancerVMMapVO> lbVmMapSearch = _loadBalancerVMMapDao.createSearchBuilder();
|
||||
lbVmMapSearch.and("instanceIp", lbVmMapSearch.entity().getInstanceIp(),SearchCriteria.Op.EQ);
|
||||
lbVmMapSearch.and("instanceId", lbVmMapSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
|
||||
|
||||
SearchBuilder<LoadBalancerVO> firewallRuleIdSearch = createSearchBuilder();
|
||||
firewallRuleIdSearch.selectFields(firewallRuleIdSearch.entity().getId());
|
||||
firewallRuleIdSearch.and("networkId",firewallRuleIdSearch.entity().getNetworkId(),Op.EQ);
|
||||
firewallRuleIdSearch.and("purpose",firewallRuleIdSearch.entity().getPurpose(),Op.EQ);
|
||||
firewallRuleIdSearch.and("state",firewallRuleIdSearch.entity().getState(),Op.NEQ);
|
||||
firewallRuleIdSearch.join("LoadBalancerRuleList", lbVmMapSearch, lbVmMapSearch.entity().getLoadBalancerId(), firewallRuleIdSearch.entity().getId(), JoinBuilder.JoinType.INNER);
|
||||
|
||||
firewallRuleIdSearch.done();
|
||||
lbVmMapSearch.done();
|
||||
|
||||
SearchCriteria<LoadBalancerVO> sc = firewallRuleIdSearch.create();
|
||||
sc.setParameters("state", State.Revoke);
|
||||
sc.setParameters("networkId", networkId);
|
||||
sc.setParameters("purpose", FirewallRule.Purpose.LoadBalancing);
|
||||
|
||||
sc.setJoinParameters("LoadBalancerRuleList", "instanceIp", instanceIp);
|
||||
sc.setJoinParameters("LoadBalancerRuleList", "instanceId", instanceId);
|
||||
|
||||
List<LoadBalancerVO> lbRuleList = customSearch(sc, null);
|
||||
|
||||
if(lbRuleList == null || lbRuleList.size() > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -197,6 +197,7 @@ import com.cloud.vm.dao.NicSecondaryIpDao;
|
||||
import com.cloud.vm.dao.NicSecondaryIpVO;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import com.cloud.network.dao.LoadBalancerDao;
|
||||
|
||||
/**
|
||||
* NetworkServiceImpl implements NetworkService.
|
||||
@ -335,6 +336,9 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
||||
@Inject
|
||||
NetworkDetailsDao _networkDetailsDao;
|
||||
|
||||
@Inject
|
||||
LoadBalancerDao _loadBalancerDao;
|
||||
|
||||
int _cidrLimit;
|
||||
boolean _allowSubdomainNetworkAccess;
|
||||
|
||||
@ -852,7 +856,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
||||
throw new InvalidParameterValueException("Can' remove the ip " + secondaryIp + "is associate with static NAT rule public IP address id " + publicIpVO.getId());
|
||||
}
|
||||
|
||||
if (_lbService.isLbRuleMappedToVmGuestIp(secondaryIp)) {
|
||||
if (_loadBalancerDao.isLoadBalancerRulesMappedToVmGuestIp(vm.getId(), secondaryIp, network.getId())) {
|
||||
s_logger.debug("VM nic IP " + secondaryIp + " is mapped to load balancing rule");
|
||||
throw new InvalidParameterValueException("Can't remove the secondary ip " + secondaryIp + " is mapped to load balancing rule");
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.network.dao.LoadBalancerVMMapDao;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
@ -93,6 +94,9 @@ public class CreateNetworkOfferingTest extends TestCase {
|
||||
@Inject
|
||||
UserIpAddressDetailsDao userIpAddressDetailsDao;
|
||||
|
||||
@Inject
|
||||
LoadBalancerVMMapDao _loadBalancerVMMapDao;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
@ -12,13 +12,13 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx.xsd
|
||||
http://www.springframework.org/schema/tx/spring-tx.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop.xsd
|
||||
http://www.springframework.org/schema/aop/spring-aop.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<context:annotation-config />
|
||||
|
||||
@ -34,23 +34,24 @@
|
||||
<ref bean="transactionContextBuilder" />
|
||||
<ref bean="actionEventInterceptor" />
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="nicIpAliasDaoImpl" class="com.cloud.vm.dao.NicIpAliasDaoImpl" />
|
||||
<bean id="ConfigurationManager" class="com.cloud.configuration.ConfigurationManagerImpl">
|
||||
<property name="name" value="ConfigurationManager"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.apache.cloudstack.networkoffering.ChildTestConfiguration" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="nicIpAliasDaoImpl" class="com.cloud.vm.dao.NicIpAliasDaoImpl" />
|
||||
<bean id="ConfigurationManager" class="com.cloud.configuration.ConfigurationManagerImpl">
|
||||
<property name="name" value="ConfigurationManager"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.apache.cloudstack.networkoffering.ChildTestConfiguration" />
|
||||
<bean id="UservmDetailsDaoImpl" class="com.cloud.vm.dao.UserVmDetailsDaoImpl" />
|
||||
<bean id="hostGpuGroupsDaoImpl" class="com.cloud.gpu.dao.HostGpuGroupsDaoImpl" />
|
||||
<bean id="vGPUTypesDaoImpl" class="com.cloud.gpu.dao.VGPUTypesDaoImpl" />
|
||||
<bean id="usageEventDaoImpl" class="com.cloud.event.dao.UsageEventDaoImpl" />
|
||||
<bean id="usageEventDetailsDaoImpl" class="com.cloud.event.dao.UsageEventDetailsDaoImpl" />
|
||||
<bean id="vGPUTypesDaoImpl" class="com.cloud.gpu.dao.VGPUTypesDaoImpl" />
|
||||
<bean id="usageEventDaoImpl" class="com.cloud.event.dao.UsageEventDaoImpl" />
|
||||
<bean id="usageEventDetailsDaoImpl" class="com.cloud.event.dao.UsageEventDetailsDaoImpl" />
|
||||
<bean id="storagePoolHostDaoImpl" class="com.cloud.storage.dao.StoragePoolHostDaoImpl" />
|
||||
<bean id="storagePoolTagsDaoImpl" class="com.cloud.storage.dao.StoragePoolTagsDaoImpl" />
|
||||
<bean id="storagePoolTagsDaoImpl" class="com.cloud.storage.dao.StoragePoolTagsDaoImpl" />
|
||||
<bean id="primaryDataStoreDaoImpl" class="org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl" />
|
||||
<bean id="userIpAddressDetailsDao" class="org.apache.cloudstack.resourcedetail.dao.UserIpAddressDetailsDaoImpl" />
|
||||
|
||||
</beans>
|
||||
<bean id="loadBalancerVMMapDaoImpl" class="com.cloud.network.dao.LoadBalancerVMMapDaoImpl" />
|
||||
|
||||
</beans>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user