diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 5062dec058d..e135264d3a4 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -2189,54 +2189,54 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag NetworkGuru guru = _networkGurus.get(network.getGuruName()); NicVO nic = _nicDao.findById(nicId); - NicProfile profile = null; - if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { - nic.setState(Nic.State.Reserving); - nic.setReservationId(context.getReservationId()); - _nicDao.update(nic.getId(), nic); - URI broadcastUri = nic.getBroadcastUri(); - if (broadcastUri == null) { - broadcastUri = network.getBroadcastUri(); - } + NicProfile profile = null; + if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) { + nic.setState(Nic.State.Reserving); + nic.setReservationId(context.getReservationId()); + _nicDao.update(nic.getId(), nic); + URI broadcastUri = nic.getBroadcastUri(); + if (broadcastUri == null) { + broadcastUri = network.getBroadcastUri(); + } - URI isolationUri = nic.getIsolationUri(); + URI isolationUri = nic.getIsolationUri(); profile = new NicProfile(nic, network, broadcastUri, isolationUri, - networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); - guru.reserve(profile, network, vmProfile, dest, context); - nic.setIp4Address(profile.getIp4Address()); - nic.setAddressFormat(profile.getFormat()); - nic.setIp6Address(profile.getIp6Address()); - nic.setMacAddress(profile.getMacAddress()); - nic.setIsolationUri(profile.getIsolationUri()); - nic.setBroadcastUri(profile.getBroadCastUri()); - nic.setReserver(guru.getName()); - nic.setState(Nic.State.Reserved); - nic.setNetmask(profile.getNetmask()); - nic.setGateway(profile.getGateway()); + networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); + guru.reserve(profile, network, vmProfile, dest, context); + nic.setIp4Address(profile.getIp4Address()); + nic.setAddressFormat(profile.getFormat()); + nic.setIp6Address(profile.getIp6Address()); + nic.setMacAddress(profile.getMacAddress()); + nic.setIsolationUri(profile.getIsolationUri()); + nic.setBroadcastUri(profile.getBroadCastUri()); + nic.setReserver(guru.getName()); + nic.setState(Nic.State.Reserved); + nic.setNetmask(profile.getNetmask()); + nic.setGateway(profile.getGateway()); - if (profile.getStrategy() != null) { - nic.setReservationStrategy(profile.getStrategy()); - } + if (profile.getStrategy() != null) { + nic.setReservationStrategy(profile.getStrategy()); + } - updateNic(nic, network.getId(), 1); - } else { + updateNic(nic, network.getId(), 1); + } else { profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), - networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); - guru.updateNicProfile(profile, network); - nic.setState(Nic.State.Reserved); - updateNic(nic, network.getId(), 1); - } - - for (NetworkElement element : _networkElements) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Asking " + element.getName() + " to prepare for " + nic); - } - prepareElement(element, network, profile, vmProfile, dest, context); - } - - profile.setSecurityGroupEnabled(isSecurityGroupSupportedInNetwork(network)); + networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network)); guru.updateNicProfile(profile, network); + nic.setState(Nic.State.Reserved); + updateNic(nic, network.getId(), 1); + } + + for (NetworkElement element : _networkElements) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Asking " + element.getName() + " to prepare for " + nic); + } + prepareElement(element, network, profile, vmProfile, dest, context); + } + + profile.setSecurityGroupEnabled(isSecurityGroupSupportedInNetwork(network)); + guru.updateNicProfile(profile, network); return profile; } diff --git a/server/src/com/cloud/network/guru/ControlNetworkGuru.java b/server/src/com/cloud/network/guru/ControlNetworkGuru.java index 4427be7a064..ed0064e774e 100755 --- a/server/src/com/cloud/network/guru/ControlNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ControlNetworkGuru.java @@ -21,8 +21,8 @@ import org.apache.log4j.Logger; import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; -import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.DataCenter; +import com.cloud.dc.DataCenter.NetworkType; import com.cloud.dc.DataCenterVO; import com.cloud.dc.dao.DataCenterDao; import com.cloud.deploy.DeployDestination; @@ -36,12 +36,10 @@ import com.cloud.network.NetworkProfile; import com.cloud.network.NetworkVO; import com.cloud.network.Networks.AddressFormat; import com.cloud.network.Networks.BroadcastDomainType; -import com.cloud.network.Networks.IsolationType; import com.cloud.network.Networks.Mode; import com.cloud.network.Networks.TrafficType; import com.cloud.offering.NetworkOffering; import com.cloud.user.Account; -import com.cloud.utils.Pair; import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.component.Inject; import com.cloud.utils.exception.CloudRuntimeException; diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index ec7bc791ab1..456677aac57 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1237,7 +1237,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (_networkMgr.isNetworkSystem(guestNetwork) || guestNetwork.getGuestType() == Network.GuestType.Shared) { owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM); - } + } //Check if public network has to be set on VR boolean publicNetwork = false; @@ -1252,25 +1252,18 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian Long offeringId = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()).getServiceOfferingId(); if (offeringId == null) { offeringId = _offering.getId(); - } + } PublicIp sourceNatIp = null; - if (publicNetwork) { + if (publicNetwork) { sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork); - } - - //Check if control network has to be set on VR - boolean controlNetwork = true; - if ( dest.getDataCenter().getNetworkType() == NetworkType.Basic ) { - // in basic mode, use private network as control network - controlNetwork = false; } //3) deploy virtual router(s) int count = routerCount - routers.size(); for (int i = 0; i < count; i++) { DomainRouterVO router = deployRouter(owner, dest, plan, params, isRedundant, vrProvider, offeringId, - null, sourceNatIp, publicNetwork, controlNetwork, guestNetwork, new Pair(publicNetwork, sourceNatIp)); + null, sourceNatIp, publicNetwork, guestNetwork, new Pair(publicNetwork, sourceNatIp)); //add router to router network map if (!_routerDao.isRouterPartOfGuestNetwork(router.getId(), network.getId())) { DomainRouterVO routerVO = _routerDao.findById(router.getId()); @@ -1284,12 +1277,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } } return routers; - } + } protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId, - Long vpcId, PublicIp sourceNatIp, boolean setupPublicNetwork, boolean setupControlNetwork, Network guestNetwork, - Pair publicNetwork) throws ConcurrentOperationException, + Long vpcId, PublicIp sourceNatIp, boolean setupPublicNetwork, Network guestNetwork, Pair publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { @@ -1299,100 +1291,100 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } //1) Create router networks - List> networks = createRouterNetworks(owner, isRedundant, plan, setupControlNetwork, - guestNetwork, publicNetwork); + List> networks = createRouterNetworks(owner, isRedundant, plan, guestNetwork, + publicNetwork); ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId); //2) Router is the network element, we don't know the hypervisor type yet. - //Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up - List supportedHypervisors = new ArrayList(); - HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId()); - if (defaults != HypervisorType.None) { - supportedHypervisors.add(defaults); - } + //Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up + List supportedHypervisors = new ArrayList(); + HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId()); + if (defaults != HypervisorType.None) { + supportedHypervisors.add(defaults); + } - if (dest.getCluster() != null) { - if (dest.getCluster().getHypervisorType() == HypervisorType.Ovm) { - supportedHypervisors.add(getClusterToStartDomainRouterForOvm(dest.getCluster().getPodId())); - } else { - supportedHypervisors.add(dest.getCluster().getHypervisorType()); - } - } else { + if (dest.getCluster() != null) { + if (dest.getCluster().getHypervisorType() == HypervisorType.Ovm) { + supportedHypervisors.add(getClusterToStartDomainRouterForOvm(dest.getCluster().getPodId())); + } else { + supportedHypervisors.add(dest.getCluster().getHypervisorType()); + } + } else { supportedHypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true, - plan.getPodId()); - } + plan.getPodId()); + } - if (supportedHypervisors.isEmpty()) { + if (supportedHypervisors.isEmpty()) { if (plan.getPodId() != null) { throw new InsufficientServerCapacityException("Unable to create virtual router, " + "there are no clusters in the pod ", Pod.class, plan.getPodId()); - } + } throw new InsufficientServerCapacityException("Unable to create virtual router, " + "there are no clusters in the zone ", DataCenter.class, dest.getDataCenter().getId()); + } + + int allocateRetry = 0; + int startRetry = 0; + DomainRouterVO router = null; + for (Iterator iter = supportedHypervisors.iterator();iter.hasNext();) { + HypervisorType hType = iter.next(); + try { + s_logger.debug("Allocating the domR with the hypervisor type " + hType); + VMTemplateVO template = _templateDao.findRoutingTemplate(hType); + + if (template == null) { + s_logger.debug(hType + " won't support system vm, skip it"); + continue; } - int allocateRetry = 0; - int startRetry = 0; - DomainRouterVO router = null; - for (Iterator iter = supportedHypervisors.iterator();iter.hasNext();) { - HypervisorType hType = iter.next(); - try { - s_logger.debug("Allocating the domR with the hypervisor type " + hType); - VMTemplateVO template = _templateDao.findRoutingTemplate(hType); - - if (template == null) { - s_logger.debug(hType + " won't support system vm, skip it"); - continue; - } - - boolean offerHA = routerOffering.getOfferHA(); - /* We don't provide HA to redundant router VMs, admin should own it all, and redundant router themselves are HA */ - if (isRedundant) { - offerHA = false; - } + boolean offerHA = routerOffering.getOfferHA(); + /* We don't provide HA to redundant router VMs, admin should own it all, and redundant router themselves are HA */ + if (isRedundant) { + offerHA = false; + } router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(), - VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), - template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false, - RedundantState.UNKNOWN, offerHA, false, vpcId); - router.setRole(Role.VIRTUAL_ROUTER); - router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner); - } catch (InsufficientCapacityException ex) { - if (allocateRetry < 2 && iter.hasNext()) { - s_logger.debug("Failed to allocate the domR with hypervisor type " + hType + ", retrying one more time"); - continue; - } else { - throw ex; - } - } finally { - allocateRetry++; - } - - try { - router = startVirtualRouter(router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), params); - break; - } catch (InsufficientCapacityException ex) { - if (startRetry < 2 && iter.hasNext()) { - s_logger.debug("Failed to start the domR " + router + " with hypervisor type " + hType + ", " + - "destroying it and recreating one more time"); - //destroy the router - destroyRouter(router.getId()); - continue; - } else { - throw ex; - } - } finally { - startRetry++; - } + VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), + template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false, + RedundantState.UNKNOWN, offerHA, false, vpcId); + router.setRole(Role.VIRTUAL_ROUTER); + router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner); + } catch (InsufficientCapacityException ex) { + if (allocateRetry < 2 && iter.hasNext()) { + s_logger.debug("Failed to allocate the domR with hypervisor type " + hType + ", retrying one more time"); + continue; + } else { + throw ex; } + } finally { + allocateRetry++; + } + + try { + router = startVirtualRouter(router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), params); + break; + } catch (InsufficientCapacityException ex) { + if (startRetry < 2 && iter.hasNext()) { + s_logger.debug("Failed to start the domR " + router + " with hypervisor type " + hType + ", " + + "destroying it and recreating one more time"); + //destroy the router + destroyRouter(router.getId()); + continue; + } else { + throw ex; + } + } finally { + startRetry++; + } + } return router; } protected List> createRouterNetworks(Account owner, boolean isRedundant, - DeploymentPlan plan, boolean setupControlNetwork, Network guestNetwork, Pair publicNetwork) throws ConcurrentOperationException, + DeploymentPlan plan, Network guestNetwork, Pair publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException { @@ -1416,8 +1408,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } 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"); + } } - } NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp); if (setupPublicNetwork) { @@ -1437,16 +1429,15 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian } networks.add(new Pair((NetworkVO) guestNetwork, gatewayNic)); hasGuestNetwork = true; - } + } //2) Control network - if (setupControlNetwork) { - s_logger.debug("Adding nic for Virtual Router in Control network "); - List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); - NetworkOfferingVO controlOffering = offerings.get(0); - NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); - networks.add(new Pair(controlConfig, null)); - } + s_logger.debug("Adding nic for Virtual Router in Control network "); + List offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork); + NetworkOfferingVO controlOffering = offerings.get(0); + NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0); + networks.add(new Pair(controlConfig, null)); + //3) Public network if (setupPublicNetwork) { @@ -1687,7 +1678,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian if (controlNic == null) { throw new CloudRuntimeException("Didn't start a control port"); - } + } String rpValue = _configDao.getValue(Config.NetworkRouterRpFilter.key()); if (rpValue != null && rpValue.equalsIgnoreCase("true")) { diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index 47c64031450..89f16c3f847 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -396,7 +396,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian DomainRouterVO router = super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, sourceNatIp, - false, true, null, null); + false, null, null); //Plug public nic if (router != null && sourceNatIp != null) {