mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
VPC: CS-15505 - allocate guest nics when new VR starts in VPC
This commit is contained in:
parent
525ba472e8
commit
c2134b431f
@ -1285,11 +1285,9 @@ 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 {
|
||||
@ -1443,6 +1441,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;
|
||||
|
||||
@ -221,11 +220,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) {
|
||||
@ -275,11 +271,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;
|
||||
@ -795,10 +787,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);
|
||||
@ -860,7 +849,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>();
|
||||
@ -879,9 +868,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) {
|
||||
@ -931,7 +920,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);
|
||||
|
||||
@ -1177,19 +1166,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());
|
||||
|
||||
@ -1210,4 +1206,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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,13 +94,6 @@ public interface VpcManager extends VpcService{
|
||||
*/
|
||||
List<DomainRouterVO> getVpcRouters(long vpcId);
|
||||
|
||||
|
||||
/**
|
||||
* @param zoneId
|
||||
* @return
|
||||
*/
|
||||
boolean vpcProviderEnabledInZone(long zoneId);
|
||||
|
||||
/**
|
||||
* @param vpcId
|
||||
* @return
|
||||
|
||||
@ -19,6 +19,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;
|
||||
@ -120,19 +121,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);
|
||||
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ import com.cloud.host.dao.HostDaoImpl;
|
||||
import com.cloud.network.Network;
|
||||
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;
|
||||
@ -269,12 +270,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,27 +280,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
|
||||
@ -319,11 +320,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…
x
Reference in New Issue
Block a user