Repository: cloudstack
Updated Branches:
  refs/heads/master b54ae7391 -> 1bb31412f


CLOUDSTACK-6170 (VMware root-disk support for managed storage)


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

Branch: refs/heads/master
Commit: 1bb31412fc70d9dab94d5f81b745d3cae3e5b1ec
Parents: b54ae73
Author: Mike Tutkowski <mike.tutkow...@solidfire.com>
Authored: Sat Apr 19 23:39:57 2014 -0600
Committer: Mike Tutkowski <mike.tutkow...@solidfire.com>
Committed: Mon Apr 21 22:22:50 2014 -0600

----------------------------------------------------------------------
 .../resource/VmwareStorageProcessor.java        | 43 +++++++++++++-------
 1 file changed, 28 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1bb31412/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 fd7520e..e413524 100644
--- 
a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
+++ 
b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java
@@ -139,8 +139,8 @@ public class VmwareStorageProcessor implements 
StorageProcessor {
         return null;
     }
 
-    private void copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost 
hyperHost, DatastoreMO datastoreMo, String secondaryStorageUrl,
-            String templatePathAtSecondaryStorage, String templateName, String 
templateUuid) throws Exception {
+    private VirtualMachineMO 
copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, DatastoreMO 
datastoreMo, String secondaryStorageUrl,
+            String templatePathAtSecondaryStorage, String templateName, String 
templateUuid, boolean createSnapshot) throws Exception {
 
         s_logger.info("Executing copyTemplateFromSecondaryToPrimary. 
secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: 
" +
                 templatePathAtSecondaryStorage + ", templateName: " + 
templateName);
@@ -186,17 +186,24 @@ public class VmwareStorageProcessor implements 
StorageProcessor {
             throw new Exception(msg);
         }
 
-        if (vmMo.createSnapshot("cloud.template.base", "Base snapshot", false, 
false)) {
-            // the same template may be deployed with multiple copies at 
per-datastore per-host basis,
-            // save the original template name from CloudStack DB as the UUID 
to associate them.
-            vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_UUID, 
templateName);
-            vmMo.markAsTemplate();
-        } else {
-            vmMo.destroy();
-            String msg = "Unable to create base snapshot for template, 
templateName: " + templateName + ", templateUuid: " + templateUuid;
-            s_logger.error(msg);
-            throw new Exception(msg);
+        if (createSnapshot) {
+            if (vmMo.createSnapshot("cloud.template.base", "Base snapshot", 
false, false)) {
+                // the same template may be deployed with multiple copies at 
per-datastore per-host basis,
+                // save the original template name from CloudStack DB as the 
UUID to associate them.
+                vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_UUID, 
templateName);
+                vmMo.markAsTemplate();
+            } else {
+                vmMo.destroy();
+
+                String msg = "Unable to create base snapshot for template, 
templateName: " + templateName + ", templateUuid: " + templateUuid;
+
+                s_logger.error(msg);
+
+                throw new Exception(msg);
+            }
         }
+
+        return vmMo;
     }
 
     @Override
@@ -289,10 +296,12 @@ public class VmwareStorageProcessor implements 
StorageProcessor {
 
                 dsMo = new DatastoreMO(context, morDs);
 
-                copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, 
secondaryStorageUrl, templateInfo.first(), templateInfo.second(),
-                        managed ? managedStoragePoolRootVolumeName : 
templateUuidName);
-
                 if (managed) {
+                    VirtualMachineMO vmMo = 
copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, secondaryStorageUrl, 
templateInfo.first(), templateInfo.second(),
+                            managedStoragePoolRootVolumeName, false);
+
+                    vmMo.unregisterVm();
+
                     String[] vmwareLayoutFilePair = 
VmwareStorageLayoutHelper.getVmdkFilePairDatastorePath(dsMo, 
managedStoragePoolRootVolumeName,
                         managedStoragePoolRootVolumeName, 
VmwareStorageLayoutType.VMWARE, false);
                     String[] legacyCloudStackLayoutFilePair = 
VmwareStorageLayoutHelper.getVmdkFilePairDatastorePath(dsMo, null,
@@ -304,6 +313,10 @@ public class VmwareStorageProcessor implements 
StorageProcessor {
                     String folderToDelete = 
dsMo.getDatastorePath(managedStoragePoolRootVolumeName, true);
                     dsMo.deleteFolder(folderToDelete, dcMo.getMor());
                 }
+                else {
+                    copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, 
secondaryStorageUrl, templateInfo.first(), templateInfo.second(),
+                            templateUuidName, true);
+                }
             } else {
                 s_logger.info("Template " + templateInfo.second() + " has 
already been setup, skip the template setup process in primary storage");
             }

Reply via email to