From 67beef15c9d6bc79c5d605af0d79b5a8b5e34e03 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Wed, 14 Aug 2013 11:54:36 -0700 Subject: [PATCH] CLOUDSTACK-3706:[Object_Store_Refactor] Failed to create template from stopped guest vm's root disk. --- .../storage/image/store/TemplateObject.java | 4 +++- .../resource/NfsSecondaryStorageResource.java | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java index 174d5ca293e..b04ca6c2d9b 100644 --- a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java +++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java @@ -202,7 +202,9 @@ public class TemplateObject implements TemplateInfo { templateStoreDao.update(templateStoreRef.getId(), templateStoreRef); if (this.getDataStore().getRole() == DataStoreRole.Image) { VMTemplateVO templateVO = this.imageDao.findById(this.getId()); - templateVO.setFormat(newTemplate.getFormat()); + if (newTemplate.getFormat() != null) { + templateVO.setFormat(newTemplate.getFormat()); + } templateVO.setSize(newTemplate.getSize()); this.imageDao.update(templateVO.getId(), templateVO); } diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java index e45b6858c5b..f2b40f2f134 100755 --- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java +++ b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java @@ -737,13 +737,21 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S final String bucket = s3.getBucketName(); File srcFile = _storage.getFile(templatePath); + // guard the case where templatePath does not have file extension, since we are not completely sure + // about hypervisor, so we check each extension if (!srcFile.exists()) { srcFile = _storage.getFile(templatePath + ".qcow2"); if (!srcFile.exists()) { - return new CopyCmdAnswer("Can't find src file:" + templatePath); + srcFile = _storage.getFile(templatePath + ".vhd"); + if (!srcFile.exists()) { + srcFile = _storage.getFile(templatePath + ".ova"); + if (!srcFile.exists()) { + return new CopyCmdAnswer("Can't find src file:" + templatePath); + } + } } } - ImageFormat format = this.getTemplateFormat(templatePath); + ImageFormat format = this.getTemplateFormat(srcFile.getName()); String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName(); putFile(s3, srcFile, bucket, key); @@ -1386,7 +1394,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S private Answer execute(ListTemplateCommand cmd) { if (!_inSystemVM) { - return new ListTemplateAnswer(null, null); + return new ListTemplateAnswer(null, null); } DataStoreTO store = cmd.getDataStore();