Github user jburwell commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1773#discussion_r90480678 --- Diff: server/src/com/cloud/template/TemplateManagerImpl.java --- @@ -1176,6 +1176,23 @@ public boolean deleteTemplate(DeleteTemplateCmd cmd) { throw new InvalidParameterValueException("unable to find template with id " + templateId); } + List<VMInstanceVO> vmInstanceVOList; + if(cmd.getZoneId() != null) { + vmInstanceVOList = _vmInstanceDao.listNonExpungedByZoneAndTemplate(cmd.getZoneId(), templateId); + } + else { + vmInstanceVOList = _vmInstanceDao.listNonExpungedByTemplate(templateId); + } + if(!cmd.isForced() && CollectionUtils.isNotEmpty(vmInstanceVOList)) { + StringBuilder s = new StringBuilder("Unable to delete template with id: " + templateId + " because some VM instances are using it. "); + for (VMInstanceVO elm : vmInstanceVOList) { + s.append(elm.getInstanceName() + ", "); + } + + s_logger.warn(s.substring(0,s.length()-2)); + throw new InvalidParameterValueException(s.substring(0,s.length()-2)); --- End diff -- Lines 1187-1193 should replaced with the following to be DRY and improve clarity: ```java final String message = String.format("Unable to delete template with id: %1$s because VM instances: [%2$s] are using it.", templateId, Joiner.on(",").join(vmInstanceVOList)); s_logger.warn(message); throw new InvalidParameterValueException(message); ```
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---