mirror of https://github.com/apache/cloudstack.git
VPC: CS-15505 - allocate guest nics when new VR starts in VPC
This commit is contained in:
parent
d53be4f6bd
commit
08b9b3bc5b
|
|
@ -1261,13 +1261,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
new Pair<Boolean, PublicIp>(publicNetwork, sourceNatIp));
|
||||
DomainRouterVO router = deployRouter(owner, dest, plan, params, isRedundant, vrProvider, offeringId,
|
||||
null, networks);
|
||||
//add router to router network map
|
||||
if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) {
|
||||
DomainRouterVO routerVO = _routerDao.findById(router.getId());
|
||||
_routerDao.addRouterToGuestNetwork(routerVO, network);
|
||||
}
|
||||
|
||||
_routerDao.addRouterToGuestNetwork(router, network);
|
||||
|
||||
routers.add(router);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (network != null) {
|
||||
_networkDao.releaseFromLockTable(network.getId());
|
||||
|
|
@ -1419,6 +1417,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
} else {
|
||||
gatewayNic.setDefaultNic(true);
|
||||
}
|
||||
|
||||
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, gatewayNic));
|
||||
hasGuestNetwork = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
|
|
@ -226,11 +225,8 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
//Add router to the Guest network
|
||||
boolean result = true;
|
||||
try {
|
||||
if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) {
|
||||
DomainRouterVO routerVO = _routerDao.findById(router.getId());
|
||||
_routerDao.addRouterToGuestNetwork(routerVO, network);
|
||||
}
|
||||
|
||||
_routerDao.addRouterToGuestNetwork(router, network);
|
||||
|
||||
NicProfile guestNic = _itMgr.addVmToNetwork(router, network, null);
|
||||
//setup guest network
|
||||
if (guestNic != null) {
|
||||
|
|
@ -280,11 +276,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
|
||||
if (result) {
|
||||
if (result) {
|
||||
//check if router is already part of network
|
||||
if (_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) {
|
||||
s_logger.debug("Removing router " + router + " from network" + network);
|
||||
_routerDao.removeRouterFromNetwork(router.getId(), network.getId());
|
||||
}
|
||||
_routerDao.removeRouterFromGuestNetwork(router.getId(), network.getId());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
@ -810,10 +802,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//4) PREPARE PLUG NIC COMMANDS
|
||||
//3) PREPARE PLUG NIC COMMANDS
|
||||
try {
|
||||
//add VPC router to public networks
|
||||
List<PublicIp> sourceNat = new ArrayList<PublicIp>(1);
|
||||
|
|
@ -874,7 +863,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
return false;
|
||||
}
|
||||
|
||||
//5) RE-APPLY ALL STATIC ROUTE RULES
|
||||
//4) RE-APPLY ALL STATIC ROUTE RULES
|
||||
List<? extends StaticRoute> routes = _staticRouteDao.listByVpcId(router.getVpcId());
|
||||
List<StaticRouteProfile> staticRouteProfiles = new ArrayList<StaticRouteProfile>(routes.size());
|
||||
Map<Long, VpcGateway> gatewayMap = new HashMap<Long, VpcGateway>();
|
||||
|
|
@ -893,9 +882,9 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
createStaticRouteCommands(staticRouteProfiles, router, cmds);
|
||||
}
|
||||
|
||||
//6) REISSUE VPN CONNECTION
|
||||
//5) REISSUE VPN CONNECTION
|
||||
|
||||
//7) REPROGRAM GUEST NETWORK
|
||||
//6) REPROGRAM GUEST NETWORK
|
||||
boolean reprogramGuestNtwks = true;
|
||||
if (profile.getParameter(Param.ReProgramGuestNetworks) != null
|
||||
&& (Boolean) profile.getParameter(Param.ReProgramGuestNetworks) == false) {
|
||||
|
|
@ -945,7 +934,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
boolean result = true;
|
||||
try {
|
||||
Network network = _networkMgr.getNetwork(gateway.getNetworkId());
|
||||
NicProfile requested = createPrivateNicProfile(gateway);
|
||||
NicProfile requested = createPrivateNicProfileForGateway(gateway);
|
||||
|
||||
NicProfile guestNic = _itMgr.addVmToNetwork(router, network, requested);
|
||||
|
||||
|
|
@ -1191,19 +1180,26 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(4);
|
||||
networks = super.createRouterNetworks(owner, isRedundant, plan, null, publicNetwork);
|
||||
|
||||
//allocate nic for private gateway if needed
|
||||
//1) allocate nic for private gateway if needed
|
||||
VpcGateway privateGateway = _vpcMgr.getPrivateGatewayForVpc(vpcId);
|
||||
if (privateGateway != null) {
|
||||
NicProfile privateNic = createPrivateNicProfile(privateGateway);
|
||||
NicProfile privateNic = createPrivateNicProfileForGateway(privateGateway);
|
||||
Network privateNetwork = _networkMgr.getNetwork(privateGateway.getNetworkId());
|
||||
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) privateNetwork, privateNic));
|
||||
}
|
||||
|
||||
//2) allocate nic for guest gateway if needed
|
||||
List<? extends Network> guestNetworks = _vpcMgr.getVpcNetworks(vpcId);
|
||||
for (Network guestNetwork : guestNetworks) {
|
||||
NicProfile guestNic = createGuestNicProfileForVpcRouter(guestNetwork);
|
||||
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, guestNic));
|
||||
}
|
||||
|
||||
return networks;
|
||||
}
|
||||
|
||||
@DB
|
||||
protected NicProfile createPrivateNicProfile(VpcGateway privateGateway) {
|
||||
protected NicProfile createPrivateNicProfileForGateway(VpcGateway privateGateway) {
|
||||
Network network = _networkMgr.getNetwork(privateGateway.getNetworkId());
|
||||
PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(network.getDataCenterId(), network.getId(), privateGateway.getIp4Address());
|
||||
|
||||
|
|
@ -1224,4 +1220,16 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
|
|||
return privateNic;
|
||||
}
|
||||
|
||||
protected NicProfile createGuestNicProfileForVpcRouter(Network guestNetwork) {
|
||||
NicProfile guestNic = new NicProfile();
|
||||
guestNic.setIp4Address(guestNetwork.getGateway());
|
||||
guestNic.setBroadcastUri(guestNetwork.getBroadcastUri());
|
||||
guestNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
|
||||
guestNic.setIsolationUri(guestNetwork.getBroadcastUri());
|
||||
guestNic.setMode(guestNetwork.getMode());
|
||||
String gatewayCidr = guestNetwork.getCidr();
|
||||
guestNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
|
||||
|
||||
return guestNic;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ package com.cloud.vm.dao;
|
|||
import java.util.List;
|
||||
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
|
|
@ -116,19 +117,12 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
|
|||
* @param routerId
|
||||
* @param guestNetwork
|
||||
*/
|
||||
void addRouterToGuestNetwork(DomainRouterVO router, Network guestNetwork);
|
||||
void addRouterToGuestNetwork(VirtualRouter router, Network guestNetwork);
|
||||
|
||||
/**
|
||||
* @param routerId
|
||||
* @param guestNetworkId
|
||||
*/
|
||||
void removeRouterFromNetwork(long routerId, long guestNetworkId);
|
||||
|
||||
/**
|
||||
* @param routerId
|
||||
* @param guestNetworkId
|
||||
* @return
|
||||
*/
|
||||
boolean isRouterPartOfGuestNetwork(long routerId, long guestNetworkId);
|
||||
void removeRouterFromGuestNetwork(long routerId, long guestNetworkId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ import javax.ejb.Local;
|
|||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDaoImpl;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.RouterNetworkDaoImpl;
|
||||
import com.cloud.network.RouterNetworkVO;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.user.UserStatisticsVO;
|
||||
|
|
@ -266,12 +266,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
|
|||
if (guestNetworks != null && !guestNetworks.isEmpty()) {
|
||||
// 2) add router to the network
|
||||
for (Network guestNetwork : guestNetworks) {
|
||||
if (!isRouterPartOfGuestNetwork(router.getId(), guestNetwork.getId())) {
|
||||
//add only when network is not private network
|
||||
if (!(guestNetwork.getName() != NetworkOffering.SystemPrivateGatewayNetworkOffering)) {
|
||||
addRouterToGuestNetwork(router, guestNetwork);
|
||||
}
|
||||
}
|
||||
addRouterToGuestNetwork(router, guestNetwork);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -281,27 +276,32 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
|
|||
|
||||
@Override
|
||||
@DB
|
||||
public void addRouterToGuestNetwork(DomainRouterVO router, Network guestNetwork) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
//1) add router to network
|
||||
RouterNetworkVO routerNtwkMap = new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType());
|
||||
_routerNetworkDao.persist(routerNtwkMap);
|
||||
//2) create user stats entry for the network
|
||||
UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(),
|
||||
guestNetwork.getId(), null, router.getId(), router.getType().toString());
|
||||
if (stats == null) {
|
||||
stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(),
|
||||
router.getType().toString(), guestNetwork.getId());
|
||||
_userStatsDao.persist(stats);
|
||||
}
|
||||
txn.commit();
|
||||
public void addRouterToGuestNetwork(VirtualRouter router, Network guestNetwork) {
|
||||
if (_routerNetworkDao.findByRouterAndNetwork(router.getId(), guestNetwork.getId()) == null &&
|
||||
guestNetwork.getName() != NetworkOffering.SystemPrivateGatewayNetworkOffering) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
//1) add router to network
|
||||
RouterNetworkVO routerNtwkMap = new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType());
|
||||
_routerNetworkDao.persist(routerNtwkMap);
|
||||
//2) create user stats entry for the network
|
||||
UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(),
|
||||
guestNetwork.getId(), null, router.getId(), router.getType().toString());
|
||||
if (stats == null) {
|
||||
stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(),
|
||||
router.getType().toString(), guestNetwork.getId());
|
||||
_userStatsDao.persist(stats);
|
||||
}
|
||||
txn.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRouterFromNetwork(long routerId, long guestNetworkId) {
|
||||
public void removeRouterFromGuestNetwork(long routerId, long guestNetworkId) {
|
||||
RouterNetworkVO routerNtwkMap = _routerNetworkDao.findByRouterAndNetwork(routerId, guestNetworkId);
|
||||
_routerNetworkDao.remove(routerNtwkMap.getId());
|
||||
if (routerNtwkMap != null) {
|
||||
_routerNetworkDao.remove(routerNtwkMap.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -316,11 +316,5 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
|
|||
sc.setParameters("role", Role.VIRTUAL_ROUTER);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRouterPartOfGuestNetwork(long routerId, long guestNetworkId) {
|
||||
RouterNetworkVO routerNtwkMap = _routerNetworkDao.findByRouterAndNetwork(routerId, guestNetworkId);
|
||||
return routerNtwkMap != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue