Lior Vernia has uploaded a new change for review.

Change subject: engine: Allowed editing a VNIC when VM image locked
......................................................................

engine: Allowed editing a VNIC when VM image locked

This allows updating VNICs while creating a VM from template.

Change-Id: Id3fa46642beacd2ecc0c6d2ad2bde05c890d8256
Bug-Url: https://bugzilla.redhat.com/996568
Signed-off-by: Lior Vernia <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AbstractVmInterfaceCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
8 files changed, 13 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/07/18607/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AbstractVmInterfaceCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AbstractVmInterfaceCommand.java
index 1f3b79b..1307b10 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AbstractVmInterfaceCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AbstractVmInterfaceCommand.java
@@ -14,6 +14,7 @@
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VdcReturnValueBase;
 import org.ovirt.engine.core.common.businessentities.Disk;
+import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmStatic;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
@@ -111,6 +112,12 @@
         return true;
     }
 
+    protected ValidationResult vmStatusLegal(VMStatus status) {
+        return status != VMStatus.Up && status != VMStatus.Down && status != 
VMStatus.ImageLocked
+                ? new 
ValidationResult(VdcBllMessages.NETWORK_CANNOT_ADD_INTERFACE_WHEN_VM_STATUS_NOT_UP_DOWN_LOCKED)
+                : ValidationResult.VALID;
+    }
+
     protected String getMacAddress() {
         return getInterface().getMacAddress();
     }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java
index f27dd16..9dc3eb4 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java
@@ -107,13 +107,7 @@
             return false;
         }
 
-        switch (getVmDynamicDao().get(getParameters().getVmId()).getStatus()) {
-        case Up:
-        case Down:
-        case ImageLocked:
-            break;
-        default:
-            
addCanDoActionMessage(VdcBllMessages.NETWORK_CANNOT_ADD_INTERFACE_WHEN_VM_STATUS_NOT_UP_DOWN_LOCKED);
+        if 
(!validate(vmStatusLegal(getVmDynamicDao().get(getParameters().getVmId()).getStatus())))
 {
             return false;
         }
 
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 1024211..c1d432d 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
@@ -155,8 +155,7 @@
             return false;
         }
 
-        if (!updateVmNicAllowed(getVm().getStatus())) {
-            
addCanDoActionMessage(VdcBllMessages.NETWORK_CANNOT_CHANGE_STATUS_WHEN_NOT_DOWN_UP);
+        if (!validate(vmStatusLegal(getVm().getStatus()))) {
             return false;
         }
 
@@ -280,10 +279,6 @@
 
     private boolean isVnicProfileChanged(VmNic oldNic, VmNic newNic) {
         return !ObjectUtils.equals(oldNic.getVnicProfileId(), 
newNic.getVnicProfileId());
-    }
-
-    private boolean updateVmNicAllowed(VMStatus vmStatus) {
-        return vmStatus == VMStatus.Up || vmStatus == VMStatus.Down;
     }
 
     private enum RequiredAction {
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index 66633df..5328cb1 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -416,7 +416,6 @@
     NETWORK_BOND_HAVE_ATTACHED_VLANS(ErrorType.CONFLICT),
     NETWORK_INTERFACE_NOT_EXISTS(ErrorType.BAD_PARAMETERS),
     NETWORK_INTERFACE_IN_USE_BY_VM(ErrorType.CONFLICT),
-    NETWORK_CANNOT_CHANGE_STATUS_WHEN_NOT_DOWN_UP(ErrorType.CONFLICT),
     
NETWORK_CANNOT_ADD_INTERFACE_WHEN_VM_STATUS_NOT_UP_DOWN_LOCKED(ErrorType.CONFLICT),
     NETWORK_CLUSTER_HAVE_NOT_EXISTING_DATA_CENTER_NETWORK(ErrorType.CONFLICT),
     NETWORK_NOT_EXISTS_IN_CURRENT_CLUSTER(ErrorType.CONFLICT),
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index 1923d5c..4da0807 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -485,8 +485,7 @@
 TAGS_SPECIFY_TAG_IS_NOT_EXISTS=The specified Tag does not exist.
 NETWORK_CANNOT_REMOVE_NETWORK_IN_USE_BY_TEMPLATE=Cannot ${action} ${type}. The 
Network is in use by a Template.\n\
        Network definition cannot be detached unless all references to it are 
cleared.
-NETWORK_CANNOT_CHANGE_STATUS_WHEN_NOT_DOWN_UP=Cannot ${action} ${type}. 
Changing interface properties is allowed only when the VM is in 'Up' or 'Down' 
status.
-NETWORK_CANNOT_ADD_INTERFACE_WHEN_VM_STATUS_NOT_UP_DOWN_LOCKED=Cannot add a 
Network Interface when VM is not Down, Up or Image-Locked.
+NETWORK_CANNOT_ADD_INTERFACE_WHEN_VM_STATUS_NOT_UP_DOWN_LOCKED=Cannot 
${action} a Network Interface when VM is not Down, Up or Image-Locked.
 NETWORK_VLAN_IN_USE=The specified VLAN ID (${vlanId}) is already in use.
 NETWORK_CLUSTER_HAVE_NOT_EXISTING_DATA_CENTER_NETWORK=Cluster has Networks 
that doesn't exist in the Data Center.\n\
        -Please remove those Networks first.
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index ada19e1..7adef82 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -1309,10 +1309,7 @@
     @DefaultStringValue("Cannot ${action} ${type}. The Network is in use by a 
Template.\nNetwork definition cannot be detached unless all references to it 
are cleared.")
     String NETWORK_CANNOT_REMOVE_NETWORK_IN_USE_BY_TEMPLATE();
 
-    @DefaultStringValue("Cannot ${action} ${type}. Changing interface 
properties is allowed only when the VM is in 'Up' or 'Down' status.")
-    String NETWORK_CANNOT_CHANGE_STATUS_WHEN_NOT_DOWN_UP();
-
-    @DefaultStringValue("Cannot add a Network Interface when VM is not Down, 
Up or Image-Locked.")
+    @DefaultStringValue("Cannot ${action} a Network Interface when VM is not 
Down, Up or Image-Locked.")
     String NETWORK_CANNOT_ADD_INTERFACE_WHEN_VM_STATUS_NOT_UP_DOWN_LOCKED();
 
     @DefaultStringValue("The specified VLAN ID (${vlanId}) is already in use.")
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 0bc3be5..5b4a4a8 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -472,8 +472,7 @@
 TAGS_SPECIFY_TAG_IS_NOT_EXISTS=The specified Tag does not exist.
 NETWORK_CANNOT_REMOVE_NETWORK_IN_USE_BY_TEMPLATE=Cannot ${action} ${type}. The 
Network is in use by a Template.\n\
        Network definition cannot be detached unless all references to it are 
cleared.
-NETWORK_CANNOT_CHANGE_STATUS_WHEN_NOT_DOWN_UP=Cannot ${action} ${type}. 
Changing interface properties is allowed only when the VM is in 'Up' or 'Down' 
status.
-NETWORK_CANNOT_ADD_INTERFACE_WHEN_VM_STATUS_NOT_UP_DOWN_LOCKED=Cannot add a 
Network Interface when VM is not Down, Up or Image-Locked.
+NETWORK_CANNOT_ADD_INTERFACE_WHEN_VM_STATUS_NOT_UP_DOWN_LOCKED=Cannot 
${action} a Network Interface when VM is not Down, Up or Image-Locked.
 NETWORK_VLAN_IN_USE=The specified VLAN ID (${vlanId}) is already in use.
 NETWORK_CLUSTER_HAVE_NOT_EXISTING_DATA_CENTER_NETWORK=Cluster has Networks 
that doesn't exist in the Data Center.\n\
        -Please remove those Networks first.
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index da67b61..fccc696 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -489,8 +489,7 @@
 TAGS_SPECIFY_TAG_IS_NOT_EXISTS=The specified Tag does not exist.
 NETWORK_CANNOT_REMOVE_NETWORK_IN_USE_BY_TEMPLATE=Cannot ${action} ${type}. The 
Network is in use by a Template.\n\
        Network definition cannot be detached unless all references to it are 
cleared.
-NETWORK_CANNOT_CHANGE_STATUS_WHEN_NOT_DOWN_UP=Cannot ${action} ${type}. 
Changing interface properties is allowed only when the VM is in 'Up' or 'Down' 
status.
-NETWORK_CANNOT_ADD_INTERFACE_WHEN_VM_STATUS_NOT_UP_DOWN_LOCKED=Cannot add a 
Network Interface when VM is not Down, Up or Image-Locked.
+NETWORK_CANNOT_ADD_INTERFACE_WHEN_VM_STATUS_NOT_UP_DOWN_LOCKED=Cannot 
${action} a Network Interface when VM is not Down, Up or Image-Locked.
 NETWORK_VLAN_IN_USE=The specified VLAN ID (${vlanId}) is already in use.
 NETWORK_CLUSTER_HAVE_NOT_EXISTING_DATA_CENTER_NETWORK=Cluster has Networks 
that doesn't exist in the Data Center.\n\
        -Please remove those Networks first.


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

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

Reply via email to