Pearl1594 commented on code in PR #13101:
URL: https://github.com/apache/cloudstack/pull/13101#discussion_r3191503190


##########
server/src/main/java/com/cloud/template/TemplateManagerImpl.java:
##########
@@ -1206,17 +1244,20 @@ protected TemplateManagerImpl() {
 
     @Override
     public boolean templateIsDeleteable(long templateId) {
+        // ISO can only be referenced by user_vm.iso_id (primary cdrom slot) 
or vm_iso_map (extra slots).
+        // Templates always live on primary storage and aren't tracked here.
         List<UserVmJoinVO> userVmUsingIso = 
_userVmJoinDao.listActiveByIsoId(templateId);
-        // check if there is any Vm using this ISO. We only need to check the
-        // case where templateId is an ISO since
-        // VM can be launched from ISO in secondary storage, while template 
will
-        // always be copied to
-        // primary storage before deploying VM.
         if (!userVmUsingIso.isEmpty()) {
             logger.debug("ISO " + templateId + " is not deleteable because it 
is attached to " + userVmUsingIso.size() + " Instances");
             return false;
         }
-
+        for (VmIsoMapVO row : _vmIsoMapDao.listByIsoId(templateId)) {
+            UserVmVO vm = _userVmDao.findById(row.getVmId());
+            if (vm != null && vm.getState() != State.Error && vm.getState() != 
State.Expunging) {
+                logger.debug("ISO " + templateId + " is not deleteable because 
it is attached to Instance " + vm.getUuid() + " at slot " + row.getDeviceSeq());

Review Comment:
   nit: 
   ```suggestion
                   logger.debug("Unable to delete ISO {} because it is attached 
to Instance {} at slot {}", templateId, vm.getUuid(), row.getDeviceSeq());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to