mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-1771: Fix ipv6 address for router
Now it won't change(as ipv4 address) after router is destroyed.
This commit is contained in:
parent
5541785827
commit
4a14ea8a4d
@ -485,7 +485,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(), null);
|
||||
_networkMgr.savePlaceholderNic(network, network.getGateway(), null, null);
|
||||
}
|
||||
|
||||
// Delete any mappings used for inline external load balancers in this network
|
||||
|
||||
@ -774,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, null);
|
||||
loadBalancingIpNic = _networkMgr.savePlaceholderNic(network, loadBalancingIpAddress, null, null);
|
||||
}
|
||||
|
||||
// Save a mapping between the source IP address and the load balancing IP address NIC
|
||||
@ -1019,7 +1019,7 @@ 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, null);
|
||||
_networkMgr.savePlaceholderNic(guestConfig, selfIp, null, null);
|
||||
} else {
|
||||
// release the self-ip obtained from guest network
|
||||
Nic selfipNic = getPlaceholderNic(guestConfig);
|
||||
|
||||
@ -381,7 +381,7 @@ public interface NetworkManager {
|
||||
|
||||
String allocatePublicIpForGuestNic(Long networkId, DataCenter dc, Pod pod, Account caller, String requestedIp) throws InsufficientAddressCapacityException;
|
||||
|
||||
NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType);
|
||||
NicVO savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType);
|
||||
|
||||
DhcpServiceProvider getDhcpServiceProvider(Network network);
|
||||
|
||||
|
||||
@ -4325,9 +4325,10 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
||||
|
||||
|
||||
@Override
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) {
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType) {
|
||||
NicVO nic = new NicVO(null, null, network.getId(), null);
|
||||
nic.setIp4Address(ip4Address);
|
||||
nic.setIp6Address(ip6Address);
|
||||
nic.setReservationStrategy(ReservationStrategy.PlaceHolder);
|
||||
nic.setState(Nic.State.Reserved);
|
||||
nic.setVmType(vmType);
|
||||
|
||||
@ -2065,17 +2065,24 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
|
||||
public NicVO getPlaceholderNicForRouter(Network network, Long podId) {
|
||||
List<NicVO> nics = _nicDao.listPlaceholderNicsByNetworkIdAndVmType(network.getId(), VirtualMachine.Type.DomainRouter);
|
||||
for (NicVO nic : nics) {
|
||||
if (nic.getReserver() == null && nic.getIp4Address() != null) {
|
||||
if (nic.getReserver() == null && (nic.getIp4Address() != null || nic.getIp6Address() != null)) {
|
||||
if (podId == null) {
|
||||
return nic;
|
||||
} else {
|
||||
//return nic only when its ip address belong to the pod range (for the Basic zone case)
|
||||
List<? extends Vlan> vlans = _vlanDao.listVlansForPod(podId);
|
||||
for (Vlan vlan : vlans) {
|
||||
IpAddress ip = _ipAddressDao.findByIpAndNetworkId(network.getId(), nic.getIp4Address());
|
||||
if (ip != null && ip.getVlanId() == vlan.getId()) {
|
||||
return nic;
|
||||
}
|
||||
if (nic.getIp4Address() != null) {
|
||||
IpAddress ip = _ipAddressDao.findByIpAndNetworkId(network.getId(), nic.getIp4Address());
|
||||
if (ip != null && ip.getVlanId() == vlan.getId()) {
|
||||
return nic;
|
||||
}
|
||||
} else {
|
||||
UserIpv6AddressVO ipv6 = _ipv6Dao.findByNetworkIdAndIp(network.getId(), nic.getIp6Address());
|
||||
if (ipv6 != null && ipv6.getVlanId() == vlan.getId()) {
|
||||
return nic;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,7 +221,6 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException {
|
||||
|
||||
//FIXME - save ipv6 informaiton in the placeholder nic
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
_networkMgr.allocateDirectIp(nic, dc, vm, network, requestedIp4Addr, requestedIp6Addr);
|
||||
@ -229,8 +228,8 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||
if (vm.getType() == VirtualMachine.Type.DomainRouter) {
|
||||
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(), VirtualMachine.Type.DomainRouter);
|
||||
s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIp4Address() + " and ipv6 address " + nic.getIp6Address() + " for the network " + network);
|
||||
_networkMgr.savePlaceholderNic(network, nic.getIp4Address(), nic.getIp6Address(), VirtualMachine.Type.DomainRouter);
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
|
||||
@ -203,7 +203,7 @@ public class DirectPodBasedNetworkGuru extends DirectNetworkGuru {
|
||||
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);
|
||||
_networkMgr.savePlaceholderNic(network, nic.getIp4Address(), VirtualMachine.Type.DomainRouter);
|
||||
_networkMgr.savePlaceholderNic(network, nic.getIp4Address(), null, VirtualMachine.Type.DomainRouter);
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
|
||||
@ -1740,30 +1740,34 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork);
|
||||
String defaultNetworkStartIp = null, defaultNetworkStartIpv6 = null;
|
||||
if (!setupPublicNetwork) {
|
||||
Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, plan.getPodId());
|
||||
if (guestNetwork.getCidr() != 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();
|
||||
} else {
|
||||
String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
|
||||
if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
|
||||
defaultNetworkStartIp = startIp;
|
||||
} else if (s_logger.isDebugEnabled()){
|
||||
s_logger.debug("First ip " + startIp + " in network id=" + guestNetwork.getId() +
|
||||
" is already allocated, can't use it for domain router; will get random ip address from the range");
|
||||
}
|
||||
}
|
||||
if (placeholder != null && placeholder.getIp4Address() != null) {
|
||||
s_logger.debug("Requesting ipv4 address " + placeholder.getIp4Address() + " stored in placeholder nic for the network " + guestNetwork);
|
||||
defaultNetworkStartIp = placeholder.getIp4Address();
|
||||
} else {
|
||||
String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
|
||||
if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
|
||||
defaultNetworkStartIp = startIp;
|
||||
} else if (s_logger.isDebugEnabled()){
|
||||
s_logger.debug("First ipv4 " + startIp + " in network id=" + guestNetwork.getId() +
|
||||
" is already allocated, can't use it for domain router; will get random ip address from the range");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME - get ipv6 stored in the placeholder
|
||||
|
||||
if (guestNetwork.getIp6Cidr() != null) {
|
||||
String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
|
||||
if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(), startIpv6) == null) {
|
||||
defaultNetworkStartIpv6 = startIpv6;
|
||||
} else if (s_logger.isDebugEnabled()){
|
||||
s_logger.debug("First ipv6 " + startIpv6 + " in network id=" + guestNetwork.getId() +
|
||||
" is already allocated, can't use it for domain router; will get random ipv6 address from the range");
|
||||
if (placeholder != null && placeholder.getIp6Address() != null) {
|
||||
s_logger.debug("Requesting ipv6 address " + placeholder.getIp6Address() + " stored in placeholder nic for the network " + guestNetwork);
|
||||
defaultNetworkStartIpv6 = placeholder.getIp6Address();
|
||||
} else {
|
||||
String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
|
||||
if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(), startIpv6) == null) {
|
||||
defaultNetworkStartIpv6 = startIpv6;
|
||||
} else if (s_logger.isDebugEnabled()){
|
||||
s_logger.debug("First ipv6 " + startIpv6 + " in network id=" + guestNetwork.getId() +
|
||||
" is already allocated, can't use it for domain router; will get random ipv6 address from the range");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,15 +66,8 @@ import com.cloud.user.Account;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.vm.Nic;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.*;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
|
||||
@ -924,7 +917,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
|
||||
|
||||
|
||||
@Override
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) {
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1393,7 +1393,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
|
||||
|
||||
|
||||
@Override
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address, Type vmType) {
|
||||
public NicVO savePlaceholderNic(Network network, String ip4Address, String ip6Address, Type vmType) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user