Leonardo Bianconi has uploaded a new change for review.

Change subject: core: Change NIC type from sPAPR VLAN to any other
......................................................................

core: Change NIC type from sPAPR VLAN to any other

After created the VM, added a network interface and have changed its
type, the VM cannot be started.

Change-Id: Ib7b6f182b90197f8552c3ae21bfc0a0e9b25be9f
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1060729
Signed-off-by: Leonardo Bianconi <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
2 files changed, 31 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/14/24014/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java
index d9d4a2c..d8c43e8 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java
@@ -11,6 +11,7 @@
 import org.ovirt.engine.core.bll.network.MacPoolManager;
 import org.ovirt.engine.core.bll.network.cluster.NetworkHelper;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
+import org.ovirt.engine.core.bll.utils.VmDeviceUtils;
 import org.ovirt.engine.core.bll.validator.VmNicValidator;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.FeatureSupported;
@@ -87,6 +88,10 @@
 
             if (macShouldBeChanged) {
                 macAddedToPool = addMacToPool(getMacAddress());
+            }
+
+            if (mustChangeAddress(oldIface.getType(), 
getInterface().getType())) {
+                VmDeviceUtils.clearNicAddress(getInterface().getVmId(), 
getInterface().getId());
             }
 
             
getInterface().setSpeed(VmInterfaceType.forValue(getInterface().getType()).getSpeed());
@@ -277,6 +282,19 @@
         return permissionList;
     }
 
+    /**
+     * Check if address must be changed after change NIC type
+     * @param oldType - Old nic type
+     * @param newType - New nic type
+     * @return
+     */
+    private boolean mustChangeAddress (int oldType, int newType) {
+        return (oldType == VmInterfaceType.spaprVlan.getValue()
+                && newType != VmInterfaceType.spaprVlan.getValue())
+                || (oldType != VmInterfaceType.spaprVlan.getValue()
+                        && newType == VmInterfaceType.spaprVlan.getValue());
+    }
+
     private boolean isVnicProfileChanged(VmNic oldNic, VmNic newNic) {
         return !ObjectUtils.equals(oldNic.getVnicProfileId(), 
newNic.getVnicProfileId());
     }
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 25bc3a8..9a68b5c 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
@@ -18,6 +18,7 @@
 import org.ovirt.engine.core.common.businessentities.Disk;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.DisplayType;
+import org.ovirt.engine.core.common.businessentities.Entities;
 import org.ovirt.engine.core.common.businessentities.UsbPolicy;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VM;
@@ -1045,4 +1046,16 @@
         return dao.getVmDeviceByVmIdTypeAndDevice(
                 vmId, VmDeviceGeneralType.CONTROLLER, 
VmDeviceType.VIRTIOSCSI.getName(), userID, isFiltered);
     }
+
+    public static void clearNicAddress(Guid vmId, Guid nicId) {
+        Map<VmDeviceId, VmDevice> devicesByDeviceId =
+        Entities.businessEntitiesById(DbFacade.getInstance()
+                .getVmDeviceDao()
+                .getVmDeviceByVmIdTypeAndDevice(vmId,
+                        VmDeviceGeneralType.INTERFACE,
+                        VmDeviceType.BRIDGE.getName()));
+        VmDevice vmDevice = devicesByDeviceId.get(new VmDeviceId(nicId, vmId));
+
+        
DbFacade.getInstance().getVmDeviceDao().clearDeviceAddress(vmDevice.getDeviceId());
+    }
 }


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

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

Reply via email to