public TemplateProp getTemplateInfo() { TemplateProp tmplInfo = new TemplateProp(); tmplInfo.id = Long.parseLong(_props.getProperty("id")); tmplInfo.installPath = _templatePath + _props.getProperty("filename"); // _templatePath endsWith / if (_resourceType == ResourceType.VOLUME) { tmplInfo.installPath = tmplInfo.installPath.substring(tmplInfo.installPath.indexOf("volumes")); } else { tmplInfo.installPath = tmplInfo.installPath.substring(tmplInfo.installPath.indexOf("template")); } tmplInfo.isCorrupted = _isCorrupted; tmplInfo.isPublic = Boolean.parseBoolean(_props.getProperty("public")); tmplInfo.templateName = _props.getProperty("uniquename"); if (_props.getProperty("virtualsize") != null) { tmplInfo.size = Long.parseLong(_props.getProperty("virtualsize")); } if (_props.getProperty("size") != null) { tmplInfo.physicalSize = Long.parseLong(_props.getProperty("size")); } return tmplInfo; }
if ((vInfo.getSize() == vInfo.getPhysicalSize()) && (vInfo.getInstallPath().endsWith(ImageFormat.OVA.getFileExtension()))) { try { Processor processor = _processors.get("OVA Processor"); OVAProcessor vmdkProcessor = (OVAProcessor)processor; long vSize = vmdkProcessor.getTemplateVirtualSize(path, vInfo.getInstallPath().substring(vInfo.getInstallPath().lastIndexOf(File.separator) + 1)); vInfo.setSize(vSize); loc.updateVirtualSize(vSize); loc.save(); } catch (Exception e) { s_logger.error("Unable to get the virtual size of the volume: " + vInfo.getInstallPath() + " due to " + e.getMessage()); result.put(vInfo.getId(), vInfo); s_logger.debug("Added volume name: " + vInfo.getTemplateName() + ", path: " + vol);
if (tmpltInfo.isCorrupted()) { tmpltStore.setDownloadState(Status.DOWNLOAD_ERROR); String msg = "Template " + tmplt.getName() + ":" + tmplt.getId() + " is corrupted on secondary storage " + tmpltStore.getId(); msg = "Private template (" + tmplt + ") with install path " + tmpltInfo.getInstallPath() + " is corrupted, please check in image store: " + tmpltStore.getDataStoreId(); s_logger.warn(msg); } else { tmpltInfo.getPhysicalSize(), tmpltInfo.getSize(), VirtualMachineTemplate.class.getName(), tmplt.getUuid()); tmpltStore.setDownloadState(Status.DOWNLOADED); tmpltStore.setState(ObjectInDataStoreStateMachine.State.Ready); tmpltStore.setInstallPath(tmpltInfo.getInstallPath()); tmpltStore.setSize(tmpltInfo.getSize()); tmpltStore.setPhysicalSize(tmpltInfo.getPhysicalSize()); tmpltStore.setLastUpdated(new Date()); tmlpt.setSize(tmpltInfo.getSize()); _templateDao.update(tmplt.getId(), tmlpt); 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());
newTemplate.setPath(destData.getPath() + File.separator + templateName); newTemplate.setFormat(ImageFormat.VHD); newTemplate.setSize(prop.getSize()); newTemplate.setPhysicalSize(prop.getPhysicalSize()); newTemplate.setName(templateUuid); return new CopyCmdAnswer(newTemplate);
if (volInfo.isCorrupted()) { volumeStore.setDownloadState(Status.DOWNLOAD_ERROR); String msg = "Volume " + volume.getUuid() + " is corrupted on image store"; volObj.processEvent(Event.OperationFailed); } else if (volumeStore.getDownloadUrl() == null) { msg = "Volume (" + volume.getUuid() + ") with install path " + volInfo.getInstallPath() + " is corrupted, please check in image store: " + volumeStore.getDataStoreId(); s_logger.warn(msg); volumeStore.setDownloadState(Status.DOWNLOADED); volumeStore.setState(ObjectInDataStoreStateMachine.State.Ready); volumeStore.setInstallPath(volInfo.getInstallPath()); volumeStore.setSize(volInfo.getSize()); volumeStore.setPhysicalSize(volInfo.getPhysicalSize()); volumeStore.setLastUpdated(new Date()); _volumeStoreDao.update(volumeStore.getId(), volumeStore); volume.setSize(volInfo.getSize()); volDao.update(volumeStore.getVolumeId(), volume); if (volInfo.getSize() > 0) { try { _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(volume.getAccountId()), com.cloud.configuration.Resource.ResourceType.secondary_storage, volInfo.getSize() - volInfo.getPhysicalSize()); } catch (ResourceAllocationException e) { s_logger.warn(e.getMessage()); tmplTO.setPath(tInfo.getInstallPath());
newTemplate.setPath(destData.getPath() + File.separator + fileName); newTemplate.setFormat(srcFormat); newTemplate.setSize(prop.getSize()); newTemplate.setPhysicalSize(prop.getPhysicalSize()); return new CopyCmdAnswer(newTemplate); } catch (ConfigurationException e) {
if ((tInfo.getSize() == tInfo.getPhysicalSize()) && (tInfo.getInstallPath().endsWith(ImageFormat.OVA.getFileExtension()))) { try { Processor processor = _processors.get("OVA Processor"); OVAProcessor vmdkProcessor = (OVAProcessor)processor; long vSize = vmdkProcessor.getTemplateVirtualSize(path, tInfo.getInstallPath().substring(tInfo.getInstallPath().lastIndexOf(File.separator) + 1)); tInfo.setSize(vSize); loc.updateVirtualSize(vSize); loc.save(); } catch (Exception e) { s_logger.error("Unable to get the virtual size of the template: " + tInfo.getInstallPath() + " due to " + e.getMessage()); result.put(tInfo.getTemplateName(), tInfo); s_logger.debug("Added template name: " + tInfo.getTemplateName() + ", path: " + tmplt);
public Map<String, TemplateProp> getDefaultSystemVmTemplateInfo() { List<VMTemplateVO> tmplts = _tmpltDao.listAllSystemVMTemplates(); Map<String, TemplateProp> tmpltInfo = new HashMap<String, TemplateProp>(); if (tmplts != null) { for (VMTemplateVO tmplt : tmplts) { TemplateProp routingInfo = new TemplateProp(tmplt.getUniqueName(), TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH + tmplt.getId() + File.separator, false, false); tmpltInfo.put(tmplt.getUniqueName(), routingInfo); } } return tmpltInfo; }
TemplateProp prop = new TemplateProp(uniqName, container + File.separator + name, size, physicalSize, true, false); tmpltInfos.put(uniqName, prop);
Map<Long, TemplateProp> s3ListVolume(S3TO s3) { String bucket = s3.getBucketName(); // List the objects in the source directory on S3 final List<S3ObjectSummary> objectSummaries = S3Utils.listDirectory(s3, bucket, VOLUME_ROOT_DIR); if (objectSummaries == null) { return null; } Map<Long, TemplateProp> tmpltInfos = new HashMap<Long, TemplateProp>(); for (S3ObjectSummary objectSummary : objectSummaries) { String key = objectSummary.getKey(); // String installPath = StringUtils.substringBeforeLast(key, // S3Utils.SEPARATOR); Long id = determineS3VolumeIdFromKey(key); // TODO: how to get volume template name TemplateProp tInfo = new TemplateProp(id.toString(), key, objectSummary.getSize(), objectSummary.getSize(), true, false); tmpltInfos.put(id, tInfo); } return tmpltInfos; }
Map<String, TemplateProp> s3ListTemplate(S3TO s3) { String bucket = s3.getBucketName(); // List the objects in the source directory on S3 final List<S3ObjectSummary> objectSummaries = S3Utils.listDirectory(s3, bucket, TEMPLATE_ROOT_DIR); if (objectSummaries == null) { return null; } Map<String, TemplateProp> tmpltInfos = new HashMap<String, TemplateProp>(); for (S3ObjectSummary objectSummary : objectSummaries) { String key = objectSummary.getKey(); // String installPath = StringUtils.substringBeforeLast(key, // S3Utils.SEPARATOR); String uniqueName = determineS3TemplateNameFromKey(key); // TODO: isPublic value, where to get? TemplateProp tInfo = new TemplateProp(uniqueName, key, objectSummary.getSize(), objectSummary.getSize(), true, false); tmpltInfos.put(uniqueName, tInfo); } return tmpltInfos; }