mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-1895: save placeholder nic with not null vmType='DomainRouter' when placeholder is used for the VR ip address
This commit is contained in:
parent
df48b6531d
commit
42ffac3ae8
|
|
@ -260,7 +260,7 @@ public interface NetworkModel {
|
|||
|
||||
String getStartIpv6Address(long id);
|
||||
|
||||
Nic getPlaceholderNic(Network network, Long podId);
|
||||
|
||||
boolean isProviderEnabledInZone(long zoneId, String provider);
|
||||
|
||||
Nic getPlaceholderNicForRouter(Network network, Long podId);
|
||||
}
|
||||
|
|
@ -483,7 +483,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
|
|||
|
||||
if (add && (!reservedIpAddressesForGuestNetwork.contains(network.getGateway()))) {
|
||||
// Insert a new NIC for this guest network to reserve the gateway address
|
||||
_networkMgr.savePlaceholderNic(network, network.getGateway());
|
||||
_networkMgr.savePlaceholderNic(network, network.getGateway(), null);
|
||||
}
|
||||
|
||||
// Delete any mappings used for inline external load balancers in this network
|
||||
|
|
@ -501,7 +501,7 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl
|
|||
if (!add) {
|
||||
List<NicVO> nics = _nicDao.listByNetworkId(network.getId());
|
||||
for (NicVO nic : nics) {
|
||||
if (nic.getReservationStrategy().equals(ReservationStrategy.PlaceHolder) && nic.getIp4Address().equals(network.getGateway())) {
|
||||
if (nic.getVmType() == null && nic.getReservationStrategy().equals(ReservationStrategy.PlaceHolder) && nic.getIp4Address().equals(network.getGateway())) {
|
||||
s_logger.debug("Removing placeholder nic " + nic + " for the network " + network);
|
||||
_nicDao.remove(nic.getId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,7 +111,6 @@ import com.cloud.user.dao.AccountDao;
|
|||
import com.cloud.user.dao.UserStatisticsDao;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
|
@ -119,18 +118,10 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
|||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.utils.net.UrlUtil;
|
||||
import com.cloud.vm.Nic;
|
||||
import com.cloud.vm.Nic.ReservationStrategy;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.response.ExternalLoadBalancerResponse;
|
||||
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase implements ExternalLoadBalancerDeviceManager, ResourceStateAdapter {
|
||||
|
||||
|
|
@ -783,7 +774,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
|||
// If a NIC doesn't exist for the load balancing IP address, create one
|
||||
loadBalancingIpNic = _nicDao.findByIp4AddressAndNetworkId(loadBalancingIpAddress, network.getId());
|
||||
if (loadBalancingIpNic == null) {
|
||||
loadBalancingIpNic = _networkMgr.savePlaceholderNic(network, loadBalancingIpAddress);
|
||||
loadBalancingIpNic = _networkMgr.savePlaceholderNic(network, loadBalancingIpAddress, null);
|
||||
}
|
||||
|
||||
// Save a mapping between the source IP address and the load balancing IP address NIC
|
||||
|
|
@ -992,7 +983,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
|||
|
||||
if (add) {
|
||||
// on restart network, network could have already been implemented. If already implemented then return
|
||||
Nic selfipNic = _networkModel.getPlaceholderNic(guestConfig, null);
|
||||
Nic selfipNic = getPlaceholderNic(guestConfig);
|
||||
if (selfipNic != null) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1006,7 +997,7 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
|||
}
|
||||
} else {
|
||||
// get the self-ip used by the load balancer
|
||||
Nic selfipNic = _networkModel.getPlaceholderNic(guestConfig, null);
|
||||
Nic selfipNic = getPlaceholderNic(guestConfig);
|
||||
if (selfipNic == null) {
|
||||
s_logger.warn("Network shutdwon requested on external load balancer element, which did not implement the network." +
|
||||
" Either network implement failed half way through or already network shutdown is completed. So just returning.");
|
||||
|
|
@ -1034,10 +1025,10 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
|||
|
||||
if (add) {
|
||||
// Insert a new NIC for this guest network to reserve the self IP
|
||||
_networkMgr.savePlaceholderNic(guestConfig, selfIp);
|
||||
_networkMgr.savePlaceholderNic(guestConfig, selfIp, null);
|
||||
} else {
|
||||
// release the self-ip obtained from guest network
|
||||
Nic selfipNic = _networkModel.getPlaceholderNic(guestConfig, null);
|
||||
Nic selfipNic = getPlaceholderNic(guestConfig);
|
||||
_nicDao.remove(selfipNic.getId());
|
||||
|
||||
// release the load balancer allocated for the network
|
||||
|
|
@ -1211,4 +1202,15 @@ public abstract class ExternalLoadBalancerDeviceManagerImpl extends AdapterBase
|
|||
return answer.getLoadBalancers();
|
||||
}
|
||||
|
||||
private NicVO getPlaceholderNic(Network network) {
|
||||
List<NicVO> guestIps = _nicDao.listByNetworkId(network.getId());
|
||||
for (NicVO guestIp : guestIps) {
|
||||
// only external firewall and external load balancer will create NicVO with PlaceHolder reservation strategy
|
||||
if (guestIp.getReservationStrategy().equals(ReservationStrategy.PlaceHolder) && guestIp.getVmType() == null
|
||||
&& guestIp.getReserver() == null && !guestIp.getIp4Address().equals(network.getGateway())) {
|
||||
return guestIp;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ import com.cloud.vm.NicVO;
|
|||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
/**
|
||||
|
|
@ -345,6 +346,6 @@ public interface NetworkManager {
|
|||
String allocatePublicIpForGuestNic(Long networkId, DataCenter dc, Pod pod, Account caller, String requestedIp) throws InsufficientAddressCapacityException;
|
||||
boolean removeVmSecondaryIpsOfNic(long nicId);
|
||||
|
||||
NicVO savePlaceholderNic(Network network, String ip4Address);
|
||||
NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3488,6 +3488,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
|||
public void allocateDirectIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<? extends VirtualMachine> vm, Network network,
|
||||
String requestedIpv4, String requestedIpv6) throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException {
|
||||
//This method allocates direct ip for the Shared network in Advance zones
|
||||
boolean ipv4 = false, ipv6 = false;
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
|
@ -3500,7 +3501,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
|||
|
||||
//Get ip address from the placeholder and don't allocate a new one
|
||||
if (requestedIpv4 != null && vm.getType() == VirtualMachine.Type.DomainRouter) {
|
||||
Nic placeholderNic = _networkModel.getPlaceholderNic(network, null);
|
||||
Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, null);
|
||||
if (placeholderNic != null) {
|
||||
IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), placeholderNic.getIp4Address());
|
||||
ip = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
|
||||
|
|
@ -3756,11 +3757,12 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
|||
}
|
||||
|
||||
@Override
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address) {
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) {
|
||||
NicVO nic = new NicVO(null, null, network.getId(), null);
|
||||
nic.setIp4Address(ip4Address);
|
||||
nic.setReservationStrategy(ReservationStrategy.PlaceHolder);
|
||||
nic.setState(Nic.State.Reserved);
|
||||
nic.setVmType(vmType);
|
||||
return _nicDao.persist(nic);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,6 @@ import com.cloud.user.Account;
|
|||
import com.cloud.user.DomainManager;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.utils.component.AdapterBase;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.JoinBuilder;
|
||||
|
|
@ -2012,12 +2011,12 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
|
|||
}
|
||||
return startIpv6;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NicVO getPlaceholderNic(Network network, Long podId) {
|
||||
List<NicVO> nics = _nicDao.listPlaceholderNicsByNetworkId(network.getId());
|
||||
public NicVO getPlaceholderNicForRouter(Network network, Long podId) {
|
||||
List<NicVO> nics = _nicDao.listPlaceholderNicsByNetworkIdAndVmType(network.getId(), VirtualMachine.Type.DomainRouter);
|
||||
for (NicVO nic : nics) {
|
||||
if (nic.getVmType() == null && nic.getReserver() == null && nic.getIp4Address() != null && !nic.getIp4Address().equals(network.getGateway())) {
|
||||
if (nic.getReserver() == null && nic.getIp4Address() != null) {
|
||||
if (podId == null) {
|
||||
return nic;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -227,10 +227,10 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
_networkMgr.allocateDirectIp(nic, dc, vm, network, requestedIp4Addr, requestedIp6Addr);
|
||||
//save the placeholder nic if the vm is the Virtual router
|
||||
if (vm.getType() == VirtualMachine.Type.DomainRouter) {
|
||||
Nic placeholderNic = _networkModel.getPlaceholderNic(network, null);
|
||||
Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, null);
|
||||
if (placeholderNic == null) {
|
||||
s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIp4Address() + " and ipv6 address " + requestedIp6Addr + " for the network " + network);
|
||||
_networkMgr.savePlaceholderNic(network, nic.getIp4Address());
|
||||
_networkMgr.savePlaceholderNic(network, nic.getIp4Address(), VirtualMachine.Type.DomainRouter);
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
|
|
@ -259,7 +259,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||
txn.start();
|
||||
|
||||
// if the ip address a part of placeholder, don't release it
|
||||
Nic placeholderNic = _networkModel.getPlaceholderNic(network, null);
|
||||
Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, null);
|
||||
if (placeholderNic != null && placeholderNic.getIp4Address().equalsIgnoreCase(ip.getAddress().addr())) {
|
||||
s_logger.debug("Not releasing direct ip " + ip.getId() +" yet as its ip is saved in the placeholder");
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
|
|
@ -173,7 +174,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
|
|||
}
|
||||
//Get ip address from the placeholder and don't allocate a new one
|
||||
if (vm.getType() == VirtualMachine.Type.DomainRouter) {
|
||||
Nic placeholderNic = _networkModel.getPlaceholderNic(network, null);
|
||||
Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, pod.getId());
|
||||
if (placeholderNic != null) {
|
||||
IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), placeholderNic.getIp4Address());
|
||||
ip = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
|
||||
|
|
@ -199,10 +200,10 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
|
|||
|
||||
//save the placeholder nic if the vm is the Virtual router
|
||||
if (vm.getType() == VirtualMachine.Type.DomainRouter) {
|
||||
Nic placeholderNic = _networkModel.getPlaceholderNic(network, null);
|
||||
Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, pod.getId());
|
||||
if (placeholderNic == null) {
|
||||
s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIp4Address() + " for the network " + network + " with the gateway " + podRangeGateway);
|
||||
_networkMgr.savePlaceholderNic(network, nic.getIp4Address());
|
||||
s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIp4Address() + " for the network " + network);
|
||||
_networkMgr.savePlaceholderNic(network, nic.getIp4Address(), VirtualMachine.Type.DomainRouter);
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
|
|
|
|||
|
|
@ -1708,15 +1708,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
|||
String defaultNetworkStartIp = null, defaultNetworkStartIpv6 = null;
|
||||
if (!setupPublicNetwork) {
|
||||
if (guestNetwork.getCidr() != null) {
|
||||
//Check the placeholder nic, and if it's ip address is not empty, allocate it from there
|
||||
String requestedGateway = null;
|
||||
if (guestNetwork.getGateway() != null) {
|
||||
requestedGateway = guestNetwork.getGateway();
|
||||
} else if (plan != null && plan.getPodId() != null) {
|
||||
Pod pod = _configMgr.getPod(plan.getPodId());
|
||||
requestedGateway = pod.getGateway();
|
||||
}
|
||||
Nic placeholder = _networkModel.getPlaceholderNic(guestNetwork, null);
|
||||
Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, plan.getPodId());
|
||||
if (placeholder != null) {
|
||||
s_logger.debug("Requesting ip address " + placeholder.getIp4Address() + " stored in placeholder nic for the network " + guestNetwork);
|
||||
defaultNetworkStartIp = placeholder.getIp4Address();
|
||||
|
|
|
|||
|
|
@ -248,7 +248,7 @@ public class Upgrade410to420 implements DbUpgrade {
|
|||
String ip = rs.getString(3);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
//Insert placeholder nic for each Domain router nic in Shared network
|
||||
pstmt = conn.prepareStatement("INSERT INTO `cloud`.`nics` (uuid, ip4_address, gateway, network_id, state, strategy) VALUES (?, ?, ?, ?, 'Reserved', 'PlaceHolder')");
|
||||
pstmt = conn.prepareStatement("INSERT INTO `cloud`.`nics` (uuid, ip4_address, gateway, network_id, state, strategy, vm_type) VALUES (?, ?, ?, ?, 'Reserved', 'PlaceHolder', 'DomainRouter')");
|
||||
pstmt.setString(1, uuid);
|
||||
pstmt.setString(2, ip);
|
||||
pstmt.setString(3, gateway);
|
||||
|
|
|
|||
|
|
@ -29,11 +29,9 @@ import javax.persistence.GenerationType;
|
|||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import com.cloud.network.Networks.AddressFormat;
|
||||
import com.cloud.network.Networks.Mode;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
@Entity
|
||||
@Table(name = "nics")
|
||||
|
|
@ -360,4 +358,8 @@ public class NicVO implements Nic {
|
|||
public void setSecondaryIp(boolean secondaryIp) {
|
||||
this.secondaryIp = secondaryIp;
|
||||
}
|
||||
|
||||
public void setVmType(VirtualMachine.Type vmType) {
|
||||
this.vmType = vmType;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,4 +65,5 @@ public interface NicDao extends GenericDao<NicVO, Long> {
|
|||
|
||||
List<NicVO> listPlaceholderNicsByNetworkId(long networkId);
|
||||
|
||||
List<NicVO> listPlaceholderNicsByNetworkIdAndVmType(long networkId, VirtualMachine.Type vmType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,4 +229,13 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
|
|||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NicVO> listPlaceholderNicsByNetworkIdAndVmType(long networkId, VirtualMachine.Type vmType) {
|
||||
SearchCriteria<NicVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("network", networkId);
|
||||
sc.setParameters("strategy", Nic.ReservationStrategy.PlaceHolder.toString());
|
||||
sc.setParameters("vmType", vmType);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ import com.cloud.vm.NicVO;
|
|||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VirtualMachineProfileImpl;
|
||||
|
||||
|
|
@ -884,7 +885,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
|
|||
}
|
||||
|
||||
@Override
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address) {
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -839,15 +839,15 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Nic getPlaceholderNic(Network network, Long podId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProviderEnabledInZone(long zoneId, String provider) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Nic getPlaceholderNicForRouter(Network network, Long podId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ import com.cloud.vm.NicVO;
|
|||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VirtualMachineProfileImpl;
|
||||
|
||||
|
|
@ -1418,7 +1419,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
|
|||
|
||||
|
||||
@Override
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address) {
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -851,16 +851,16 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Nic getPlaceholderNic(Network network, Long podId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProviderEnabledInZone(long zoneId, String provider) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Nic getPlaceholderNicForRouter(Network network, Long podId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue