mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
StartRouter: set only control nic during the initial router start; plug exising public and guest nics after the router is started with control nic
This commit is contained in:
parent
c75fe80125
commit
d70d2f82d4
@ -201,6 +201,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
|||||||
import com.cloud.utils.net.MacAddress;
|
import com.cloud.utils.net.MacAddress;
|
||||||
import com.cloud.utils.net.NetUtils;
|
import com.cloud.utils.net.NetUtils;
|
||||||
import com.cloud.vm.DomainRouterVO;
|
import com.cloud.vm.DomainRouterVO;
|
||||||
|
import com.cloud.vm.Nic;
|
||||||
import com.cloud.vm.NicProfile;
|
import com.cloud.vm.NicProfile;
|
||||||
import com.cloud.vm.NicVO;
|
import com.cloud.vm.NicVO;
|
||||||
import com.cloud.vm.ReservationContext;
|
import com.cloud.vm.ReservationContext;
|
||||||
@ -1565,7 +1566,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||||||
String defaultDns1 = null;
|
String defaultDns1 = null;
|
||||||
String defaultDns2 = null;
|
String defaultDns2 = null;
|
||||||
|
|
||||||
for (NicProfile nic : profile.getNics()) {
|
|
||||||
|
Iterator<NicProfile> it = profile.getNics().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
NicProfile nic = it.next();
|
||||||
int deviceId = nic.getDeviceId();
|
int deviceId = nic.getDeviceId();
|
||||||
buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address());
|
buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address());
|
||||||
buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask());
|
buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask());
|
||||||
@ -1600,6 +1604,10 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||||||
buf.append(" localgw=").append(dest.getPod().getGateway());
|
buf.append(" localgw=").append(dest.getPod().getGateway());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
//Remove public and guest nics from the profile
|
||||||
|
s_logger.debug("Removing nic of type " + nic.getTrafficType() + " from virtual machine profile " + profile.getVirtualMachine());
|
||||||
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1893,15 +1901,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||||||
ReservationContext context) {
|
ReservationContext context) {
|
||||||
DomainRouterVO router = profile.getVirtualMachine();
|
DomainRouterVO router = profile.getVirtualMachine();
|
||||||
|
|
||||||
//Get guest nic info
|
|
||||||
List<NicProfile> routerNics = profile.getNics();
|
|
||||||
List<Network> guestNetworks = new ArrayList<Network>();
|
|
||||||
for (NicProfile routerNic : routerNics) {
|
|
||||||
if (routerNic.getTrafficType() == TrafficType.Guest) {
|
|
||||||
guestNetworks.add(_networkMgr.getNetwork(routerNic.getNetworkId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
|
|
||||||
Answer answer = cmds.getAnswer("checkSsh");
|
Answer answer = cmds.getAnswer("checkSsh");
|
||||||
@ -1917,6 +1916,23 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||||||
if (result == false) {
|
if (result == false) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get guest nic info
|
||||||
|
Map<Nic, Network> guestNics = new HashMap<Nic, Network>();
|
||||||
|
Map<Nic, Network> publicNics = new HashMap<Nic, Network>();
|
||||||
|
List<Network> guestNetworks = new ArrayList<Network>();
|
||||||
|
|
||||||
|
List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
|
||||||
|
for (Nic routerNic : routerNics) {
|
||||||
|
Network network = _networkMgr.getNetwork(routerNic.getNetworkId());
|
||||||
|
if (network.getTrafficType() == TrafficType.Guest) {
|
||||||
|
guestNics.put(routerNic, network);
|
||||||
|
guestNetworks.add(network);
|
||||||
|
} else if (network.getTrafficType() == TrafficType.Public) {
|
||||||
|
publicNics.put(routerNic, network);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
answer = cmds.getAnswer("getDomRVersion");
|
answer = cmds.getAnswer("getDomRVersion");
|
||||||
if (answer != null && answer instanceof GetDomRVersionAnswer) {
|
if (answer != null && answer instanceof GetDomRVersionAnswer) {
|
||||||
GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer)answer;
|
GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer)answer;
|
||||||
@ -1932,6 +1948,30 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
//add router to public and guest networks
|
||||||
|
for (Nic publicNic : publicNics.keySet()) {
|
||||||
|
Network publicNtwk = publicNics.get(publicNic);
|
||||||
|
if (!addRouterToPublicNetwork(router, publicNtwk, _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(),
|
||||||
|
publicNic.getIp4Address()))) {
|
||||||
|
s_logger.warn("Failed to plug nic " + publicNic + " to router " + router);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Nic guestNic : guestNics.keySet()) {
|
||||||
|
Network guestNtwk = guestNics.get(guestNic);
|
||||||
|
if (!addRouterToGuestNetwork(router, guestNtwk, false)) {
|
||||||
|
s_logger.warn("Failed to plug nic " + guestNic + " to router " + router);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
s_logger.warn("Failed to plug nic for router " + router + " due to exception ", ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3051,7 +3091,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||||||
}
|
}
|
||||||
|
|
||||||
NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId());
|
NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), router.getId());
|
||||||
NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null,
|
NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkMgr.getNetworkRate(network.getId(), router.getId()),
|
||||||
_networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(router.getHypervisorType(), network));
|
_networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(router.getHypervisorType(), network));
|
||||||
|
|
||||||
SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, isRedundant, priority,
|
SetupGuestNetworkCommand setupCmd = new SetupGuestNetworkCommand(dhcpRange, networkDomain, isRedundant, priority,
|
||||||
@ -3086,12 +3126,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if router is already a part of the Guest network
|
|
||||||
if (_networkMgr.isVmPartOfNetwork(router.getId(), network.getId())) {
|
|
||||||
s_logger.debug("Router " + router + " is already part of the Guest network " + network);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Add router to the Guest network
|
//Add router to the Guest network
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
try {
|
try {
|
||||||
@ -3155,7 +3189,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean addRouterToPublicNetwork(VirtualRouter router, Network publicNetwork, IpAddress sourceNatIp)
|
protected boolean addRouterToPublicNetwork(VirtualRouter router, Network publicNetwork, IpAddress publicIpAddr)
|
||||||
throws ConcurrentOperationException,ResourceUnavailableException, InsufficientCapacityException {
|
throws ConcurrentOperationException,ResourceUnavailableException, InsufficientCapacityException {
|
||||||
|
|
||||||
if (publicNetwork.getTrafficType() != TrafficType.Public) {
|
if (publicNetwork.getTrafficType() != TrafficType.Public) {
|
||||||
@ -3163,12 +3197,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if router is already a part of the Public network
|
|
||||||
if (_networkMgr.isVmPartOfNetwork(router.getId(), publicNetwork.getId())) {
|
|
||||||
s_logger.debug("Router " + router + " is already part of the Public network " + publicNetwork);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Add router to the Public network
|
//Add router to the Public network
|
||||||
boolean result = true;
|
boolean result = true;
|
||||||
try {
|
try {
|
||||||
@ -3176,8 +3204,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||||||
NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork);
|
NicProfile publicNic = _itMgr.addVmToNetwork(router, publicNetwork);
|
||||||
//setup public network
|
//setup public network
|
||||||
if (publicNic != null) {
|
if (publicNic != null) {
|
||||||
if (sourceNatIp != null) {
|
if (publicIpAddr != null) {
|
||||||
IPAddressVO ipVO = _ipAddressDao.findById(sourceNatIp.getId());
|
IPAddressVO ipVO = _ipAddressDao.findById(publicIpAddr.getId());
|
||||||
PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()),
|
PublicIp publicIp = new PublicIp(ipVO, _vlanDao.findById(ipVO.getVlanId()),
|
||||||
NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
|
NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
|
||||||
result = setupPublicNetwork(publicNetwork, router, false, publicIp);
|
result = setupPublicNetwork(publicNetwork, router, false, publicIp);
|
||||||
@ -3242,10 +3270,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean setupPublicNetwork(Network network, VirtualRouter router, boolean add, PublicIp sourceNatIp)
|
protected boolean setupPublicNetwork(Network network, VirtualRouter router, boolean add, PublicIp ipAddress)
|
||||||
throws ConcurrentOperationException, ResourceUnavailableException{
|
throws ConcurrentOperationException, ResourceUnavailableException{
|
||||||
|
|
||||||
List<PublicIp> publicIps = new ArrayList<PublicIp>(1);
|
List<PublicIp> publicIps = new ArrayList<PublicIp>(1);
|
||||||
|
publicIps.add(ipAddress);
|
||||||
Commands cmds = new Commands(OnError.Stop);
|
Commands cmds = new Commands(OnError.Stop);
|
||||||
createAssociateIPCommands(router, publicIps, cmds, 0);
|
createAssociateIPCommands(router, publicIps, cmds, 0);
|
||||||
sendCommandsToRouter(router, cmds);
|
sendCommandsToRouter(router, cmds);
|
||||||
@ -3254,7 +3283,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||||||
IpAssocAnswer ipAssocAnswer = cmds.getAnswer(IpAssocAnswer.class);
|
IpAssocAnswer ipAssocAnswer = cmds.getAnswer(IpAssocAnswer.class);
|
||||||
String setup = add ? "set" : "destroy";
|
String setup = add ? "set" : "destroy";
|
||||||
if (!(ipAssocAnswer != null && ipAssocAnswer.getResult())) {
|
if (!(ipAssocAnswer != null && ipAssocAnswer.getResult())) {
|
||||||
s_logger.warn("Unable to " + setup + " guest network on router " + router);
|
s_logger.warn("Unable to " + setup + " public network on router " + router);
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2448,31 +2448,40 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||||||
Host host = _hostDao.findById(vm.getHostId());
|
Host host = _hostDao.findById(vm.getHostId());
|
||||||
DeployDestination dest = new DeployDestination(dc, null, null, host);
|
DeployDestination dest = new DeployDestination(dc, null, null, host);
|
||||||
|
|
||||||
s_logger.debug("Adding vm " + vm + " to network " + network);
|
NicProfile nic = null;
|
||||||
|
NicVO nicVO = _nicsDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId());
|
||||||
|
if (nicVO != null) {
|
||||||
|
nic = new NicProfile(nicVO, network, nicVO.getBroadcastUri(), nicVO.getIsolationUri(), _networkMgr.getNetworkRate(network.getId(), vm.getId()),
|
||||||
|
_networkMgr.isSecurityGroupSupportedInNetwork(network), _networkMgr.getNetworkTag(vm.getHypervisorType(), network));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nic == null) {
|
||||||
|
s_logger.debug("Allocating nic for the " + vm + " in network " + network);
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
txn.start();
|
txn.start();
|
||||||
//1) allocate nic
|
//1) allocate nic and prepare nic if needed
|
||||||
NicProfile nic = _networkMgr.allocateNic(null, network, false,
|
int deviceId = _nicsDao.countNics(vm.getId());
|
||||||
100, vmProfile).first();
|
|
||||||
|
nic = _networkMgr.allocateNic(null, network, false,
|
||||||
|
deviceId, vmProfile).first();
|
||||||
|
|
||||||
s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
|
s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
|
||||||
|
|
||||||
//2) Prepare nic
|
|
||||||
nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO);
|
nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO);
|
||||||
|
|
||||||
s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
|
s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
}
|
||||||
|
|
||||||
//3) Convert vmProfile to vmTO
|
//2) Convert vmProfile to vmTO
|
||||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
|
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
|
||||||
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
|
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
|
||||||
|
|
||||||
//4) Convert nicProfile to NicTO
|
//3) Convert nicProfile to NicTO
|
||||||
NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType());
|
NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType());
|
||||||
|
|
||||||
//5) plug the nic to the vm
|
//4) plug the nic to the vm
|
||||||
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
|
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
|
||||||
|
|
||||||
if (vmGuru.plugNic(network, nicTO, vmTO, context, dest)) {
|
if (vmGuru.plugNic(network, nicTO, vmTO, context, dest)) {
|
||||||
@ -2482,7 +2491,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||||||
s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network);
|
s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -46,4 +46,6 @@ public interface NicDao extends GenericDao<NicVO, Long> {
|
|||||||
NicVO findNonReleasedByInstanceIdAndNetworkId(long networkId, long instanceId);
|
NicVO findNonReleasedByInstanceIdAndNetworkId(long networkId, long instanceId);
|
||||||
|
|
||||||
String getIpAddress(long networkId, long instanceId);
|
String getIpAddress(long networkId, long instanceId);
|
||||||
|
|
||||||
|
int countNics(long instanceId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,8 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
|
|||||||
private final SearchBuilder<NicVO> AllFieldsSearch;
|
private final SearchBuilder<NicVO> AllFieldsSearch;
|
||||||
private final GenericSearchBuilder<NicVO, String> IpSearch;
|
private final GenericSearchBuilder<NicVO, String> IpSearch;
|
||||||
private final SearchBuilder<NicVO> NonReleasedSearch;
|
private final SearchBuilder<NicVO> NonReleasedSearch;
|
||||||
|
final GenericSearchBuilder<NicVO, Integer> CountBy;
|
||||||
|
|
||||||
|
|
||||||
protected NicDaoImpl() {
|
protected NicDaoImpl() {
|
||||||
super();
|
super();
|
||||||
@ -55,6 +57,12 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
|
|||||||
NonReleasedSearch.and("network", NonReleasedSearch.entity().getNetworkId(), Op.EQ);
|
NonReleasedSearch.and("network", NonReleasedSearch.entity().getNetworkId(), Op.EQ);
|
||||||
NonReleasedSearch.and("state", NonReleasedSearch.entity().getState(), Op.NOTIN);
|
NonReleasedSearch.and("state", NonReleasedSearch.entity().getState(), Op.NOTIN);
|
||||||
NonReleasedSearch.done();
|
NonReleasedSearch.done();
|
||||||
|
|
||||||
|
CountBy = createSearchBuilder(Integer.class);
|
||||||
|
CountBy.select(null, Func.COUNT, CountBy.entity().getId());
|
||||||
|
CountBy.and("vmId", CountBy.entity().getInstanceId(), Op.EQ);
|
||||||
|
CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL);
|
||||||
|
CountBy.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -150,4 +158,12 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
|
|||||||
return findOneBy(sc).getIp4Address();
|
return findOneBy(sc).getIp4Address();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int countNics(long instanceId) {
|
||||||
|
SearchCriteria<Integer> sc = CountBy.create();
|
||||||
|
sc.setParameters("vmId", instanceId);
|
||||||
|
List<Integer> results = customSearch(sc, null);
|
||||||
|
return results.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
2
wscript
2
wscript
@ -4,7 +4,7 @@
|
|||||||
# the following two variables are used by the target "waf dist"
|
# the following two variables are used by the target "waf dist"
|
||||||
# if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog
|
# if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog
|
||||||
|
|
||||||
VERSION = '3.0.3.2012-06-06T23:35:14Z'
|
VERSION = '3.0.3.2012-06-06T23:43:59Z'
|
||||||
APPNAME = 'cloud'
|
APPNAME = 'cloud'
|
||||||
|
|
||||||
import shutil,os
|
import shutil,os
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user