From 1fa67ff3173b13e45140b5b42c5f90c1f4f372a8 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Wed, 22 Aug 2012 11:10:39 -0700 Subject: [PATCH] VPC: CS-16100 - 1) when start VPC router, never pick up any other hypervisor besides vmWare and Xen 2) When start user vm in vpc network, throw an error when deploy from the tempalate of not supported hypervisor Reviewed-by: Frank Zhang --- .../VirtualNetworkApplianceManagerImpl.java | 39 ++++++++++++------- ...VpcVirtualNetworkApplianceManagerImpl.java | 3 +- .../src/com/cloud/network/vpc/VpcManager.java | 7 ++++ .../com/cloud/network/vpc/VpcManagerImpl.java | 11 +++++- .../src/com/cloud/vm/UserVmManagerImpl.java | 13 ++++++- 5 files changed, 56 insertions(+), 17 deletions(-) diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 9253a22ff47..19fa804beb7 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1428,7 +1428,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian new Pair(publicNetwork, sourceNatIp)); //don't start the router as we are holding the network lock that needs to be released at the end of router allocation DomainRouterVO router = deployRouter(owner, dest, plan, params, isRedundant, vrProvider, offeringId, - null, networks, false); + null, networks, false, null); _routerDao.addRouterToGuestNetwork(router, guestNetwork); @@ -1447,7 +1447,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map params, boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId, - Long vpcId, List> networks, boolean startRouter) throws ConcurrentOperationException, + Long vpcId, List> networks, boolean startRouter, List supportedHypervisors) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException { @@ -1460,12 +1460,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian // 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 = getSupportedHypervisors(dest, plan); + List hypervisors = getHypervisors(dest, plan, supportedHypervisors); int allocateRetry = 0; int startRetry = 0; DomainRouterVO router = null; - for (Iterator iter = supportedHypervisors.iterator(); iter.hasNext();) { + for (Iterator iter = hypervisors.iterator(); iter.hasNext();) { HypervisorType hType = iter.next(); try { s_logger.debug("Allocating the domR with the hypervisor type " + hType); @@ -1525,33 +1525,44 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian return router; } - protected List getSupportedHypervisors(DeployDestination dest, DeploymentPlan plan) throws InsufficientServerCapacityException { - List supportedHypervisors = new ArrayList(); + protected List getHypervisors(DeployDestination dest, DeploymentPlan plan, + List supportedHypervisors) throws InsufficientServerCapacityException { + List hypervisors = new ArrayList(); HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId()); if (defaults != HypervisorType.None) { - supportedHypervisors.add(defaults); + hypervisors.add(defaults); } if (dest.getCluster() != null) { if (dest.getCluster().getHypervisorType() == HypervisorType.Ovm) { - supportedHypervisors.add(getClusterToStartDomainRouterForOvm(dest.getCluster().getPodId())); + hypervisors.add(getClusterToStartDomainRouterForOvm(dest.getCluster().getPodId())); } else { - supportedHypervisors.add(dest.getCluster().getHypervisorType()); + hypervisors.add(dest.getCluster().getHypervisorType()); } } else { - supportedHypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true, + hypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true, plan.getPodId()); } - if (supportedHypervisors.isEmpty()) { + //keep only elements defined in supported hypervisors + StringBuilder hTypesStr = new StringBuilder(); + if (supportedHypervisors != null && !supportedHypervisors.isEmpty()) { + hypervisors.retainAll(supportedHypervisors); + for (HypervisorType hType : supportedHypervisors) { + hTypesStr.append(hType).append(" "); + } + } + + if (hypervisors.isEmpty()) { + String errMsg = (hTypesStr.capacity() > 0) ? "supporting hypervisors " + hTypesStr.toString() : ""; if (plan.getPodId() != null) { throw new InsufficientServerCapacityException("Unable to create virtual router, " + - "there are no clusters in the pod ", Pod.class, plan.getPodId()); + "there are no clusters in the pod " + errMsg, Pod.class, plan.getPodId()); } throw new InsufficientServerCapacityException("Unable to create virtual router, " + - "there are no clusters in the zone ", DataCenter.class, dest.getDataCenter().getId()); + "there are no clusters in the zone " + errMsg, DataCenter.class, dest.getDataCenter().getId()); } - return supportedHypervisors; + return hypervisors; } protected List> createRouterNetworks(Account owner, boolean isRedundant, diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index dcf83f4deac..a059975579a 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -318,7 +318,8 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian List> networks = createVpcRouterNetworks(owner, isRedundant, plan, new Pair(true, sourceNatIp), vpcId); DomainRouterVO router = - super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, networks, true); + super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, networks, true, + _vpcMgr.getSupportedVpcHypervisors()); return router; } diff --git a/server/src/com/cloud/network/vpc/VpcManager.java b/server/src/com/cloud/network/vpc/VpcManager.java index 469fab1f74a..d5c44053293 100644 --- a/server/src/com/cloud/network/vpc/VpcManager.java +++ b/server/src/com/cloud/network/vpc/VpcManager.java @@ -20,6 +20,7 @@ import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.IpAddress; import com.cloud.network.Network; import com.cloud.network.Network.Service; @@ -135,4 +136,10 @@ public interface VpcManager extends VpcService{ */ void validateNtwkOffForVpc(NetworkOffering guestNtwkOff, List supportedSvcs); + + /** + * @return + */ + List getSupportedVpcHypervisors(); + } diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java index a8330a0a6e5..1831ce22a15 100644 --- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java +++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java @@ -50,6 +50,7 @@ import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.UnsupportedServiceException; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.IPAddressVO; import com.cloud.network.IpAddress; import com.cloud.network.Network; @@ -1959,5 +1960,13 @@ public class VpcManagerImpl implements VpcManager, Manager{ return _ntwkMgr.updateGuestNetwork(networkId, name, displayText, callerAccount, callerUser, domainSuffix, ntwkOffId, changeCidr); - } + } + + @Override + public List getSupportedVpcHypervisors() { + List hTypes = new ArrayList(); + hTypes.add(HypervisorType.XenServer); + hTypes.add(HypervisorType.VMware); + return hTypes; + } } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 33dd8d74778..af5c991da11 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -134,7 +134,7 @@ import com.cloud.network.security.SecurityGroup; import com.cloud.network.security.SecurityGroupManager; import com.cloud.network.security.dao.SecurityGroupDao; import com.cloud.network.security.dao.SecurityGroupVMMapDao; -import com.cloud.offering.DiskOffering; +import com.cloud.network.vpc.VpcManager; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.Availability; import com.cloud.offering.ServiceOffering; @@ -349,6 +349,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager ResourceTagDao _resourceTagDao; @Inject PhysicalNetworkDao _physicalNetworkDao; + @Inject + VpcManager _vpcMgr; protected ScheduledExecutorService _executor = null; protected int _expungeInterval; @@ -2206,6 +2208,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager // Verify that caller can perform actions in behalf of vm owner _accountMgr.checkAccess(caller, null, true, owner); + List vpcSupportedHTypes = _vpcMgr.getSupportedVpcHypervisors(); if (networkIdList == null || networkIdList.isEmpty()) { NetworkVO defaultNetwork = null; @@ -2256,7 +2259,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (network == null) { throw new InvalidParameterValueException("Unable to find network by id", null); } + if (network.getVpcId() != null) { + //Only XenServer and VmWare hypervisors are supported for vpc networks + if (!vpcSupportedHTypes.contains(template.getHypervisorType())) { + throw new InvalidParameterValueException("Can't create vm from template with hypervisor " + + template.getHypervisorType() + " in vpc network " + network, null); + } + } + _networkMgr.checkNetworkPermissions(owner, network); //don't allow to use system networks