|
29 | 29 | import javax.inject.Inject; |
30 | 30 |
|
31 | 31 | import com.cloud.domain.Domain; |
| 32 | +import com.cloud.vm.VMInstanceVO; |
| 33 | +import com.cloud.vm.dao.VMInstanceDao; |
32 | 34 | import org.apache.cloudstack.agent.directdownload.CheckUrlAnswer; |
33 | 35 | import org.apache.cloudstack.agent.directdownload.CheckUrlCommand; |
34 | 36 | import org.apache.cloudstack.annotation.AnnotationService; |
@@ -142,6 +144,8 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase { |
142 | 144 | private TemplateDeployAsIsDetailsDao templateDeployAsIsDetailsDao; |
143 | 145 | @Inject |
144 | 146 | private AnnotationDao annotationDao; |
| 147 | + @Inject |
| 148 | + VMInstanceDao _vmInstanceDao; |
145 | 149 |
|
146 | 150 | @Override |
147 | 151 | public String getName() { |
@@ -665,6 +669,14 @@ public boolean delete(TemplateProfile profile) { |
665 | 669 | // Remove template details |
666 | 670 | templateDetailsDao.removeDetails(template.getId()); |
667 | 671 |
|
| 672 | + // Remove deploy-as-is details (if any and if there are no VMs using it) |
| 673 | + if (template.isDeployAsIs()) { |
| 674 | + List<VMInstanceVO> vmInstanceVOList = _vmInstanceDao.listNonExpungedByTemplate(template.getId()); |
| 675 | + if (CollectionUtils.isEmpty(vmInstanceVOList)) { |
| 676 | + templateDeployAsIsDetailsDao.removeDetails(template.getId()); |
| 677 | + } |
| 678 | + } |
| 679 | + |
668 | 680 | // Remove comments (if any) |
669 | 681 | AnnotationService.EntityType entityType = template.getFormat().equals(ImageFormat.ISO) ? |
670 | 682 | AnnotationService.EntityType.ISO : AnnotationService.EntityType.TEMPLATE; |
|
0 commit comments