@Override public String getUrl() { if (url != null) { return url; } return imageVO.getUrl(); }
@Override public String getUri() { if (url != null) { return url; } VMTemplateVO image = imageDao.findById(imageVO.getId()); return image.getUrl(); }
@Override public VMTemplateVO create(TemplateProfile profile) { VMTemplateVO template = persistTemplate(profile, State.Active); List<Long> zones = profile.getZoneIdList(); // create an entry at template_store_ref with store_id = null to represent that this template is ready for use. TemplateDataStoreVO vmTemplateHost = new TemplateDataStoreVO(null, template.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, null, template.getUrl()); this._tmpltStoreDao.persist(vmTemplateHost); if (zones == null) { List<DataCenterVO> dcs = _dcDao.listAllIncludingRemoved(); if (dcs != null && dcs.size() > 0) { templateCreateUsage(template, dcs.get(0).getId()); } } else { for (Long zoneId: zones) { templateCreateUsage(template, zoneId); } } _resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template); return template; }
@Override public void addSystemVMTemplatesToSecondary(DataStore store) { long storeId = store.getId(); List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates(); for (VMTemplateVO tmplt : rtngTmplts) { TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId()); if (tmpltStore == null) { tmpltStore = new TemplateDataStoreVO(storeId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH + tmplt.getId() + '/', tmplt.getUrl()); tmpltStore.setSize(0L); tmpltStore.setPhysicalSize(0); // no size information for // pre-seeded system vm templates tmpltStore.setDataStoreRole(store.getRole()); _vmTemplateStoreDao.persist(tmpltStore); } } }
s_logger.error("Unexpected state transition exception for template " + tmplt.getName() + ". Details: " + e.getMessage()); } else if (tmplt.getUrl() == null) { msg = "Private template (" + tmplt + ") with install path " + tmpltInfo.getInstallPath() + " is corrupted, please check in image store: " + tmpltStore.getDataStoreId(); s_logger.warn(msg); if (tmpltInfo.getSize() > 0 && tmplt.getAccountId() != Account.ACCOUNT_ID_SYSTEM && tmplt.getUrl() != null) { long accountId = tmplt.getAccountId(); try { _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(accountId), com.cloud.configuration.Resource.ResourceType.secondary_storage, tmpltInfo.getSize() - UriUtils.getRemoteSize(tmplt.getUrl())); } catch (ResourceAllocationException e) { s_logger.warn(e.getMessage()); tmpltStore = new TemplateDataStoreVO(storeId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, tmpltInfo.getInstallPath(), tmplt.getUrl()); tmpltStore.setSize(tmpltInfo.getSize()); tmpltStore.setPhysicalSize(tmpltInfo.getPhysicalSize()); if (tmplt.getUrl() == null) { // If url is null, skip downloading s_logger.info("Skip downloading template " + tmplt.getUniqueName() + " since no url is specified."); continue;
long guestOsId = dataDiskTemplate.isIso() ? 1 : 0; String templateName = dataDiskTemplate.isIso() ? dataDiskTemplate.getPath().substring(dataDiskTemplate.getPath().lastIndexOf(File.separator) + 1) : template.getName() + suffix + diskCount; VMTemplateVO templateVO = new VMTemplateVO(templateId, templateName, format, false, false, false, ttype, template.getUrl(), template.requiresHvm(), template.getBits(), template.getAccountId(), null, templateName, false, guestOsId, false, template.getHypervisorType(), null, null, false, false, false);
String url = template.getUrl(); String checksum = template.getChecksum(); Map<String, String> headers = getHeadersFromDetails(details);