Fix VPC restart with cleanup (#12)

This commit is contained in:
Nicolas Vazquez 2024-02-02 11:58:48 -03:00 committed by GitHub
parent 54c8672eb0
commit 44fa33c18d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 4 deletions

View File

@ -44,6 +44,8 @@ public interface NicDao extends GenericDao<NicVO, Long> {
NicVO findByNetworkIdAndType(long networkId, VirtualMachine.Type vmType);
NicVO findByNetworkIdAndTypeIncludingRemoved(long networkId, VirtualMachine.Type vmType);
NicVO findByIp4AddressAndNetworkId(String ip4Address, long networkId);
NicVO findByNetworkIdAndMacAddress(long networkId, String mac);

View File

@ -176,12 +176,21 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
return findOneIncludingRemovedBy(sc);
}
@Override
public NicVO findByNetworkIdAndType(long networkId, VirtualMachine.Type vmType) {
private NicVO findByNetworkIdAndTypeInternal(long networkId, VirtualMachine.Type vmType, boolean includingRemoved) {
SearchCriteria<NicVO> sc = AllFieldsSearch.create();
sc.setParameters("network", networkId);
sc.setParameters("vmType", vmType);
return findOneBy(sc);
return includingRemoved ? findOneIncludingRemovedBy(sc) : findOneBy(sc);
}
@Override
public NicVO findByNetworkIdAndType(long networkId, VirtualMachine.Type vmType) {
return findByNetworkIdAndTypeInternal(networkId, vmType, false);
}
@Override
public NicVO findByNetworkIdAndTypeIncludingRemoved(long networkId, VirtualMachine.Type vmType) {
return findByNetworkIdAndTypeInternal(networkId, vmType, true);
}
@Override

View File

@ -21,6 +21,8 @@ import java.net.URI;
import javax.inject.Inject;
import com.cloud.vm.NicVO;
import com.cloud.vm.VirtualMachine;
import org.apache.cloudstack.network.router.deployment.RouterDeploymentDefinition;
import com.cloud.network.IpAddressManager;
@ -118,7 +120,13 @@ public class NicProfileHelperImpl implements NicProfileHelper {
public NicProfile createGuestNicProfileForVpcRouter(final RouterDeploymentDefinition vpcRouterDeploymentDefinition, final Network guestNetwork) {
final NicProfile guestNic = new NicProfile();
if (vpcRouterDeploymentDefinition.isRedundant()) {
if (BroadcastDomainType.NSX == guestNetwork.getBroadcastDomainType()) {
NicVO vrNic = _nicDao.findByNetworkIdAndTypeIncludingRemoved(guestNetwork.getId(), VirtualMachine.Type.DomainRouter);
if (vrNic != null) {
guestNic.setIPv4Address(vrNic.getIPv4Address());
guestNic.setIPv4Gateway(vrNic.getIPv4Gateway());
}
} else if (vpcRouterDeploymentDefinition.isRedundant()) {
guestNic.setIPv4Address(this.acquireGuestIpAddressForVrouterRedundant(guestNetwork));
} else {
guestNic.setIPv4Address(guestNetwork.getGateway());