File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
server/src/main/java/com/cloud/template Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change 2929import javax .inject .Inject ;
3030
3131import com .cloud .domain .Domain ;
32+ import com .cloud .vm .VMInstanceVO ;
3233import org .apache .cloudstack .agent .directdownload .CheckUrlAnswer ;
3334import org .apache .cloudstack .agent .directdownload .CheckUrlCommand ;
3435import org .apache .cloudstack .annotation .AnnotationService ;
@@ -665,6 +666,14 @@ public boolean delete(TemplateProfile profile) {
665666 // Remove template details
666667 templateDetailsDao .removeDetails (template .getId ());
667668
669+ // Remove deploy-as-is details (if any and if there are no VMs using it)
670+ if (template .isDeployAsIs ()) {
671+ List <VMInstanceVO > vmInstanceVOList = _vmInstanceDao .listNonExpungedByTemplate (template .getId ());
672+ if (CollectionUtils .isEmpty (vmInstanceVOList )) {
673+ templateDeployAsIsDetailsDao .removeDetails (template .getId ());
674+ }
675+ }
676+
668677 // Remove comments (if any)
669678 AnnotationService .EntityType entityType = template .getFormat ().equals (ImageFormat .ISO ) ?
670679 AnnotationService .EntityType .ISO : AnnotationService .EntityType .TEMPLATE ;
Original file line number Diff line number Diff line change 2828import com .cloud .storage .upload .params .TemplateUploadParams ;
2929import com .cloud .storage .upload .params .UploadParams ;
3030import com .cloud .vm .VmDetailConstants ;
31+ import com .cloud .vm .dao .VMInstanceDao ;
3132import org .apache .cloudstack .api .command .user .iso .GetUploadParamsForIsoCmd ;
3233import org .apache .cloudstack .api .command .user .template .GetUploadParamsForTemplateCmd ;
3334import org .apache .commons .collections .CollectionUtils ;
@@ -123,6 +124,8 @@ public abstract class TemplateAdapterBase extends AdapterBase implements Templat
123124 ProjectManager _projectMgr ;
124125 @ Inject
125126 private TemplateDataStoreDao templateDataStoreDao ;
127+ @ Inject
128+ VMInstanceDao _vmInstanceDao ;
126129
127130 @ Override
128131 public boolean stop () {
You can’t perform that action at this time.
0 commit comments