Omer Frenkel has uploaded a new change for review.

Change subject: core: remove vmType related logic
......................................................................

core: remove vmType related logic

remove logic that based on vmType,
add parameter to determine sound card creation.

on import, create sound device only if absent and imported from old
cluster.

Change-Id: I53d6e5bbd66c4d67ec37326b545b65f086600169
Signed-off-by: Omer Frenkel <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromSnapshotCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachUserToVmFromPoolAndRunCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java
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/action/AddVmTemplateParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmManagementParametersBase.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmOldInfoBuilder.java
13 files changed, 75 insertions(+), 52 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/63/14963/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
index ca23779..4d74d20 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
@@ -536,7 +536,8 @@
         VmDeviceUtils.copyVmDevices(getVmTemplateId(),
                 getVmId(),
                 newDiskImages,
-                _vmInterfaces);
+                _vmInterfaces,
+                getParameters().isSoundDeviceEnabled());
     }
 
     protected static boolean IsLegalClusterId(Guid clusterId, List<String> 
reasons) {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromSnapshotCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromSnapshotCommand.java
index 971127a..c262388 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromSnapshotCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromSnapshotCommand.java
@@ -228,7 +228,15 @@
     protected void copyVmDevices() {
         List<VmDevice> devices = new 
ArrayList<VmDevice>(vmFromConfiguration.getVmUnamagedDeviceList());
         devices.addAll(vmFromConfiguration.getManagedVmDeviceMap().values());
-        VmDeviceUtils.copyVmDevices(getVmIdFromSnapshot(), getVmId(), 
vmFromConfiguration, vmFromConfiguration.getStaticData(), true, devices, 
newDiskImages, _vmInterfaces);
+        VmDeviceUtils.copyVmDevices(getVmIdFromSnapshot(),
+                getVmId(),
+                vmFromConfiguration,
+                vmFromConfiguration.getStaticData(),
+                true,
+                devices,
+                newDiskImages,
+                _vmInterfaces,
+                getParameters().isSoundDeviceEnabled());
     }
 
     @Override
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
index 8194847..b3e3786 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java
@@ -138,7 +138,7 @@
                 addPermission();
                 AddVmTemplateImages();
                 List<VmNetworkInterface> vmInterfaces = addVmInterfaces();
-                VmDeviceUtils.copyVmDevices(getVmId(), getVmTemplateId(), 
newDiskImages, vmInterfaces);
+                VmDeviceUtils.copyVmDevices(getVmId(), getVmTemplateId(), 
newDiskImages, vmInterfaces, getParameters().isSoundDeviceEnabled());
                 setSucceeded(true);
                 return null;
             }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachUserToVmFromPoolAndRunCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachUserToVmFromPoolAndRunCommand.java
index cdbe10a..f1fd037 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachUserToVmFromPoolAndRunCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachUserToVmFromPoolAndRunCommand.java
@@ -22,7 +22,6 @@
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmPoolMap;
-import org.ovirt.engine.core.common.businessentities.VmType;
 import org.ovirt.engine.core.common.businessentities.permissions;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.errors.VdcBllErrors;
@@ -203,7 +202,6 @@
             setVm(getVmDAO().get(vmToAttach));
             RunVmParams runVmParams = new RunVmParams(vmToAttach);
             runVmParams.setSessionId(getParameters().getSessionId());
-            runVmParams.setUseVnc(getVm().getVmType() == VmType.Server);
             runVmParams.setParentParameters(getParameters());
             runVmParams.setEntityId(vmToAttach);
             
runVmParams.setParentCommand(VdcActionType.AttachUserToVmFromPoolAndRun);
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
index 2dd2fd3..ab80d4b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
@@ -56,8 +56,8 @@
 public class ImportVmTemplateCommand extends 
MoveOrCopyTemplateCommand<ImportVmTemplateParameters>
         implements QuotaStorageDependent {
 
-    private List<Guid> diskGuidList = new ArrayList<Guid>();
-    private List<Guid> imageGuidList = new ArrayList<Guid>();
+    private final List<Guid> diskGuidList = new ArrayList<Guid>();
+    private final List<Guid> imageGuidList = new ArrayList<Guid>();
 
     public ImportVmTemplateCommand(ImportVmTemplateParameters parameters) {
         super(parameters);
@@ -109,6 +109,7 @@
                     if (t.getId().equals(getVmTemplate().getId())) {
                         images = templates.get(t);
                         getVmTemplate().setInterfaces(t.getInterfaces());
+                        getVmTemplate().setOvfVersion(t.getOvfVersion());
                         break;
                     }
                 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java
index bb1bf98..7fc4a79 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java
@@ -12,7 +12,6 @@
 import org.ovirt.engine.core.common.businessentities.MigrationSupport;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VmStatic;
-import org.ovirt.engine.core.common.businessentities.VmType;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.validation.group.DesktopVM;
@@ -36,9 +35,7 @@
 
     @Override
     protected List<Class<?>> getValidationGroups() {
-        if (getParameters().getVmStaticData().getVmType() == VmType.Desktop) {
-            addValidationGroup(DesktopVM.class);
-        }
+        addValidationGroup(DesktopVM.class);
         return super.getValidationGroups();
     }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
index 045e4b0..8870adb 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
@@ -22,7 +22,6 @@
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VmPool;
 import org.ovirt.engine.core.common.businessentities.VmPoolMap;
-import org.ovirt.engine.core.common.businessentities.VmType;
 import org.ovirt.engine.core.common.businessentities.tags;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.NGuid;
@@ -223,7 +222,6 @@
         VmHandler.updateNetworkInterfacesFromDb(vm);
 
         RunVmParams runVmParams = new RunVmParams(vmId);
-        runVmParams.setUseVnc(vm.getVmOs().isLinux() || vm.getVmType() == 
VmType.Server);
         VdsSelector vdsSelector =
                 new VdsSelector(vm,
                         runVmParams.getDestinationVdsId() != null ?
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java
index 05c645a..8c0551e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java
@@ -8,9 +8,8 @@
 import org.ovirt.engine.core.common.action.VdcReturnValueBase;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
-import org.ovirt.engine.core.common.businessentities.VmPoolMap;
-import org.ovirt.engine.core.common.businessentities.VmType;
 import org.ovirt.engine.core.common.businessentities.VmPool;
+import org.ovirt.engine.core.common.businessentities.VmPoolMap;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.compat.Guid;
@@ -130,7 +129,6 @@
         log.infoFormat("Running Vm {0} as stateless", vmToRunAsStateless);
         boolean prestartingVmSucceeded = false;
         RunVmParams runVmParams = new RunVmParams(vmToRunAsStateless.getId());
-        runVmParams.setUseVnc(vmToRunAsStateless.getVmType() == VmType.Server);
         runVmParams.setEntityId(vmToRunAsStateless);
         runVmParams.setRunAsStateless(true);
         VdcReturnValueBase vdcReturnValue = 
Backend.getInstance().runInternalAction(VdcActionType.RunVm,
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 2c4eda3..79dc850 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
@@ -35,7 +35,7 @@
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dao.VmDeviceDAO;
 import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties;
-import org.ovirt.engine.core.vdsbroker.vdsbroker.VmInfoBuilderBase;
+import org.ovirt.engine.core.vdsbroker.vdsbroker.VmInfoBuilder;
 
 public class VmDeviceUtils {
     private static VmDeviceDAO dao = DbFacade.getInstance().getVmDeviceDao();
@@ -81,7 +81,7 @@
             updateUSBSlots(oldVmBase, entity);
             updateMemoryBalloon(oldVmBase, entity, params.isBalloonEnabled());
 
-            updateAudioDevice(oldVm, entity);
+            updateAudioDevice(oldVm, params);
             updateSmartcardDevice(oldVm, entity);
         }
     }
@@ -126,20 +126,24 @@
      * @param oldVm
      * @param newVmBase
      */
-    private static void updateAudioDevice(VM oldVm, VmBase newVmBase) {
-        // for desktop, if the os type has changed, recreate Audio devices
-        if (newVmBase.getVmType() == VmType.Desktop && oldVm.getOs() != 
newVmBase.getOs()) {
-            Guid vmId = oldVm.getId();
-            // remove any old sound device
+    private static void updateAudioDevice(VM oldVm, VmManagementParametersBase 
params) {
+        VmBase newVmBase = params.getVmStaticData();
+        Guid vmId = oldVm.getId();
+        boolean osChanged = oldVm.getOs() != newVmBase.getOs();
+
+        // if no sound card or if the os type has changed remove current Audio 
devices
+        if (!params.isSoundDeviceEnabled() || osChanged) {
             List<VmDevice> list =
                     DbFacade.getInstance()
                             .getVmDeviceDao()
                             .getVmDeviceByVmIdAndType(vmId, 
VmDeviceType.SOUND.getName());
             removeNumberOfDevices(list, list.size());
+        }
 
-            // create new device
+        // now there are no audio devices, create new one
+        if (params.isSoundDeviceEnabled() && osChanged) {
             String soundDevice =
-                    VmInfoBuilderBase.getSoundDevice(newVmBase, 
oldVm.getVdsGroupCompatibilityVersion());
+                    VmInfoBuilder.getSoundDevice(newVmBase, 
oldVm.getVdsGroupCompatibilityVersion());
             addManagedDevice(new VmDeviceId(Guid.NewGuid(), vmId),
                     VmDeviceType.SOUND,
                     VmDeviceType.getSoundDeviceType(soundDevice),
@@ -161,7 +165,7 @@
     /**
      * Copy related data from the given VM/VmBase/VmDevice list to the 
destination VM/VmTemplate.
      */
-    public static void copyVmDevices(Guid srcId, Guid dstId, VM vm, VmBase 
vmBase, boolean isVm, List<VmDevice> devicesDataToUse, List<DiskImage> disks, 
List<VmNetworkInterface> ifaces) {
+    public static void copyVmDevices(Guid srcId, Guid dstId, VM vm, VmBase 
vmBase, boolean isVm, List<VmDevice> devicesDataToUse, List<DiskImage> disks, 
List<VmNetworkInterface> ifaces, boolean soundDeviceEnabled) {
         Guid id;
         int diskCount = 0;
         int ifaceCount = 0;
@@ -236,7 +240,7 @@
             updateBootOrderInVmDeviceAndStoreToDB(vmBase);
 
             // create sound card for a desktop VM if not exists
-            if (vmBase.getVmType() == VmType.Desktop) {
+            if (soundDeviceEnabled) {
                 List<VmDevice> list = 
DbFacade.getInstance().getVmDeviceDao().getVmDeviceByVmIdAndType(vmBase.getId(),
 VmDeviceType.SOUND.getName());
                 if (list.isEmpty()) {
                     addSoundCard(vm.getStaticData(), 
vm.getVdsGroupCompatibilityVersion());
@@ -256,7 +260,7 @@
     }
 
     private static void addSoundCard(VmBase vmBase, Version 
vdsGroupCompatibilityVersion) {
-        String soundDevice = VmInfoBuilderBase.getSoundDevice(vmBase, 
vdsGroupCompatibilityVersion);
+        String soundDevice = VmInfoBuilder.getSoundDevice(vmBase, 
vdsGroupCompatibilityVersion);
         addManagedDevice(new VmDeviceId(Guid.NewGuid(), vmBase.getId()),
                 VmDeviceType.SOUND,
                 VmDeviceType.getSoundDeviceType(soundDevice),
@@ -273,7 +277,7 @@
      * @param disks
      *            The disks which were saved for the destination VM.
      */
-    public static void copyVmDevices(Guid srcId, Guid dstId, List<DiskImage> 
disks, List<VmNetworkInterface> ifaces) {
+    public static void copyVmDevices(Guid srcId, Guid dstId, List<DiskImage> 
disks, List<VmNetworkInterface> ifaces, boolean soundDeviceEnabled) {
         VM vm = DbFacade.getInstance().getVmDao().get(dstId);
         VmBase vmBase = (vm != null) ? vm.getStaticData() : null;
         boolean isVm = (vmBase != null);
@@ -281,7 +285,7 @@
             vmBase = DbFacade.getInstance().getVmTemplateDao().get(dstId);
         }
         List<VmDevice> devices = dao.getVmDeviceByVmId(srcId);
-        copyVmDevices(srcId, dstId, vm, vmBase, isVm, devices, disks, ifaces);
+        copyVmDevices(srcId, dstId, vm, vmBase, isVm, devices, disks, ifaces, 
soundDeviceEnabled);
     }
 
     private static void addVideoDevice(VM vm) {
@@ -681,7 +685,10 @@
         if (!hasCD) { // add an empty CD
             addEmptyCD(entity.getId());
         }
-        if (!hasSoundCard && entity.getVmType() == VmType.Desktop) {
+
+        // add sound card for desktops imported from old versions only, since 
devices didnt exist
+        Version ovfVer = new Version(entity.getOvfVersion());
+        if (!hasSoundCard && VmDeviceCommonUtils.isOldClusterVersion(ovfVer) 
&& entity.getVmType() == VmType.Desktop) {
             addSoundCard(entity);
         }
         for (VmDevice vmDevice : entity.getUnmanagedDeviceList()) {
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmTemplateParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmTemplateParameters.java
index 8c7628e..406bed0 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmTemplateParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddVmTemplateParameters.java
@@ -35,6 +35,7 @@
     private String _description;
 
     private boolean publicUse = false;
+    boolean soundDeviceEnabled;
 
     public AddVmTemplateParameters(VmStatic masterVm, String name, String 
description) {
         _masterVm = masterVm;
@@ -102,4 +103,12 @@
     public void setDiskInfoDestinationMap(HashMap<Guid, DiskImage> 
diskInfoDestinationMap) {
         this.diskInfoDestinationMap = diskInfoDestinationMap;
     }
+
+    public boolean isSoundDeviceEnabled() {
+        return soundDeviceEnabled;
+    }
+
+    public void setSoundDeviceEnabled(boolean soundDeviceEnabled) {
+        this.soundDeviceEnabled = soundDeviceEnabled;
+    }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmManagementParametersBase.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmManagementParametersBase.java
index e496395..e083027 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmManagementParametersBase.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmManagementParametersBase.java
@@ -24,6 +24,7 @@
     private boolean clearPayload;
     private boolean balloonEnabled = true;
     private VM vm = null;
+    private boolean soundDeviceEnabled;
 
     public VmManagementParametersBase() {
     }
@@ -122,4 +123,12 @@
     public void setBalloonEnabled(boolean isBallonEnabled) {
         this.balloonEnabled = isBallonEnabled;
     }
+
+    public boolean isSoundDeviceEnabled() {
+        return soundDeviceEnabled;
+    }
+
+    public void setSoundDeviceEnabled(boolean soundDeviceEnabled) {
+        this.soundDeviceEnabled = soundDeviceEnabled;
+    }
 }
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 102d17b..f219d2b 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
@@ -22,7 +22,6 @@
 import org.ovirt.engine.core.common.businessentities.VmDevice;
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.businessentities.VmPayload;
-import org.ovirt.engine.core.common.businessentities.VmType;
 import org.ovirt.engine.core.common.businessentities.VolumeFormat;
 import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
@@ -338,22 +337,20 @@
 
     @Override
     protected void buildVmSoundDevices() {
-        if (vm.getVmType() == VmType.Desktop) {
-            // get vm device for Sound device from DB
-            List<VmDevice> vmDevices =
-                    DbFacade.getInstance()
-                            .getVmDeviceDao()
-                            .getVmDeviceByVmIdAndType(vm.getId(),
-                                    VmDeviceType.SOUND.getName());
-            for (VmDevice vmDevice : vmDevices) {
-                Map struct = new HashMap();
-                struct.put(VdsProperties.Type, vmDevice.getType());
-                struct.put(VdsProperties.Device, vmDevice.getDevice());
-                struct.put(VdsProperties.SpecParams, vmDevice.getSpecParams());
-                struct.put(VdsProperties.DeviceId, 
String.valueOf(vmDevice.getId().getDeviceId()));
-                addAddress(vmDevice, struct);
-                devices.add(struct);
-            }
+        // get Sound device for vm from DB
+        List<VmDevice> vmDevices =
+                DbFacade.getInstance()
+                        .getVmDeviceDao()
+                        .getVmDeviceByVmIdAndType(vm.getId(),
+                                VmDeviceType.SOUND.getName());
+        for (VmDevice vmDevice : vmDevices) {
+            Map struct = new HashMap();
+            struct.put(VdsProperties.Type, vmDevice.getType());
+            struct.put(VdsProperties.Device, vmDevice.getDevice());
+            struct.put(VdsProperties.SpecParams, vmDevice.getSpecParams());
+            struct.put(VdsProperties.DeviceId, 
String.valueOf(vmDevice.getId().getDeviceId()));
+            addAddress(vmDevice, struct);
+            devices.add(struct);
         }
     }
 
@@ -660,9 +657,9 @@
         Set<Entry<String, Object>> values = specParams.entrySet();
         for (Entry<String, Object> currEntry : values) {
             if (currEntry.getValue() instanceof String) {
-                struct.put(currEntry.getKey(), (String) currEntry.getValue());
+                struct.put(currEntry.getKey(), currEntry.getValue());
             } else if (currEntry.getValue() instanceof Map) {
-                struct.put(currEntry.getKey(), (Map) currEntry.getValue());
+                struct.put(currEntry.getKey(), currEntry.getValue());
             }
         }
     }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmOldInfoBuilder.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmOldInfoBuilder.java
index ada087c..7a4aee6 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmOldInfoBuilder.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmOldInfoBuilder.java
@@ -13,7 +13,6 @@
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
-import org.ovirt.engine.core.common.businessentities.VmType;
 import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType;
 import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
@@ -176,7 +175,8 @@
 
     @Override
     protected void buildVmSoundDevices() {
-        if (vm.getVmType() == VmType.Desktop) {
+        List<VmDevice> vmSoundDevices = 
DbFacade.getInstance().getVmDeviceDao().getVmDeviceByVmIdAndType(vm.getId(), 
VmDeviceType.SOUND.getName());
+        if (!vmSoundDevices.isEmpty()) {
             createInfo.put(VdsProperties.soundDevice, 
getSoundDevice(vm.getStaticData(), vm.getVdsGroupCompatibilityVersion()));
         }
     }


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

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

Reply via email to