Skip to content

Commit 3ada5e4

Browse files
author
Alena Prokharchyk
committed
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 Conflicts: server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java server/src/com/cloud/vm/UserVmManagerImpl.java
1 parent 4a2796d commit 3ada5e4

5 files changed

Lines changed: 60 additions & 17 deletions

File tree

‎server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java‎

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ protected List<DomainRouterVO> findOrDeployVirtualRouterInGuestNetwork(Network g
13511351
new Pair<Boolean, PublicIp>(publicNetwork, sourceNatIp));
13521352
//don't start the router as we are holding the network lock that needs to be released at the end of router allocation
13531353
DomainRouterVO router = deployRouter(owner, dest, plan, params, isRedundant, vrProvider, offeringId,
1354-
null, networks, false);
1354+
null, networks, false, null);
13551355

13561356
_routerDao.addRouterToGuestNetwork(router, guestNetwork);
13571357
routers.add(router);
@@ -1369,7 +1369,7 @@ protected List<DomainRouterVO> findOrDeployVirtualRouterInGuestNetwork(Network g
13691369

13701370
protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params,
13711371
boolean isRedundant, VirtualRouterProvider vrProvider, long svcOffId,
1372-
Long vpcId, List<Pair<NetworkVO, NicProfile>> networks, boolean startRouter) throws ConcurrentOperationException,
1372+
Long vpcId, List<Pair<NetworkVO, NicProfile>> networks, boolean startRouter, List<HypervisorType> supportedHypervisors) throws ConcurrentOperationException,
13731373
InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException,
13741374
StorageUnavailableException, ResourceUnavailableException {
13751375

@@ -1382,12 +1382,12 @@ protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, Dep
13821382

13831383
// Router is the network element, we don't know the hypervisor type yet.
13841384
// Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up
1385-
List<HypervisorType> supportedHypervisors = getSupportedHypervisors(dest, plan);
1385+
List<HypervisorType> hypervisors = getHypervisors(dest, plan, supportedHypervisors);
13861386

13871387
int allocateRetry = 0;
13881388
int startRetry = 0;
13891389
DomainRouterVO router = null;
1390-
for (Iterator<HypervisorType> iter = supportedHypervisors.iterator();iter.hasNext();) {
1390+
for (Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext();) {
13911391
HypervisorType hType = iter.next();
13921392
try {
13931393
s_logger.debug("Allocating the domR with the hypervisor type " + hType);
@@ -1446,33 +1446,44 @@ protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, Dep
14461446
}
14471447

14481448

1449-
protected List<HypervisorType> getSupportedHypervisors(DeployDestination dest, DeploymentPlan plan) throws InsufficientServerCapacityException {
1450-
List<HypervisorType> supportedHypervisors = new ArrayList<HypervisorType>();
1449+
protected List<HypervisorType> getHypervisors(DeployDestination dest, DeploymentPlan plan,
1450+
List<HypervisorType> supportedHypervisors) throws InsufficientServerCapacityException {
1451+
List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
14511452
HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId());
14521453
if (defaults != HypervisorType.None) {
1453-
supportedHypervisors.add(defaults);
1454+
hypervisors.add(defaults);
14541455
}
14551456

14561457
if (dest.getCluster() != null) {
14571458
if (dest.getCluster().getHypervisorType() == HypervisorType.Ovm) {
1458-
supportedHypervisors.add(getClusterToStartDomainRouterForOvm(dest.getCluster().getPodId()));
1459+
hypervisors.add(getClusterToStartDomainRouterForOvm(dest.getCluster().getPodId()));
14591460
} else {
1460-
supportedHypervisors.add(dest.getCluster().getHypervisorType());
1461+
hypervisors.add(dest.getCluster().getHypervisorType());
14611462
}
14621463
} else {
1463-
supportedHypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true,
1464+
hypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true,
14641465
plan.getPodId());
14651466
}
14661467

1467-
if (supportedHypervisors.isEmpty()) {
1468+
//keep only elements defined in supported hypervisors
1469+
StringBuilder hTypesStr = new StringBuilder();
1470+
if (supportedHypervisors != null && !supportedHypervisors.isEmpty()) {
1471+
hypervisors.retainAll(supportedHypervisors);
1472+
for (HypervisorType hType : supportedHypervisors) {
1473+
hTypesStr.append(hType).append(" ");
1474+
}
1475+
}
1476+
1477+
if (hypervisors.isEmpty()) {
1478+
String errMsg = (hTypesStr.capacity() > 0) ? "supporting hypervisors " + hTypesStr.toString() : "";
14681479
if (plan.getPodId() != null) {
14691480
throw new InsufficientServerCapacityException("Unable to create virtual router, " +
1470-
"there are no clusters in the pod ", Pod.class, plan.getPodId());
1481+
"there are no clusters in the pod " + errMsg, Pod.class, plan.getPodId());
14711482
}
14721483
throw new InsufficientServerCapacityException("Unable to create virtual router, " +
1473-
"there are no clusters in the zone ", DataCenter.class, dest.getDataCenter().getId());
1484+
"there are no clusters in the zone " + errMsg, DataCenter.class, dest.getDataCenter().getId());
14741485
}
1475-
return supportedHypervisors;
1486+
return hypervisors;
14761487
}
14771488

14781489
protected List<Pair<NetworkVO, NicProfile>> createRouterNetworks(Account owner, boolean isRedundant,

‎server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ protected DomainRouterVO deployVpcRouter(Account owner, DeployDestination dest,
318318
List<Pair<NetworkVO, NicProfile>> networks = createVpcRouterNetworks(owner, isRedundant, plan, new Pair<Boolean, PublicIp>(true, sourceNatIp),
319319
vpcId);
320320
DomainRouterVO router =
321-
super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, networks, true);
321+
super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, networks, true,
322+
_vpcMgr.getSupportedVpcHypervisors());
322323

323324
return router;
324325
}

‎server/src/com/cloud/network/vpc/VpcManager.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.cloud.exception.InsufficientCapacityException;
2525
import com.cloud.exception.ResourceAllocationException;
2626
import com.cloud.exception.ResourceUnavailableException;
27+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2728
import com.cloud.network.IpAddress;
2829
import com.cloud.network.Network;
2930
import com.cloud.network.Network.Service;
@@ -136,4 +137,10 @@ Network createVpcGuestNetwork(long ntwkOffId, String name, String displayText, S
136137
*/
137138
void validateNtwkOffForVpc(NetworkOffering guestNtwkOff, List<Service> supportedSvcs);
138139

140+
141+
/**
142+
* @return
143+
*/
144+
List<HypervisorType> getSupportedVpcHypervisors();
145+
139146
}

‎server/src/com/cloud/network/vpc/VpcManagerImpl.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import com.cloud.exception.ResourceAllocationException;
5555
import com.cloud.exception.ResourceUnavailableException;
5656
import com.cloud.exception.UnsupportedServiceException;
57+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
5758
import com.cloud.network.IPAddressVO;
5859
import com.cloud.network.IpAddress;
5960
import com.cloud.network.Network;
@@ -1954,5 +1955,13 @@ public Network updateVpcGuestNetwork(long networkId, String name, String display
19541955

19551956
return _ntwkMgr.updateGuestNetwork(networkId, name, displayText, callerAccount, callerUser, domainSuffix,
19561957
ntwkOffId, changeCidr);
1957-
}
1958+
}
1959+
1960+
@Override
1961+
public List<HypervisorType> getSupportedVpcHypervisors() {
1962+
List<HypervisorType> hTypes = new ArrayList<HypervisorType>();
1963+
hTypes.add(HypervisorType.XenServer);
1964+
hTypes.add(HypervisorType.VMware);
1965+
return hTypes;
1966+
}
19581967
}

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import org.apache.commons.codec.binary.Base64;
3535
import org.apache.log4j.Logger;
36+
import org.apache.tools.ant.taskdefs.Length.When;
3637

3738
import com.cloud.acl.ControlledEntity.ACLType;
3839
import com.cloud.agent.AgentManager;
@@ -128,6 +129,7 @@
128129
import com.cloud.network.dao.LoadBalancerVMMapDao;
129130
import com.cloud.network.dao.NetworkDao;
130131
import com.cloud.network.dao.NetworkServiceMapDao;
132+
import com.cloud.network.dao.PhysicalNetworkDao;
131133
import com.cloud.network.element.UserDataServiceProvider;
132134
import com.cloud.network.lb.LoadBalancingRulesManager;
133135
import com.cloud.network.rules.FirewallManager;
@@ -139,6 +141,7 @@
139141
import com.cloud.network.security.SecurityGroupManager;
140142
import com.cloud.network.security.dao.SecurityGroupDao;
141143
import com.cloud.network.security.dao.SecurityGroupVMMapDao;
144+
import com.cloud.network.vpc.VpcManager;
142145
import com.cloud.offering.NetworkOffering;
143146
import com.cloud.offering.NetworkOffering.Availability;
144147
import com.cloud.offering.ServiceOffering;
@@ -352,7 +355,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
352355
protected VolumeHostDao _volumeHostDao;
353356
@Inject
354357
ResourceTagDao _resourceTagDao;
355-
358+
@Inject
359+
PhysicalNetworkDao _physicalNetworkDao;
360+
@Inject
361+
VpcManager _vpcMgr;
356362

357363
protected ScheduledExecutorService _executor = null;
358364
protected int _expungeInterval;
@@ -2185,6 +2191,7 @@ public UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serv
21852191
// Verify that caller can perform actions in behalf of vm owner
21862192
_accountMgr.checkAccess(caller, null, true, owner);
21872193

2194+
List<HypervisorType> vpcSupportedHTypes = _vpcMgr.getSupportedVpcHypervisors();
21882195
if (networkIdList == null || networkIdList.isEmpty()) {
21892196
NetworkVO defaultNetwork = null;
21902197

@@ -2227,7 +2234,15 @@ public UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serv
22272234
if (network == null) {
22282235
throw new InvalidParameterValueException("Unable to find network by id " + networkIdList.get(0).longValue());
22292236
}
2237+
if (network.getVpcId() != null) {
2238+
//Only XenServer and VmWare hypervisors are supported for vpc networks
2239+
if (!vpcSupportedHTypes.contains(template.getHypervisorType())) {
2240+
throw new InvalidParameterValueException("Can't create vm from template with hypervisor "
2241+
+ template.getHypervisorType() + " in vpc network " + network);
2242+
}
22302243

2244+
}
2245+
22312246
_networkMgr.checkNetworkPermissions(owner, network);
22322247

22332248
//don't allow to use system networks

0 commit comments

Comments
 (0)