Liron Aravot has uploaded a new change for review.

Change subject: core : AddVmFromSnapshot - use device information from snapshot.
......................................................................

core : AddVmFromSnapshot - use device information from snapshot.

When adding a vm from snapshot (clone of a snapshot), the device
information was taken from the vm current state and not from the
snapshot configuration - which caused the cloned vm to not be in the
desired state and possibly have missing devices.

Change-Id: I0611bbbef00fd2c2390ead5f3110e56dcaacd579
BUg-Url: https://bugzilla.redhat.com/show_bug.cgi?id=882644
Signed-off-by: Liron Aravot <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromSnapshotCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
2 files changed, 23 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/52/12452/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromSnapshotCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromSnapshotCommand.java
index 047f8c4..5323a83 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromSnapshotCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromSnapshotCommand.java
@@ -19,6 +19,7 @@
 import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
+import org.ovirt.engine.core.common.businessentities.VmDevice;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
 import 
org.ovirt.engine.core.common.queries.GetVmConfigurationBySnapshotQueryParams;
 import org.ovirt.engine.core.common.queries.VdcQueryReturnValue;
@@ -223,10 +224,9 @@
 
     @Override
     protected void copyVmDevices() {
-        VmDeviceUtils.copyVmDevices(getVmIdFromSnapshot(),
-                getVmId(),
-                newDiskImages,
-                _vmInterfaces);
+        ArrayList<VmDevice> devices = new 
ArrayList<VmDevice>(vmFromConfiguration.getVmUnamagedDeviceList());
+        devices.addAll(vmFromConfiguration.getManagedVmDeviceMap().values());
+        VmDeviceUtils.copyVmDevices(getVmIdFromSnapshot(), getVmId(), 
vmFromConfiguration, vmFromConfiguration.getStaticData(), true, devices, 
newDiskImages, _vmInterfaces);
     }
 
     @Override
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
index f3a6cd5..f0d8335 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
@@ -157,26 +157,10 @@
         }
     }
 
-
-    /**
-     * Copies relevant entries on "Vm from Template" or "Template from VM" 
creation.
-     *
-     * @param srcId
-     * @param dstId
-     * @param disks
-     *            The disks which were saved for the destination VM.
-     */
-    public static void copyVmDevices(Guid srcId, Guid dstId, List<DiskImage> 
disks, List<VmNetworkInterface> ifaces) {
+    public static void copyVmDevices(Guid srcId, Guid dstId, VM vm, VmBase 
vmBase, boolean isVm, List<VmDevice> devices, List<DiskImage> disks, 
List<VmNetworkInterface> ifaces) {
         Guid id;
-        VM vm = DbFacade.getInstance().getVmDao().get(dstId);
-        VmBase vmBase = (vm != null) ? vm.getStaticData() : null;
         int diskCount = 0;
         int ifaceCount = 0;
-        boolean isVm = (vmBase != null);
-        if (!isVm) {
-            vmBase = DbFacade.getInstance().getVmTemplateDao().get(dstId);
-        }
-        List<VmDevice> devices = dao.getVmDeviceByVmId(srcId);
         String isoPath=vmBase.getIsoPath();
         // indicates that VM should have CD either from its own (iso_path) or 
from the snapshot it was cloned from.
         boolean shouldHaveCD = StringUtils.isNotEmpty(isoPath);
@@ -268,6 +252,24 @@
 
         }
     }
+    /**
+     * Copies relevant entries on "Vm from Template" or "Template from VM" 
creation.
+     *
+     * @param srcId
+     * @param dstId
+     * @param disks
+     *            The disks which were saved for the destination VM.
+     */
+    public static void copyVmDevices(Guid srcId, Guid dstId, List<DiskImage> 
disks, List<VmNetworkInterface> ifaces) {
+        VM vm = DbFacade.getInstance().getVmDao().get(dstId);
+        VmBase vmBase = (vm != null) ? vm.getStaticData() : null;
+        boolean isVm = (vmBase != null);
+        if (!isVm) {
+            vmBase = DbFacade.getInstance().getVmTemplateDao().get(dstId);
+        }
+        List<VmDevice> devices = dao.getVmDeviceByVmId(srcId);
+        copyVmDevices(srcId, dstId, vm, vmBase, isVm, devices, disks, ifaces);
+    }
 
     private static void addVideoDevice(VM vm) {
         addManagedDevice(


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

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

Reply via email to