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

Change subject: engine: VM Device Type for Display Type
......................................................................

engine: VM Device Type for Display Type

This change added VM Device Type for Display Type in property file.
The attribute VM Device Type for each OS is present in the os info
property file.
The attribute VM Device Type in the Display Type now is the default
value if none is found in the os file.

Change-Id: I326f8aaf0de95332436499205f90336d2f4e73d7
Signed-off-by: Gustavo Pedrosa <gustavo.pedr...@eldorado.org.br>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DisplayType.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepository.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceType.java
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java
M 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
M packaging/conf/osinfo-defaults.properties
10 files changed, 106 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/77/18677/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 f8480f5..ad6f0ae 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
@@ -72,9 +72,10 @@
                 // add video device per each monitor
                 int monitors = entity.getSingleQxlPci() ? 1 : 
entity.getNumOfMonitors();
                 for (int i = 0; i<monitors; i++) {
+                    VmDeviceType vmDeviceType = 
osRepository.getVmDeviceType(entity.getOsId(), entity.getDefaultDisplayType());
                     addManagedDevice(new VmDeviceId(Guid.newGuid(), 
entity.getId()),
                             VmDeviceGeneralType.VIDEO,
-                            entity.getDefaultDisplayType().getVmDeviceType(),
+                            vmDeviceType,
                             getMemExpr(entity.getNumOfMonitors(), 
entity.getSingleQxlPci()),
                             true,
                             false,
@@ -401,10 +402,12 @@
     }
 
     private static void addVideoDevice(VmBase vm) {
+        VmDeviceType vmDeviceType = osRepository.getVmDeviceType(vm.getOsId(), 
vm.getDefaultDisplayType());
+
         addManagedDevice(
                 new VmDeviceId(Guid.newGuid(),vm.getId()),
                 VmDeviceGeneralType.VIDEO,
-                vm.getDefaultDisplayType().getVmDeviceType(),
+                vmDeviceType,
                 getMemExpr(vm.getNumOfMonitors(), vm.getSingleQxlPci()),
                 true,
                 true,
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DisplayType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DisplayType.java
index e08bea1..8d794de 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DisplayType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DisplayType.java
@@ -6,21 +6,21 @@
     vnc(VmDeviceType.CIRRUS),
     qxl(VmDeviceType.QXL);
 
-    private VmDeviceType vmDeviceType;
+    private VmDeviceType defaultVmDeviceType;
 
     public int getValue() {
         return this.ordinal();
     }
 
-    DisplayType(VmDeviceType vmDeviceType) {
-        this.vmDeviceType = vmDeviceType;
+    DisplayType(VmDeviceType defaultVmDeviceType) {
+        this.defaultVmDeviceType = defaultVmDeviceType;
     }
     public static DisplayType forValue(int value) {
         return values()[value];
     }
 
-    public VmDeviceType getVmDeviceType() {
-        return vmDeviceType;
+    public VmDeviceType getDefaultVmDeviceType() {
+        return defaultVmDeviceType;
     }
 
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepository.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepository.java
index d18c98c..72b72f0 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepository.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepository.java
@@ -3,6 +3,8 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 
+import org.ovirt.engine.core.common.businessentities.DisplayType;
+import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.compat.Version;
 
 /**
@@ -70,6 +72,14 @@
     public boolean hasSpiceSupport(int osId, Version version);
 
     /**
+     * Get device type from display type of the OS
+     * @param osId - OS id
+     * @param displayType - Display type
+     * @return
+     */
+    public VmDeviceType getVmDeviceType(int osId, DisplayType displayType);
+
+    /**
      * this is Windows OSs specific path to the sysprep file
      * @param osId
      * @param version
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
index 3a2542f..d01b0ff 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
@@ -7,6 +7,8 @@
 import java.util.prefs.BackingStoreException;
 import java.util.prefs.Preferences;
 
+import org.ovirt.engine.core.common.businessentities.DisplayType;
+import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.compat.Version;
 
 /**
@@ -288,4 +290,13 @@
     public boolean isSingleQxlDeviceEnabled(int osId) {
         return isLinux(osId);
     }
+
+    @Override
+    public VmDeviceType getVmDeviceType(int osId, DisplayType displayType) {
+        String vmDeviceTypeName = getValueByVersion(idToUnameLookup.get(osId),
+                "devices." + displayType.name() + ".vmDeviceType", null);
+        VmDeviceType vmDeviceType = VmDeviceType.getByName(vmDeviceTypeName);
+        return vmDeviceType == null ? displayType.getDefaultVmDeviceType() : 
vmDeviceType;
+    }
+
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceType.java
index db2d69e..d973360 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceType.java
@@ -14,6 +14,7 @@
     SPICEVMC("spicevmc", "23"),
     QXL("qxl"),
     CIRRUS("cirrus"),
+    VGA("vga"),
     SOUND("sound"),
     ICH6("ich6"),
     AC97("ac97"),
@@ -71,5 +72,21 @@
         }
         return VmDeviceType.ICH6;
     }
+
+    /**
+     * gets device type for a given device name
+     *
+     * @param name
+     * @return
+     */
+    public static VmDeviceType getByName(String name) {
+        for (VmDeviceType vmDeviceType : values()) {
+            if (name.equals(vmDeviceType.getName())) {
+                return vmDeviceType;
+            }
+        }
+        return null;
+    }
+
 }
 
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java
index ddc50c5..2d5a9aa 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfReader.java
@@ -298,6 +298,8 @@
 
     protected abstract void readHardwareSection(XmlNode section);
 
+    protected abstract VmDeviceType getDisplayType(DisplayType displayType);
+
     protected void readGeneralData() {
         XmlNode content = _document.SelectSingleNode("//*/Content");
         XmlNode node;
@@ -382,17 +384,22 @@
         }
 
         XmlNodeList list = content.SelectNodes("Section");
-        for (XmlNode section : list) {
-            String value = section.Attributes.get("xsi:type").getValue();
 
-            if ("ovf:OperatingSystemSection_Type".equals(value)) {
-                readOsSection(section);
-
+        if (list != null) {
+            // The Os need to be read before the hardware
+            node = getNode(list, "xsi:type", 
"ovf:OperatingSystemSection_Type");
+            if (node != null) {
+                readOsSection(node);
             }
-            else if ("ovf:VirtualHardwareSection_Type".equals(value)) {
-                readHardwareSection(section);
-            } else if ("ovf:SnapshotsSection_Type".equals(value)) {
-                readSnapshotsSection(section);
+
+            node = getNode(list, "xsi:type", 
"ovf:VirtualHardwareSection_Type");
+            if (node != null) {
+                readHardwareSection(node);
+            }
+
+            node = getNode(list, "xsi:type", "ovf:SnapshotsSection_Type");
+            if (node != null) {
+                readSnapshotsSection(node);
             }
         }
 
@@ -467,6 +474,19 @@
         }
 
         readGeneralData(content);
+    }
+
+    private XmlNode getNode(XmlNodeList nodeList, String attributeName, String 
attributeValue) {
+
+        for (XmlNode section : nodeList) {
+            String value = section.Attributes.get(attributeName).getValue();
+
+            if (value.equals(attributeValue)) {
+                return section;
+            }
+        }
+
+        return null;
     }
 
     protected void readSnapshotsSection(@SuppressWarnings("unused") XmlNode 
section) {
@@ -556,7 +576,8 @@
             if (Integer.valueOf(OvfHardware.Monitor) == resourceType) {
                 // if default display type is defined in the ovf, set the 
video device that is suitable for it
                 if (defaultDisplayType != null) {
-                    
vmDevice.setDevice(defaultDisplayType.getVmDeviceType().getName());
+                    VmDeviceType vmDeviceType = 
getDisplayType(defaultDisplayType);
+                    vmDevice.setDevice(vmDeviceType.getName());
                 }
                 else {
                     // get number of monitors from VirtualQuantity in OVF
@@ -568,7 +589,8 @@
                         if (virtualQuantity > 1) {
                             vmDevice.setDevice(VmDeviceType.QXL.getName());
                         } else {
-                            vmDevice.setDevice(VmDeviceType.CIRRUS.getName());
+                            VmDeviceType vmDeviceType = 
getDisplayType(DisplayType.vnc);
+                            vmDevice.setDevice(vmDeviceType.getName());
                         }
                     } else { // default to spice if quantity not found
                         vmDevice.setDevice(VmDeviceType.QXL.getName());
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java
index c8eba81..8418e55 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfTemplateReader.java
@@ -6,6 +6,7 @@
 
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
+import org.ovirt.engine.core.common.businessentities.DisplayType;
 import org.ovirt.engine.core.common.businessentities.UsbPolicy;
 import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
@@ -14,6 +15,7 @@
 import org.ovirt.engine.core.common.osinfo.OsRepository;
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils;
+import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.backendcompat.XmlDocument;
 import org.ovirt.engine.core.compat.backendcompat.XmlNode;
@@ -194,4 +196,9 @@
     protected String getDefaultDisplayTypeStringRepresentation() {
         return "default_display_type";
     }
+
+    @Override
+    protected VmDeviceType getDisplayType(DisplayType displayType) {
+        return osRepository.getVmDeviceType(_vmTemplate.getOsId(), 
displayType);
+    }
 }
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
index 60f5965..40f82c9 100644
--- 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfVmReader.java
@@ -11,6 +11,7 @@
 import org.ovirt.engine.core.common.businessentities.Snapshot;
 import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus;
 import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
+import org.ovirt.engine.core.common.businessentities.DisplayType;
 import org.ovirt.engine.core.common.businessentities.UsbPolicy;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
@@ -20,6 +21,7 @@
 import org.ovirt.engine.core.common.osinfo.OsRepository;
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils;
+import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.backendcompat.XmlDocument;
 import org.ovirt.engine.core.compat.backendcompat.XmlNode;
@@ -293,4 +295,10 @@
     @Override
     protected void buildNicReference() {
     }
+
+    @Override
+    protected VmDeviceType getDisplayType(DisplayType displayType) {
+        return osRepository.getVmDeviceType(_vm.getOs(), displayType);
+    }
+
 }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
index 983aa0f..b12e37f 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
@@ -29,6 +29,8 @@
 import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.businessentities.network.VnicProfile;
+import org.ovirt.engine.core.common.osinfo.OsRepository;
+import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.compat.Guid;
@@ -78,14 +80,19 @@
      */
     private void addVideoCardByDisplayType(DisplayType displayType, int 
numOfMonitors) {
         Map<String, Object> struct = new HashMap<String, Object>();
+        VmDeviceType vmDeviceType = 
getOsRepository().getVmDeviceType(vm.getOs(), vm.getDefaultDisplayType());
         // create a monitor as an unmanaged device
         struct.put(VdsProperties.Type, VmDeviceGeneralType.VIDEO.getValue());
-        struct.put(VdsProperties.Device, 
displayType.getVmDeviceType().getName());
+        struct.put(VdsProperties.Device, vmDeviceType);
         struct.put(VdsProperties.SpecParams, 
getNewMonitorSpecParams(displayType, numOfMonitors));
         struct.put(VdsProperties.DeviceId, String.valueOf(Guid.newGuid()));
         devices.add(struct);
     }
 
+    private OsRepository getOsRepository() {
+        return SimpleDependecyInjector.getInstance().get(OsRepository.class);
+    }
+
     /**
      * Add the video cards defined for the VM with the given id in the DB
      */
diff --git a/packaging/conf/osinfo-defaults.properties 
b/packaging/conf/osinfo-defaults.properties
index e56160b..d97b626 100644
--- a/packaging/conf/osinfo-defaults.properties
+++ b/packaging/conf/osinfo-defaults.properties
@@ -48,6 +48,8 @@
 os.other.devices.audio.value = ich6
 # See VmInterfaceType.java
 os.other.devices.network.value =  rtl8139, e1000, pv
+os.other.devices.vnc.vmDeviceType.value = cirrus
+os.other.devices.qxl.vmDeviceType.value = qxl
 
 os.linux.id.value = 100
 os.linux.name.value = Linux


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I326f8aaf0de95332436499205f90336d2f4e73d7
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Gustavo Frederico Temple Pedrosa <gustavo.pedr...@eldorado.org.br>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to