@Override public VMTemplateVO create(TemplateProfile profile) { VMTemplateVO template = persistTemplate(profile); if (template == null) { throw new CloudRuntimeException("Unable to persist the template " + profile.getTemplate()); } _downloadMonitor.downloadTemplateToStorage(template, profile.getZoneId()); _resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template); return template; }
protected VMTemplateVO persistTemplate(TemplateProfile profile) { Long zoneId = profile.getZoneId(); VMTemplateVO template = new VMTemplateVO( profile.getTemplateId(), profile.getName(), profile.getFormat(), profile.getIsPublic(), profile.getFeatured(), profile.getIsExtractable(), TemplateType.USER, profile.getUrl(), profile.getRequiresHVM(), profile.getBits(), profile.getAccountId(), profile.getCheckSum(), profile.getDisplayText(), profile.getPasswordEnabled(), profile.getGuestOsId(), profile.getBootable(), profile.getHypervisorType(), profile.getTemplateTag(), profile.getDetails()); if (zoneId == null || zoneId == -1) { List<DataCenterVO> dcs = _dcDao.listAllIncludingRemoved(); for (DataCenterVO dc : dcs) { _tmpltDao.addTemplateToZone(template, dc.getId()); } template.setCrossZones(true); } else { _tmpltDao.addTemplateToZone(template, zoneId); } return template; }