From 47882e98093327f28bd71be422a50abf9dd55bcd Mon Sep 17 00:00:00 2001 From: nit Date: Tue, 8 Mar 2011 15:39:38 -0800 Subject: [PATCH] bug 7433: In case of multiple zones deleting a tempate from a zone doesn't prevent a user from selecting it to deploy the VM in the same zone. It was still visible in the listTemplates. Made change to check for template_zone_ref and template_host_ref removed and destroyed columns. During deployVM disallow a vm to be deployed from a template that has been removed in the zone. --- server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java | 6 ++++-- .../src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java | 2 +- server/src/com/cloud/vm/UserVmManagerImpl.java | 8 +++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java b/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java index 79cd61d807f..17ee5e174f3 100755 --- a/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java +++ b/server/src/com/cloud/storage/dao/VMTemplateDaoImpl.java @@ -376,12 +376,14 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem } if (onlyReady){ - sql += " AND thr.download_state = '" +Status.DOWNLOADED.toString() + "'"; + sql += " AND thr.download_state = '" +Status.DOWNLOADED.toString() + "'" + " AND thr.destroyed=0 "; if (zoneId != null){ sql += " AND h.data_center_id = " +zoneId; } }else if (zoneId != null){ - sql += " AND tzr.zone_id = " +zoneId; + sql += " AND tzr.zone_id = " +zoneId+ " AND tzr.removed is null" ; + }else{ + sql += " AND tzr.removed is null "; } if (!showDomr){ sql += " AND t.type != '" +Storage.TemplateType.SYSTEM.toString() + "'"; diff --git a/server/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java b/server/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java index d2d89c7e34c..9e1d323f0ea 100644 --- a/server/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java +++ b/server/src/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java @@ -81,7 +81,7 @@ public class VMTemplateZoneDaoImpl extends GenericDaoBase sc = ZoneTemplateSearch.create(); sc.setParameters("zone_id", zoneId); sc.setParameters("template_id", templateId); - return listIncludingRemovedBy(sc); + return listBy(sc); } } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 9b547fd596a..32e3c10436d 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -129,6 +129,7 @@ import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.GuestOSVO; import com.cloud.storage.SnapshotVO; import com.cloud.storage.Storage; +import com.cloud.storage.VMTemplateZoneVO; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.StorageResourceType; @@ -149,6 +150,7 @@ import com.cloud.storage.dao.SnapshotDao; import com.cloud.storage.dao.StoragePoolDao; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VMTemplateHostDao; +import com.cloud.storage.dao.VMTemplateZoneDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.storage.snapshot.SnapshotManager; import com.cloud.template.VirtualMachineTemplate; @@ -205,6 +207,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager @Inject protected UserStatisticsDao _userStatsDao = null; @Inject protected VMTemplateDao _templateDao = null; @Inject protected VMTemplateHostDao _templateHostDao = null; + @Inject protected VMTemplateZoneDao _templateZoneDao = null; @Inject protected DomainDao _domainDao = null; @Inject protected ResourceLimitDao _limitDao = null; @Inject protected UserVmDao _vmDao = null; @@ -2028,7 +2031,10 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (template.getTemplateType().equals(TemplateType.SYSTEM)) { throw new InvalidParameterValueException("Unable to use system template " + template.getId() + " to deploy a user vm"); } - + List listZoneTemplate = _templateZoneDao.listByZoneTemplate(zone.getId(),template.getId()); + if (listZoneTemplate==null || listZoneTemplate.isEmpty()){ + throw new InvalidParameterValueException("The template " +template.getId()+ " is not available for use"); + } boolean isIso = Storage.ImageFormat.ISO == template.getFormat(); if (isIso && !template.isBootable()) { throw new InvalidParameterValueException("Installing from ISO requires an ISO that is bootable: " + template.getId());