Hello Shmuel Melamud,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/41409

to review the following change.

Change subject: core: Correctly copy memballoon device from template
......................................................................

core: Correctly copy memballoon device from template

When memballoon device is present in the template and enabled in the VM,
it is copied from the template. If it is absent in the template, but
enabled in the VM, it is created for the VM.

Change-Id: I8585a7301ebedb8b93f46dde2677747c5afc1d6f
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1218690
Signed-off-by: Shmuel Melamud <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
1 file changed, 21 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/09/41409/1

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 561aaca..1097c77 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
@@ -300,6 +300,7 @@
         boolean hasSoundDevice = false;
         boolean hasAlreadyConsoleDevice = false;
         boolean hasVirtioScsiController = false;
+        boolean hasAlreadyBalloonDevice = false;
 
         VDSGroup cluster = vmBase.getVdsGroupId() != null ? 
DbFacade.getInstance().getVdsGroupDao().get(vmBase.getVdsGroupId()) : null;
 
@@ -372,6 +373,10 @@
                     break;
 
                 case BALLOON:
+                    hasAlreadyBalloonDevice = true;
+                    if (!isBalloonEnabled) {
+                        continue;
+                    }
                     specParams.put(VdsProperties.Model, VdsProperties.Virtio);
                     break;
 
@@ -445,6 +450,10 @@
 
         if (Boolean.TRUE.equals(isVirtioScsiEnabled) && 
!hasVirtioScsiController) {
             addVirtioScsiController(dstId);
+        }
+
+        if (isBalloonEnabled && !hasAlreadyBalloonDevice) {
+            addEmptyMemoryBalloon(dstId);
         }
 
         if (isVm) {
@@ -1054,10 +1063,7 @@
         boolean hasBalloon = dao.isMemBalloonEnabled(id);
         if (hasBalloon != shouldHaveBalloon) {
             if (!hasBalloon && shouldHaveBalloon) {
-                // add a balloon device
-                Map<String, Object> specParams = new HashMap<>();
-                specParams.put(VdsProperties.Model, VdsProperties.Virtio);
-                addManagedDevice(new VmDeviceId(Guid.newGuid(), id) , 
VmDeviceGeneralType.BALLOON, VmDeviceType.MEMBALLOON, specParams, true, true, 
null, false);
+                addEmptyMemoryBalloon(id);
             }
             else {
                 // remove the balloon device
@@ -1071,6 +1077,17 @@
         }
     }
 
+    private static void addEmptyMemoryBalloon(Guid id) {
+        addManagedDevice(new VmDeviceId(Guid.newGuid(), id),
+                VmDeviceGeneralType.BALLOON,
+                VmDeviceType.MEMBALLOON,
+                Collections.<String, Object>singletonMap(VdsProperties.Model, 
VdsProperties.Virtio),
+                true,
+                true,
+                null,
+                false);
+    }
+
     private static void setNewIdInImportedCollections(VmBase entity) {
         for (VmDevice managedDevice : entity.getManagedDeviceMap().values()){
             if (!isDiskOrInterface(managedDevice)) {


-- 
To view, visit https://gerrit.ovirt.org/41409
To unsubscribe, visit https://gerrit.ovirt.org/settings

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

Reply via email to