Skip to content

Commit d054344

Browse files
authored
Changes to the error message displayed during the removal of public templates that are used (#12373)
1 parent da7ac80 commit d054344

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

server/src/main/java/com/cloud/template/TemplateManagerImpl.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@
219219
import com.cloud.vm.VmDetailConstants;
220220
import com.cloud.vm.dao.UserVmDao;
221221
import com.cloud.vm.dao.VMInstanceDao;
222-
import com.google.common.base.Joiner;
223222
import com.google.gson.Gson;
224223
import com.google.gson.GsonBuilder;
225224

@@ -1375,9 +1374,16 @@ public boolean deleteTemplate(DeleteTemplateCmd cmd) {
13751374
else {
13761375
vmInstanceVOList = _vmInstanceDao.listNonExpungedByTemplate(templateId);
13771376
}
1378-
if(!cmd.isForced() && CollectionUtils.isNotEmpty(vmInstanceVOList)) {
1379-
final String message = String.format("Unable to delete Template: %s because Instance: [%s] are using it.", template, Joiner.on(",").join(vmInstanceVOList));
1380-
logger.warn(message);
1377+
if (!cmd.isForced() && CollectionUtils.isNotEmpty(vmInstanceVOList)) {
1378+
String message = String.format("Unable to delete template [%s] because there are [%d] VM instances using it.", template, vmInstanceVOList.size());
1379+
String instancesListMessage = String.format(" Instances list: [%s].", StringUtils.join(vmInstanceVOList, ","));
1380+
1381+
logger.warn("{}{}", message, instancesListMessage);
1382+
1383+
if (_accountMgr.isRootAdmin(caller.getAccountId())) {
1384+
message += instancesListMessage;
1385+
}
1386+
13811387
throw new InvalidParameterValueException(message);
13821388
}
13831389

0 commit comments

Comments
 (0)