Updated Branches:
  refs/heads/4.2 7391e5f71 -> 1a3f39473

CLOUDSTACK-4946. VM Restore with template id/Volatile VM feature doesnt work on 
VMware
When a ROOT volume is created from base template, if a folder already exists 
for the ROOT volume's VM then replace the old ROOT disk files with the new one.


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

Branch: refs/heads/4.2
Commit: 1a3f394730e92bb80388a9f78aa83bbc513b451f
Parents: 7391e5f
Author: Likitha Shetty <[email protected]>
Authored: Fri Oct 25 15:39:33 2013 +0530
Committer: Likitha Shetty <[email protected]>
Committed: Mon Oct 28 13:14:48 2013 +0530

----------------------------------------------------------------------
 .../resource/VmwareStorageProcessor.java        | 21 +++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1a3f3947/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
----------------------------------------------------------------------
diff --git 
a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
 
b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
index 05ffec9..3b661e9 100644
--- 
a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
+++ 
b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
@@ -360,11 +360,6 @@ public class VmwareStorageProcessor implements 
StorageProcessor {
                         vmMo.createDisk(volumeDatastorePath, (int) 
(volume.getSize() / (1024L * 1024L)), morDatastore, -1);
                         vmMo.detachDisk(volumeDatastorePath, false);
                     }
-
-                    VolumeObjectTO newVol = new VolumeObjectTO();
-                    newVol.setPath(vmdkName);
-                    newVol.setSize(volume.getSize());
-                    return new CopyCmdAnswer(newVol);
                 } finally {
                     vmMo.detachAllDisks();
 
@@ -398,11 +393,19 @@ public class VmwareStorageProcessor implements 
StorageProcessor {
 
                 String srcFile = dsMo.getDatastorePath(vmdkName, true);
                 dsMo.deleteFile(srcFile, dcMo.getMor(), true);
-                VolumeObjectTO newVol = new VolumeObjectTO();
-                newVol.setPath(vmdkName);
-                newVol.setSize(volume.getSize());
-                return new CopyCmdAnswer(newVol);
             }
+            // restoreVM - move the new ROOT disk into corresponding VM folder
+            String vmInternalCSName = volume.getVmName();
+            if (dsMo.folderExists(String.format("[%s]", dsMo.getName()), 
vmInternalCSName)) {
+                String oldRootDisk = 
VmwareStorageLayoutHelper.getVmwareDatastorePathFromVmdkFileName(dsMo, 
vmInternalCSName, vmdkName);
+                if (oldRootDisk != null)
+                    
VmwareStorageLayoutHelper.syncVolumeToVmDefaultFolder(dcMo, vmInternalCSName, 
dsMo, vmdkName);
+            }
+
+            VolumeObjectTO newVol = new VolumeObjectTO();
+            newVol.setPath(vmdkName);
+            newVol.setSize(volume.getSize());
+            return new CopyCmdAnswer(newVol);
         } catch (Throwable e) {
             if (e instanceof RemoteException) {
                 s_logger.warn("Encounter remote exception to vCenter, 
invalidate VMware session context");

Reply via email to