Amit Aviram has uploaded a new change for review.

Change subject: core: Image configuration adjustments for cloning a VM
......................................................................

core: Image configuration adjustments for cloning a VM

Changeoning a VM, in some cases disk image configurations must be
applied before executing the command. specifically when cloning a
VM's snapshot with thin NFS,raw disk allocation , to a VM with thin
block disk allocation- the raw format needs to be changed to COW.

Change-Id: Id924e9beab5d84277fad4f3a2a40b14571beaf22
Id: I7f9f61a69c63da668efee601962bc20de2650629
Bug-Url: https://bugzilla.redhat.com/1121397
Signed-off-by: Amit Aviram <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmAndCloneImageCommand.java
1 file changed, 26 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/25/35225/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmAndCloneImageCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmAndCloneImageCommand.java
index c9fd579..6ebcb53 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmAndCloneImageCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmAndCloneImageCommand.java
@@ -34,6 +34,7 @@
 import org.ovirt.engine.core.common.businessentities.StorageDomain;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
+import org.ovirt.engine.core.common.businessentities.VolumeFormat;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
@@ -161,13 +162,29 @@
         }
 
         for (DiskImage diskImage : getDiskImagesToBeCloned()) {
-            if (!checkImageConfiguration(diskImage)) {
-                return false;
+            // if the image configuration is not supposed to be changed, check 
if it is valid for the cloning.
+            if (!shouldAdjustImageConfiguration(diskImage)) {
+                if (!checkImageConfiguration(diskImage)) {
+                    return false;
+                }
             }
         }
 
         return true;
     }
+
+    private boolean shouldAdjustImageConfiguration(DiskImage diskImage) {
+        return 
(destStorages.get(diskInfoDestinationMap.get(diskImage.getId()).getStorageIds().get(0)).getStorageStaticData().getStorageType().isBlockDomain()
 &&
+                diskImage.getVolumeFormat().equals(VolumeFormat.RAW));
+    }
+
+    private void adjustImageConfiguration(DiskImage diskImage) {
+        if 
(destStorages.get(diskInfoDestinationMap.get(diskImage.getId()).getStorageIds().get(0)).getStorageStaticData().getStorageType().isBlockDomain()
 &&
+                diskImage.getVolumeFormat().equals(VolumeFormat.RAW)) {
+            diskImage.setvolumeFormat(VolumeFormat.COW);
+        }
+    }
+
 
     protected boolean checkImageConfiguration(DiskImage diskImage) {
         return 
ImagesHandler.checkImageConfiguration(destStorages.get(diskInfoDestinationMap.get(diskImage.getId())
@@ -333,6 +350,13 @@
 
     @Override
     protected void executeVmCommand() {
+        for (DiskImage diskImage : getDiskImagesToBeCloned()) {
+            // Adjust disk image configuration if needed.
+            if (shouldAdjustImageConfiguration(diskImage)) {
+                adjustImageConfiguration(diskImage);
+            }
+        }
+
         super.executeVmCommand();
         setVm(null);
         getVm().setVmtGuid(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);


-- 
To view, visit http://gerrit.ovirt.org/35225
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id924e9beab5d84277fad4f3a2a40b14571beaf22
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Amit Aviram <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to