From fc357e9831c9dd3b2929489ee859bf96fc95b939 Mon Sep 17 00:00:00 2001 From: Saksham Srivastava Date: Fri, 28 Jun 2013 00:16:02 +0530 Subject: [PATCH] CLOUDSTACK-3064: Able to create an instance from different account of the same domain without using affinity group even if the zone is dedicated to an account. The check to make sure that explicit resources are not picked up for non-explicit deployment was present only at the domain level for zones. Added a check at account level too. --- .../cloud/deploy/DeploymentPlanningManagerImpl.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java index eb895e53b04..e0f017dad3c 100644 --- a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java +++ b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java @@ -452,9 +452,22 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements Deploy DedicatedResourceVO dedicatedZone = _dedicatedDao.findByZoneId(dc.getId()); if (dedicatedZone != null) { long accountDomainId = vmProfile.getOwner().getDomainId(); + long accountId = vmProfile.getOwner().getAccountId(); if (dedicatedZone.getDomainId() != null && !dedicatedZone.getDomainId().equals(accountDomainId)) { throw new CloudRuntimeException("Failed to deploy VM. Zone " + dc.getName() + " is dedicated."); } + + // If a zone is dedicated to an account then all hosts in this zone will be explicitly dedicated to + // that account. So there won't be any shared hosts in the zone, the only way to deploy vms from that + // account will be to use explicit dedication affinity group. + if (dedicatedZone.getAccountId() != null) { + if (dedicatedZone.getAccountId().equals(accountId)) { + throw new CloudRuntimeException("Failed to deploy VM. There are no shared hosts available in" + + " this dedicated zone."); + } else { + throw new CloudRuntimeException("Failed to deploy VM. Zone " + dc.getName() + " is dedicated."); + } + } } List podsInDc = _podDao.listByDataCenterId(dc.getId());