protected void validateParameters() { if ((zoneId != null) && (zoneIds != null && !zoneIds.isEmpty())) throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Both zoneid and zoneids cannot be specified at the same time"); if (zoneId == null && (zoneIds == null || zoneIds.isEmpty())) throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Either zoneid or zoneids is required. Both cannot be null."); if (zoneIds != null && zoneIds.size() > 1 && zoneIds.contains(-1L)) throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Parameter zoneids cannot combine all zones (-1) option with other zones"); if (isDirectDownload() && !getHypervisor().equalsIgnoreCase(Hypervisor.HypervisorType.KVM.toString())) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Parameter directdownload is only allowed for KVM templates"); } } }
@Override public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException { TemplateProfile profile = super.prepare(cmd); String url = profile.getUrl(); UriUtils.validateUrl(cmd.getFormat(), url); if (cmd.isDirectDownload()) { DigestHelper.validateChecksumString(cmd.getChecksum()); Long templateSize = performDirectDownloadUrlValidation(url); profile.setSize(templateSize); } profile.setUrl(url); // Check that the resource limit for secondary storage won't be exceeded _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(cmd.getEntityOwnerId()), ResourceType.secondary_storage, UriUtils.getRemoteSize(url)); return profile; }
@Override public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException { //check if the caller can operate with the template owner Account caller = CallContext.current().getCallingAccount(); Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId()); _accountMgr.checkAccess(caller, null, true, owner); boolean isRouting = (cmd.isRoutingType() == null) ? false : cmd.isRoutingType(); List<Long> zoneId = cmd.getZoneIds(); // ignore passed zoneId if we are using region wide image store List<ImageStoreVO> stores = _imgStoreDao.findRegionImageStores(); if (stores != null && stores.size() > 0) { zoneId = null; } HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor()); if(hypervisorType == HypervisorType.None) { throw new InvalidParameterValueException("Hypervisor Type: " + cmd.getHypervisor() + " is invalid. Supported Hypervisor types are " + EnumUtils.listValues(HypervisorType.values()).replace("None, ", "")); } return prepare(false, CallContext.current().getCallingUserId(), cmd.getTemplateName(), cmd.getDisplayText(), cmd.getBits(), cmd.isPasswordEnabled(), cmd.getRequiresHvm(), cmd.getUrl(), cmd.isPublic(), cmd.isFeatured(), cmd.isExtractable(), cmd.getFormat(), cmd.getOsTypeId(), zoneId, hypervisorType, cmd.getChecksum(), true, cmd.getTemplateTag(), owner, cmd.getDetails(), cmd.isSshKeyEnabled(), null, cmd.isDynamicallyScalable(), isRouting ? TemplateType.ROUTING : TemplateType.USER, cmd.isDirectDownload()); }