@Override public String getEventDescription() { return "Deleting ISO " + getId(); }
@Override public Long getInstanceId() { return getId(); }
@Override public long getEntityOwnerId() { VirtualMachineTemplate iso = _entityMgr.findById(VirtualMachineTemplate.class, getId()); if (iso != null) { return iso.getAccountId(); } return Account.ACCOUNT_ID_SYSTEM; }
@Override public void execute() { CallContext.current().setEventDetails("ISO Id: " + getId()); boolean result = _templateService.deleteIso(this); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete ISO"); } } }
@Override public TemplateProfile prepareDelete(DeleteIsoCmd cmd) { Long templateId = cmd.getId(); Long userId = CallContext.current().getCallingUserId(); Account account = CallContext.current().getCallingAccount(); Long zoneId = cmd.getZoneId(); VMTemplateVO template = _tmpltDao.findById(templateId); if (template == null) { throw new InvalidParameterValueException("unable to find iso with id " + templateId); } userId = accountAndUserValidation(account, userId, null, template, "Unable to delete iso "); UserVO user = _userDao.findById(userId); if (user == null) { throw new InvalidParameterValueException("Please specify a valid user."); } if (template.getFormat() != ImageFormat.ISO) { throw new InvalidParameterValueException("Please specify a valid iso."); } return new TemplateProfile(userId, template, zoneId); }
@Override @ActionEvent(eventType = EventTypes.EVENT_ISO_DELETE, eventDescription = "deleting iso", async = true) public boolean deleteIso(DeleteIsoCmd cmd) { Long templateId = cmd.getId(); Account caller = CallContext.current().getCallingAccount(); Long zoneId = cmd.getZoneId(); VMTemplateVO template = _tmpltDao.findById(templateId); if (template == null) { throw new InvalidParameterValueException("unable to find iso with id " + templateId); } _accountMgr.checkAccess(caller, AccessType.OperateEntry, true, template); if (template.getFormat() != ImageFormat.ISO) { throw new InvalidParameterValueException("Please specify a valid iso."); } // check if there is any VM using this ISO. if (!templateIsDeleteable(templateId)) { throw new InvalidParameterValueException("Unable to delete iso, as it's used by other vms"); } if (zoneId != null && (_dataStoreMgr.getImageStore(zoneId) == null)) { throw new InvalidParameterValueException("Failed to find a secondary storage store in the specified zone."); } TemplateAdapter adapter = getAdapter(template.getHypervisorType()); TemplateProfile profile = adapter.prepareDelete(cmd); boolean result = adapter.delete(profile); if (result) { return true; } else { throw new CloudRuntimeException("Failed to delete ISO"); } }