Updated Branches:
  refs/heads/4.2 a71810f70 -> 838345088

CLOUDSTACK-3741:Object_Store_Refactor - [KVM] Creation of Template from
Snapshot Fails.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/83834508
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/83834508
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/83834508

Branch: refs/heads/4.2
Commit: 838345088c0683eb3b28bed96ed1b109843f9a6a
Parents: a71810f
Author: Min Chen <[email protected]>
Authored: Wed Jul 24 09:25:20 2013 -0700
Committer: Min Chen <[email protected]>
Committed: Wed Jul 24 09:26:35 2013 -0700

----------------------------------------------------------------------
 .../resource/NfsSecondaryStorageResource.java       | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/83834508/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
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 5318e09..29c05d5 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
@@ -417,15 +417,21 @@ public class NfsSecondaryStorageResource extends 
ServerResourceBase implements S
         } else if (srcData.getHypervisorType() == HypervisorType.KVM) {
             File srcFile = getFile(srcData.getPath(), srcDataStore.getUrl());
             File destFile = getFile(destData.getPath(), 
destDataStore.getUrl());
-            s_logger.debug("copy snapshot to template");
-            Script.runSimpleBashScript("cp " + srcFile.getAbsolutePath() + " " 
+ destFile.getAbsolutePath());
+            // get snapshot file name, add extension if it is missing
+            String templateName = srcFile.getName();
+            if (!templateName.endsWith(ImageFormat.QCOW2.getFileExtension())) {
+                templateName = templateName + 
ImageFormat.QCOW2.getFileExtension();
+            }
+            String destFileFullPath = destFile.getAbsolutePath() + 
File.separator + templateName;
+            s_logger.debug("copy snapshot " + srcFile.getAbsolutePath() + " to 
template " + destFileFullPath);
+            Script.runSimpleBashScript("cp " + srcFile.getAbsolutePath() + " " 
+ destFileFullPath);
+            // template post processing
             QCOW2Processor processor = new QCOW2Processor();
             Map<String, Object> params = new HashMap<String, Object>();
             params.put(StorageLayer.InstanceConfigKey, _storage);
             try {
                 processor.configure("qcow2 processor", params);
                 String destPath = destFile.getAbsolutePath();
-                String templateName = srcFile.getName();
                 FormatInfo info = processor.process(destPath, null, 
templateName);
                 TemplateLocation loc = new TemplateLocation(_storage, 
destPath);
                 loc.create(1, true, srcFile.getName());
@@ -434,7 +440,7 @@ public class NfsSecondaryStorageResource extends 
ServerResourceBase implements S
                 TemplateProp prop = loc.getTemplateInfo();
                 TemplateObjectTO newTemplate = new TemplateObjectTO();
                 newTemplate.setPath(destData.getPath() + File.separator + 
templateName);
-                newTemplate.setFormat(ImageFormat.VHD);
+                newTemplate.setFormat(ImageFormat.QCOW2);
                 newTemplate.setSize(prop.getSize());
                 return new CopyCmdAnswer(newTemplate);
             } catch (ConfigurationException e) {
@@ -481,7 +487,7 @@ public class NfsSecondaryStorageResource extends 
ServerResourceBase implements S
                     return answer;
                 }
                 s_logger.debug("starting copy template to swift");
-                DataTO newTemplate = (DataTO)answer.getNewData();
+                DataTO newTemplate = answer.getNewData();
                 File templateFile = getFile(newTemplate.getPath(), ((NfsTO) 
srcDataStore).getUrl());
                 SwiftTO swift = (SwiftTO)destDataStore;
                 String containterName = 
SwiftUtil.getContainerName(destData.getObjectType().toString(), 
destData.getId());

Reply via email to