[GitHub] cloudstack pull request #1773: CLOUDSTACK-9607: Preventing template deletion...
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 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. ---
[GitHub] cloudstack pull request #1773: CLOUDSTACK-9607: Preventing template deletion...
Github user jburwell commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/1773#discussion_r90481980 --- Diff: api/src/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java --- @@ -52,6 +52,9 @@ @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "the ID of zone of the template") private Long zoneId; +@Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, required = false, description = "Force delete a template.") --- End diff -- Please add `since` to this annotation to indicate that this parameter is available in 4.9+. --- 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. ---
[GitHub] cloudstack pull request #1773: CLOUDSTACK-9607: Preventing template deletion...
GitHub user priyankparihar opened a pull request: https://github.com/apache/cloudstack/pull/1773 CLOUDSTACK-9607: Preventing template deletion when template is in use. You can merge this pull request into a Git repository by running: $ git pull https://github.com/priyankparihar/cloudstack CLOUDSTACK-9607 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/cloudstack/pull/1773.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #1773 commit cd367dc46a2edc9732b08b0117320252394fd33d Author: Priyank Parihar Date: 2016-09-27T04:03:58Z CLOUDSTACK-9607: Preventing template deletion when template is in use. Reviewed-by: Koushik Das --- 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. ---