Gustavo Frederico Temple Pedrosa has uploaded a new change for review.

Change subject: engine: Vnic interface validation
......................................................................

engine: Vnic interface validation

This change displays an error if the network interface type is not
compatible with the selected operating system.

Change-Id: Ia1236826adbc021f4fa7f3816c6bd8a2f199de79
Signed-off-by: Gustavo Pedrosa <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.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/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.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
10 files changed, 62 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/42/18042/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java
index ffd932b..d947756 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java
@@ -68,9 +68,11 @@
         }
 
         Version clusterCompatibilityVersion = 
getVdsGroup().getcompatibility_version();
-        VmNicValidator nicValidator = new 
VmNicValidator(getParameters().getInterface(), clusterCompatibilityVersion);
+        VmNicValidator nicValidator = new 
VmNicValidator(getParameters().getInterface(), clusterCompatibilityVersion, 
getVmTemplate().getOsId());
 
-        if (!validate(nicValidator.linkedCorrectly()) || 
!validate(nicValidator.emptyNetworkValid())) {
+        if (!validate(nicValidator.linkedCorrectly())
+                || !validate(nicValidator.isVersionCompatible())
+                || !validate(nicValidator.emptyNetworkValid())) {
             return false;
         }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java
index 3eec8d7..5dbbec8 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java
@@ -62,9 +62,11 @@
         });
 
         Version clusterCompatibilityVersion = 
getVdsGroup().getcompatibility_version();
-        VmNicValidator nicValidator = new 
VmNicValidator(getParameters().getInterface(), clusterCompatibilityVersion);
+        VmNicValidator nicValidator = new 
VmNicValidator(getParameters().getInterface(), clusterCompatibilityVersion, 
getVmTemplate().getOsId());
 
-        if (!validate(nicValidator.linkedCorrectly()) || 
!validate(nicValidator.emptyNetworkValid())) {
+        if (!validate(nicValidator.linkedCorrectly())
+                || !validate(nicValidator.isVersionCompatible())
+                || !validate(nicValidator.emptyNetworkValid())) {
             return false;
         }
 
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 adf0429..0b6db00 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
@@ -131,9 +131,11 @@
         }
 
         Version compatibilityVersion = 
getVm().getVdsGroupCompatibilityVersion();
-        VmNicValidator nicValidator = new VmNicValidator(getInterface(), 
compatibilityVersion);
+        VmNicValidator nicValidator = new VmNicValidator(getInterface(), 
compatibilityVersion, getVm().getOs());
 
-        if (!validate(nicValidator.linkedCorrectly()) || 
!validate(nicValidator.emptyNetworkValid())) {
+        if (!validate(nicValidator.linkedCorrectly())
+                || !validate(nicValidator.isVersionCompatible())
+                || !validate(nicValidator.emptyNetworkValid())) {
             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 f1de649..0cb8db6 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
@@ -184,9 +184,10 @@
         }
 
         UpdateVmNicValidator nicValidator =
-                new UpdateVmNicValidator(getInterface(), 
getVm().getVdsGroupCompatibilityVersion());
+                new UpdateVmNicValidator(getInterface(), 
getVm().getVdsGroupCompatibilityVersion(), getVm().getOs());
         if (!validate(nicValidator.unplugPlugNotRequired())
                 || !validate(nicValidator.linkedCorrectly())
+                || !validate(nicValidator.isVersionCompatible())
                 || !validate(nicValidator.emptyNetworkValid())
                 || !validate(nicValidator.hotUpdatePossible())) {
             return false;
@@ -300,6 +301,10 @@
             super(nic, version);
         }
 
+        public UpdateVmNicValidator(VmNic nic, Version version, int osId) {
+            super(nic, version, osId);
+        }
+
         /**
          * @return An error if hot updated is needed, and either network 
linking is not supported or the NIC has port
          *         mirroring set.
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java
index 3e7a2c9..bb2b66e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java
@@ -1,9 +1,15 @@
 package org.ovirt.engine.core.bll.validator;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.ovirt.engine.core.bll.ValidationResult;
 import org.ovirt.engine.core.common.FeatureSupported;
+import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.osinfo.OsRepository;
+import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.compat.Version;
 
 /**
@@ -17,9 +23,17 @@
 
     protected Version version;
 
+    protected int osId;
+
     public VmNicValidator(VmNic nic, Version version) {
         this.nic = nic;
         this.version = version;
+    }
+
+    public VmNicValidator(VmNic nic, Version version, int osId) {
+        this.nic = nic;
+        this.version = version;
+        this.osId = osId;
     }
 
     /**
@@ -43,4 +57,27 @@
     protected String clusterVersion() {
         return String.format(CLUSTER_VERSION_REPLACEMENT_FORMAT, 
version.getValue());
     }
+
+    /**
+     * @return An error if the network interface type is not compatible with 
the selected operating
+     *         system.
+     */
+    public ValidationResult isVersionCompatible() {
+
+        OsRepository osRepository = 
SimpleDependecyInjector.getInstance().get(OsRepository.class);
+
+        ArrayList<String> networkDevices = 
osRepository.getNetworkDevices(osId, version);
+
+        List<VmInterfaceType> interfaceTypes = new 
ArrayList<VmInterfaceType>();
+
+        for (String networkDevice : networkDevices) {
+            interfaceTypes.add(VmInterfaceType.valueOf(networkDevice));
+        }
+
+        return 
(!interfaceTypes.contains(VmInterfaceType.forValue(nic.getType())))
+                ? new 
ValidationResult(VdcBllMessages.VM_INTERFACE_VERSION_IS_NOT_SUPPORTED)
+                : ValidationResult.VALID;
+
+    }
+
 }
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 639b2e6..a399da4 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
@@ -624,6 +624,7 @@
     UNLINKING_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
     NULL_NETWORK_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
     HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
+    VM_INTERFACE_VERSION_IS_NOT_SUPPORTED(ErrorType.INCOMPATIBLE_VERSION),
     CANNOT_PERFOM_HOT_UPDATE(ErrorType.CONFLICT),
     CANNOT_PERFOM_HOT_UPDATE_WITH_PORT_MIRRORING(ErrorType.CONFLICT),
     PORT_MIRRORING_REQUIRES_NETWORK(ErrorType.BAD_PARAMETERS),
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 393146b..4283632 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -809,6 +809,7 @@
 UNLINKING_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Link state is set to 
'Down' on the virtual machine's interface, this is not supported for clusters 
of version ${clusterVersion}.
 NULL_NETWORK_IS_NOT_SUPPORTED=Cannot ${action} ${type}. There is no network on 
the virtual machine's interface, this is not supported for clusters of version 
${clusterVersion}.
 HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Updating 
the virtual machine interface while the virtual machine is running is not 
supported for clusters of version ${clusterVersion}.
+VM_INTERFACE_VERSION_IS_NOT_SUPPORTED=Cannot ${action} ${type}. The network 
interface type is not compatible with the selected operating system.
 CANNOT_PERFOM_HOT_UPDATE=Cannot ${action} ${type}. Updating some of the 
properties is not supported while the interface is plugged into a running 
virtual machine. Please un-plug the interface, update the properties, and then 
plug it back.
 CANNOT_PERFOM_HOT_UPDATE_WITH_PORT_MIRRORING=Cannot ${action} ${type}. Update 
is not possible when 'Port Mirroring' is set on the interface of a running 
virtual machine.
 PORT_MIRRORING_REQUIRES_NETWORK=Cannot ${action} ${type}. 'Port Mirroring' 
setting requires a network.
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 fdfffb5..2756341 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
@@ -2185,6 +2185,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. Updating the virtual 
machine interface while the virtual machine is running is not supported for 
clusters of version ${clusterVersion}.")
     String HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED();
 
+    @DefaultStringValue("Cannot ${action} ${type}. The network interface type 
is not compatible with the selected operating system.")
+    String VM_INTERFACE_VERSION_IS_NOT_SUPPORTED();
+
     @DefaultStringValue("Cannot ${action} ${type}. Updating some of the 
properties is not supported while the interface is plugged into a running 
virtual machine. Please un-plug the interface, update the properties, and then 
plug it back.")
     String CANNOT_PERFOM_HOT_UPDATE();
 
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 faa0147..6e0af33 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
@@ -790,6 +790,7 @@
 UNLINKING_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Link state is set to 
'Down' on the virtual machine's interface, this is not supported for clusters 
of version ${clusterVersion}.
 NULL_NETWORK_IS_NOT_SUPPORTED=Cannot ${action} ${type}. There is no network on 
the virtual machine's interface, this is not supported for clusters of version 
${clusterVersion}.
 HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Updating 
the virtual machine interface while the virtual machine is running is not 
supported for clusters of version ${clusterVersion}.
+VM_INTERFACE_VERSION_IS_NOT_SUPPORTED=Cannot ${action} ${type}. The network 
interface type is not compatible with the selected operating system.
 CANNOT_PERFOM_HOT_UPDATE=Cannot ${action} ${type}. Updating some of the 
properties is not supported while the interface is plugged into a running 
virtual machine. Please un-plug the interface, update the properties, and then 
plug it back.
 CANNOT_PERFOM_HOT_UPDATE_WITH_PORT_MIRRORING=Cannot ${action} ${type}. Update 
is not possible when 'Port Mirroring' is set on the interface of a running 
virtual machine.
 PORT_MIRRORING_REQUIRES_NETWORK=Cannot ${action} ${type}. 'Port Mirroring' 
setting requires a network.
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 031d8b2..39bac25 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
@@ -811,6 +811,7 @@
 UNLINKING_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Link state is set to 
'Down' on the virtual machine's interface, this is not supported for clusters 
of version ${clusterVersion}.
 NULL_NETWORK_IS_NOT_SUPPORTED=Cannot ${action} ${type}. There is no network on 
the virtual machine's interface, this is not supported for clusters of version 
${clusterVersion}.
 HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Updating 
the virtual machine interface while the virtual machine is running is not 
supported for clusters of version ${clusterVersion}.
+VM_INTERFACE_VERSION_IS_NOT_SUPPORTED=Cannot ${action} ${type}. The network 
interface type is not compatible with the selected operating system.
 CANNOT_PERFOM_HOT_UPDATE=Cannot ${action} ${type}. Updating some of the 
properties is not supported while the interface is plugged into a running 
virtual machine. Please un-plug the interface, update the properties, and then 
plug it back.
 CANNOT_PERFOM_HOT_UPDATE_WITH_PORT_MIRRORING=Cannot ${action} ${type}. Update 
is not possible when 'Port Mirroring' is set on the interface of a running 
virtual machine.
 PORT_MIRRORING_REQUIRES_NETWORK=Cannot ${action} ${type}. 'Port Mirroring' 
setting requires a network.


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

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

Reply via email to