Shmuel Leib Melamud has uploaded a new change for review.

Change subject: core: Save graphics devices when VM is running
......................................................................

core: Save graphics devices when VM is running

Added support of saving of VM's graphics devices for the next run if
VM properties are edited when it is running. Notification to user is
displayed as well.

Added @EditableDeviceOnVmStatusField annotation to
VmManagementParametersBase.graphicsDevices field and extended the
@EditableDeviceOnVmStatusField annotation to support fields of VmDevice
and Map type in addition to Boolean. Also added missing functionality in
ProcessDownVmCommand and InstanceTypeManager to restore graphics
devices.

Change-Id: I9cce664ae9fafe2713c014a95b4569b8c7e45f8e
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1210382
Signed-off-by: Shmuel Melamud <smela...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmChangedFieldsForNextRunQuery.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ProcessDownVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.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/VmManagementParametersBase.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceTypeSpec.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceUpdate.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/instancetypes/InstanceTypeManager.java
8 files changed, 303 insertions(+), 78 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/37/40037/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmChangedFieldsForNextRunQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmChangedFieldsForNextRunQuery.java
index 02f456e..ea7c15d 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmChangedFieldsForNextRunQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmChangedFieldsForNextRunQuery.java
@@ -1,13 +1,12 @@
 package org.ovirt.engine.core.bll;
 
-import 
org.ovirt.engine.core.common.businessentities.EditableDeviceOnVmStatusField;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmStatic;
 import 
org.ovirt.engine.core.common.queries.GetVmChangedFieldsForNextRunParameters;
-import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
+import org.ovirt.engine.core.common.utils.VmDeviceUpdate;
 import org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils;
 
 import java.util.ArrayList;
@@ -42,12 +41,12 @@
 
         List<String> result = new 
ArrayList<>(VmHandler.getChangedFieldsForStatus(srcStatic, dstStatic, 
VMStatus.Up));
 
-        for (Pair<EditableDeviceOnVmStatusField, Boolean> device :
+        for (VmDeviceUpdate device :
                 VmHandler.getVmDevicesFieldsToUpdateOnNextRun(srcVm.getId(), 
VMStatus.Up, getParameters().getUpdateVmParameters())) {
-            if (device.getFirst().type() != VmDeviceType.UNKNOWN) {
-                result.add(device.getFirst().type().getName());
+            if (device.getType() != VmDeviceType.UNKNOWN) {
+                result.add(device.getType().getName());
             } else {
-                result.add(device.getFirst().generalType().name());
+                result.add(device.getGeneralType().name());
             }
         }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ProcessDownVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ProcessDownVmCommand.java
index 5c92bb2..89de6e5 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ProcessDownVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ProcessDownVmCommand.java
@@ -13,6 +13,8 @@
 import org.ovirt.engine.core.common.action.VmManagementParametersBase;
 import org.ovirt.engine.core.common.action.VmOperationParameterBase;
 import org.ovirt.engine.core.common.action.VmPoolSimpleUserParameters;
+import org.ovirt.engine.core.common.businessentities.GraphicsDevice;
+import org.ovirt.engine.core.common.businessentities.GraphicsType;
 import org.ovirt.engine.core.common.businessentities.Snapshot;
 import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
@@ -113,9 +115,7 @@
     }
 
     /**
-     * remove VMs unmanaged devices that are created during run-once or 
stateless run.
-     *
-     * @param vmId
+     * Remove VM's unmanaged devices that are created during run-once or 
stateless run.
      */
     private void removeStatelessVmUnmanagedDevices() {
         if (getVm().isStateless() || isRunOnce()) {
@@ -156,8 +156,7 @@
     }
 
     /**
-     * Update vm configuration with NEXT_RUN configuration, if exists
-     * @param vmId
+     * Update VM configuration with NEXT_RUN configuration, if exists.
      */
     private void applyNextRunConfiguration() {
         // Remove snpashot first, in case other update is in progress, it will 
block this one with exclusive lock
@@ -185,6 +184,9 @@
         updateVmParams.setBalloonEnabled(false);
         updateVmParams.setVirtioScsiEnabled(false);
         updateVmParams.setClearPayload(true);
+        for (GraphicsType graphicsType : GraphicsType.values()) {
+            updateVmParams.getGraphicsDevices().put(graphicsType, null);
+        }
 
         for (VmDevice device : getVm().getManagedVmDeviceMap().values()) {
             switch (device.getType()) {
@@ -210,6 +212,10 @@
                 case CONSOLE:
                     updateVmParams.setConsoleEnabled(true);
                     break;
+                case GRAPHICS:
+                    
updateVmParams.getGraphicsDevices().put(GraphicsType.fromString(device.getDevice()),
+                            new GraphicsDevice(device));
+                    break;
                 default:
             }
         }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
index 4125113..69dc3f4 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
@@ -47,6 +47,8 @@
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmBase;
+import org.ovirt.engine.core.common.businessentities.VmDevice;
+import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
 import org.ovirt.engine.core.common.businessentities.VmDynamic;
 import org.ovirt.engine.core.common.businessentities.VmInit;
 import org.ovirt.engine.core.common.businessentities.VmNumaNode;
@@ -68,6 +70,8 @@
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
+import org.ovirt.engine.core.common.utils.VmDeviceTypeSpec;
+import org.ovirt.engine.core.common.utils.VmDeviceUpdate;
 import 
org.ovirt.engine.core.common.vdscommands.SetVmStatusVDSCommandParameters;
 import 
org.ovirt.engine.core.common.vdscommands.UpdateVmDynamicDataVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
@@ -104,7 +108,7 @@
      * Initialize static list containers, for identity and permission check. 
The initialization should be executed
      * before calling ObjectIdentityChecker.
      *
-     * @see Backend#InitHandlers
+     * @see Backend#initHandlers
      */
     public static void init() {
         Class<?>[] inspectedClassNames = new Class<?>[] {
@@ -819,9 +823,9 @@
         return getVmDevicesFieldsToUpdateOnNextRun(vmId, vmStatus, 
objectWithEditableDeviceFields).isEmpty();
     }
 
-    public static List<Pair<EditableDeviceOnVmStatusField, Boolean>> 
getVmDevicesFieldsToUpdateOnNextRun(
+    public static List<VmDeviceUpdate> getVmDevicesFieldsToUpdateOnNextRun(
             Guid vmId, VMStatus vmStatus, Object 
objectWithEditableDeviceFields) {
-        List<Pair<EditableDeviceOnVmStatusField, Boolean>> fieldList = new 
ArrayList<>();
+        List<VmDeviceUpdate> fieldList = new ArrayList<>();
 
         if (objectWithEditableDeviceFields == null) {
             return fieldList;
@@ -835,35 +839,96 @@
             Field field = pair.getSecond();
             field.setAccessible(true);
 
-            Boolean isEnabled = null;
-            try {
-                isEnabled = (Boolean) 
field.get(objectWithEditableDeviceFields);
-            } catch (IllegalAccessException | ClassCastException e) {
-                log.warn("VmHandler:: isUpdateValidForVmDevices: Reflection 
error");
-                log.debug("Original exception was:", e);
-            }
-
-            // if device type is set to unknown, search by general type only
-            // because some devices has more than one type, like sound can be 
ac97/ich6
-            String device = null;
-            if (annotation.type() != VmDeviceType.UNKNOWN) {
-                device = annotation.type().getName();
-            }
-
-            if (isEnabled == null ||
-                    !VmDeviceUtils.vmDeviceChanged(vmId, 
annotation.generalType(),
-                            device, isEnabled)) {
+            if (VmHandler.isUpdateValidForVmDevice(field.getName(), vmStatus)) 
{
+                // field may be updated on the current run, so not including 
for the next run
                 continue;
             }
 
-            if (!VmHandler.isUpdateValidForVmDevice(field.getName(), 
vmStatus)) {
-                fieldList.add(new Pair<>(annotation, isEnabled));
+            try {
+                Object value = field.get(objectWithEditableDeviceFields);
+                if (value instanceof Boolean) {
+                    addDeviceUpdateOnNextRun(vmId, annotation, null, value, 
fieldList);
+                } else if (value instanceof Map) {
+                    Map<?, ?> map = (Map<?, ?>) value;
+                    for (Map.Entry<?, ?> entry : map.entrySet()) {
+                        boolean success = addDeviceUpdateOnNextRun(vmId, 
annotation,
+                                entry.getKey(), entry.getValue(), fieldList);
+                        if (!success)
+                            break;
+                    }
+                } else {
+                    log.warn("VmHandler::getVmDevicesFieldsToUpdateOnNextRun: 
Unsupported field type: " +
+                            value.getClass().getName());
+                }
+            } catch (IllegalAccessException | ClassCastException e) {
+                log.warn("VmHandler::getVmDevicesFieldsToUpdateOnNextRun: 
Reflection error");
+                log.debug("Original exception was:", e);
             }
+
+
         }
 
         return fieldList;
     }
 
+    private static boolean addDeviceUpdateOnNextRun(Guid vmId, 
EditableDeviceOnVmStatusField annotation,
+                                                Object key, Object value, 
List<VmDeviceUpdate> updates) {
+        VmDeviceGeneralType generalType = annotation.generalType();
+        VmDeviceType type = annotation.type();
+
+        if (key != null) {
+            VmDeviceGeneralType keyGeneralType = VmDeviceGeneralType.UNKNOWN;
+            VmDeviceType keyType = VmDeviceType.UNKNOWN;
+
+            if (key instanceof VmDeviceGeneralType) {
+                keyGeneralType = (VmDeviceGeneralType) key;
+            } else if (key instanceof VmDeviceType) {
+                keyType = (VmDeviceType) key;
+            } else if (key instanceof GraphicsType) {
+                keyType = ((GraphicsType) key).getCorrespondingDeviceType();
+            } else if (key instanceof VmDeviceTypeSpec) {
+                final VmDeviceTypeSpec spec = (VmDeviceTypeSpec) key;
+                keyGeneralType = spec.getGeneralType();
+                keyType = spec.getType();
+            } else {
+                log.warn("VmHandler::addDeviceUpdateOnNextRun: Unsupported map 
key type: " +
+                        key.getClass().getName());
+                return false;
+            }
+
+            if (keyGeneralType != VmDeviceGeneralType.UNKNOWN) {
+                generalType = keyGeneralType;
+            }
+            if (keyType != VmDeviceType.UNKNOWN) {
+                type = keyType;
+            }
+        }
+
+        // if device type is set to unknown, search by general type only
+        // because some devices have more than one type, like sound can be 
ac97/ich6
+        String typeName = type != VmDeviceType.UNKNOWN ? type.getName() : null;
+
+        if (value == null) {
+            if (VmDeviceUtils.vmDeviceChanged(vmId, generalType, typeName, 
false)) {
+                updates.add(new VmDeviceUpdate(generalType, type, 
annotation.isReadOnly(), false));
+            }
+        } else if (value instanceof Boolean) {
+            if (VmDeviceUtils.vmDeviceChanged(vmId, generalType, typeName, 
(Boolean) value)) {
+                updates.add(new VmDeviceUpdate(annotation, (Boolean) value));
+            }
+        } else if (value instanceof VmDevice) {
+            if (VmDeviceUtils.vmDeviceChanged(vmId, generalType, typeName, 
true)) {
+                updates.add(new VmDeviceUpdate(generalType, type, 
annotation.isReadOnly(), (VmDevice) value));
+            }
+        } else {
+            log.warn("VmHandler::addDeviceUpdateOnNextRun: Unsupported value 
type: " +
+                    value.getClass().getName());
+            return false;
+        }
+
+        return true;
+    }
+
     public static boolean isCpuSupported(int osId, Version version, String 
cpuName, ArrayList<String> canDoActionMessages) {
         if (osRepository.isCpuSupported(
                 osId,
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 afb107f..e75a409 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
@@ -7,7 +7,6 @@
 import org.ovirt.engine.core.bll.validator.VirtIoRngValidator;
 import org.ovirt.engine.core.common.action.VmManagementParametersBase;
 import org.ovirt.engine.core.common.businessentities.DisplayType;
-import 
org.ovirt.engine.core.common.businessentities.EditableDeviceOnVmStatusField;
 import org.ovirt.engine.core.common.businessentities.GraphicsType;
 import org.ovirt.engine.core.common.businessentities.UsbPolicy;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
@@ -26,10 +25,10 @@
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.osinfo.OsRepository;
-import org.ovirt.engine.core.common.utils.Pair;
 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.common.utils.VmDeviceUpdate;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
@@ -210,8 +209,8 @@
      *
      * @param oldVm
      * @param newVmBase
-     * @param cluster compatibility version
-     * @param sound device enabled - if null, keep old state
+     * @param compatibilityVersion compatibility version
+     * @param isSoundDeviceEnabled device enabled - if null, keep old state
      */
     public static void updateAudioDevice(VmBase oldVm, VmBase newVmBase, 
Version compatibilityVersion, Boolean isSoundDeviceEnabled) {
         boolean removeDevice = false;
@@ -1021,7 +1020,7 @@
         VmDeviceUtils.addManagedDevice(new VmDeviceId(Guid.newGuid(), dstId),
                 VmDeviceGeneralType.DISK,
                 VmDeviceType.CDROM,
-                Collections.<String, Object> singletonMap(VdsProperties.Path, 
""),
+                Collections.<String, Object>singletonMap(VdsProperties.Path, 
""),
                 true,
                 true,
                 null);
@@ -1127,15 +1126,16 @@
 
     /**
      * Determines whether a VM device change has been request by the user.
-     * @param deviceType VmDeviceGeneralType.
-     * @param device VmDeviceType name.
+     * @param deviceGeneralType VmDeviceGeneralType.
+     * @param deviceTypeName VmDeviceType name.
      * @param deviceEnabled indicates whether the user asked to enable the 
device.
      * @return true if a change has been requested; otherwise, false
      */
-    public static boolean vmDeviceChanged(Guid vmId, VmDeviceGeneralType 
deviceType, String device, boolean deviceEnabled) {
-        List<VmDevice> vmDevices = device != null ?
-                dao.getVmDeviceByVmIdTypeAndDevice(vmId, deviceType, device):
-                dao.getVmDeviceByVmIdAndType(vmId, deviceType);
+    public static boolean vmDeviceChanged(Guid vmId, VmDeviceGeneralType 
deviceGeneralType, String deviceTypeName,
+                                          boolean deviceEnabled) {
+        List<VmDevice> vmDevices = deviceTypeName != null ?
+                dao.getVmDeviceByVmIdTypeAndDevice(vmId, deviceGeneralType, 
deviceTypeName):
+                dao.getVmDeviceByVmIdAndType(vmId, deviceGeneralType);
 
         return deviceEnabled == vmDevices.isEmpty();
     }
@@ -1156,34 +1156,41 @@
         VmDeviceUtils.setVmDevices(vm.getStaticData());
         Map<Guid, VmDevice> vmManagedDeviceMap = vm.getManagedVmDeviceMap();
 
-        List<Pair<EditableDeviceOnVmStatusField, Boolean>> fieldList =
+        List<VmDeviceUpdate> fieldList =
                 VmHandler.getVmDevicesFieldsToUpdateOnNextRun(vm.getId(), 
vm.getStatus(), objectWithEditableDeviceFields);
 
         // Add the enabled devices and remove the disabled ones
-        for (Pair<EditableDeviceOnVmStatusField, Boolean> pair : fieldList) {
-            final EditableDeviceOnVmStatusField field = pair.getFirst();
-            Boolean isEnabled = pair.getSecond();
-
-            if (Boolean.TRUE.equals(isEnabled)) {
-                VmDevice device =
-                        new VmDevice(new VmDeviceId(Guid.newGuid(), 
vm.getId()),
-                                field.generalType(),
-                                field.type().getName(),
-                                "",
-                                0,
-                                new HashMap<String, Object>(),
-                                true,
-                                true,
-                                field.isReadOnly(),
-                                "",
-                                null,
-                                null,
-                                null);
+        for (VmDeviceUpdate update : fieldList) {
+            if (update.isEnable()) {
+                VmDevice device;
+                if (update.getDevice() == null) {
+                    device = new VmDevice(new VmDeviceId(Guid.newGuid(), 
vm.getId()),
+                                    update.getGeneralType(),
+                                    update.getType().getName(),
+                                    "",
+                                    0,
+                                    new HashMap<String, Object>(),
+                                    true,
+                                    true,
+                                    update.isReadOnly(),
+                                    "",
+                                    null,
+                                    null,
+                                    null);
+                } else {
+                    device = update.getDevice();
+                    if (device.getVmId() == null) {
+                        device.setVmId(vm.getId());
+                    }
+                    if (device.getDeviceId() == null) {
+                        device.setDeviceId(Guid.newGuid());
+                    }
+                }
 
                 vmManagedDeviceMap.put(device.getDeviceId(), device);
-            }
-            else {
-                
vmManagedDeviceMap.remove(getVmDeviceIdByName(vmManagedDeviceMap, 
field.generalType(), field.type().getName()));
+            } else {
+                
vmManagedDeviceMap.remove(getVmDeviceIdByName(vmManagedDeviceMap, 
update.getGeneralType(),
+                        update.getType().getName()));
             }
         }
 
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 b7a85c1..b457b43 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
@@ -22,9 +22,9 @@
     private static final long serialVersionUID = -7695630335738521510L;
 
     @Valid
-    private VmStatic _vmStatic;
+    private VmStatic vmStatic;
     private boolean makeCreatorExplicitOwner;
-    private Guid privateStorageDomainId;
+    private Guid storageDomainId;
     private HashMap<Guid, DiskImage> diskInfoDestinationMap;
     private VmPayload payload;
     private boolean clearPayload;
@@ -79,6 +79,7 @@
      * null for removing the device. If the map doesn't contain entry for 
graphics type, VM's graphics card
      * of this type is not modified.
      */
+    @EditableDeviceOnVmStatusField(generalType = VmDeviceGeneralType.GRAPHICS, 
type = VmDeviceType.UNKNOWN)
     private Map<GraphicsType, GraphicsDevice> graphicsDevices;
 
     public VmManagementParametersBase() {
@@ -87,12 +88,12 @@
 
     public VmManagementParametersBase(VmStatic vmStatic) {
         super(vmStatic.getId());
-        _vmStatic = vmStatic;
+        this.vmStatic = vmStatic;
         init();
     }
 
     private void init() {
-        privateStorageDomainId = Guid.Empty;
+        storageDomainId = Guid.Empty;
         consoleEnabled = Boolean.FALSE;
         graphicsDevices = new HashMap<GraphicsType, GraphicsDevice>();
     }
@@ -102,19 +103,19 @@
     }
 
     public VmStatic getVmStaticData() {
-        return _vmStatic;
+        return vmStatic;
     }
 
     public void setVmStaticData(VmStatic value) {
-        _vmStatic = value;
+        vmStatic = value;
     }
 
     public Guid getStorageDomainId() {
-        return privateStorageDomainId;
+        return storageDomainId;
     }
 
     public void setStorageDomainId(Guid value) {
-        privateStorageDomainId = value;
+        storageDomainId = value;
     }
 
     private boolean privateDontAttachToDefaultTag;
@@ -130,7 +131,7 @@
     public VM getVm() {
         if (vm == null) {
             vm = new VM();
-            vm.setStaticData(_vmStatic);
+            vm.setStaticData(vmStatic);
         }
         return vm;
     }
@@ -138,7 +139,7 @@
     public void setVm(VM value) {
         // to make the getVm() use the new value
         vm = null;
-        _vmStatic = value.getStaticData();
+        vmStatic = value.getStaticData();
     }
 
     public void setMakeCreatorExplicitOwner(boolean makeCreatorExplicitOwner) {
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceTypeSpec.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceTypeSpec.java
new file mode 100644
index 0000000..9648a5a
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceTypeSpec.java
@@ -0,0 +1,54 @@
+package org.ovirt.engine.core.common.utils;
+
+import 
org.ovirt.engine.core.common.businessentities.EditableDeviceOnVmStatusField;
+import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
+
+public class VmDeviceTypeSpec {
+
+    private VmDeviceGeneralType generalType;
+    private VmDeviceType type;
+    private boolean readOnly;
+
+    public VmDeviceTypeSpec() {
+        this(VmDeviceGeneralType.UNKNOWN, VmDeviceType.UNKNOWN, false);
+    }
+
+    public VmDeviceTypeSpec(VmDeviceGeneralType generalType, VmDeviceType 
type) {
+        this(generalType, type, false);
+    }
+
+    public VmDeviceTypeSpec(VmDeviceGeneralType generalType, VmDeviceType 
type, boolean readOnly) {
+        this.generalType = generalType;
+        this.type = type;
+        this.readOnly = readOnly;
+    }
+
+    public VmDeviceTypeSpec(EditableDeviceOnVmStatusField field) {
+        this(field.generalType(), field.type(), field.isReadOnly());
+    }
+
+    public VmDeviceGeneralType getGeneralType() {
+        return generalType;
+    }
+
+    public void setGeneralType(VmDeviceGeneralType generalType) {
+        this.generalType = generalType;
+    }
+
+    public VmDeviceType getType() {
+        return type;
+    }
+
+    public void setType(VmDeviceType type) {
+        this.type = type;
+    }
+
+    public boolean isReadOnly() {
+        return readOnly;
+    }
+
+    public void setReadOnly(boolean readOnly) {
+        this.readOnly = readOnly;
+    }
+
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceUpdate.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceUpdate.java
new file mode 100644
index 0000000..825e466
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceUpdate.java
@@ -0,0 +1,84 @@
+package org.ovirt.engine.core.common.utils;
+
+import 
org.ovirt.engine.core.common.businessentities.EditableDeviceOnVmStatusField;
+import org.ovirt.engine.core.common.businessentities.VmDevice;
+import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
+
+public class VmDeviceUpdate {
+
+    private VmDeviceTypeSpec typeSpec;
+    private boolean enable;
+    private VmDevice device = null;
+
+    public VmDeviceUpdate() {
+        typeSpec = new VmDeviceTypeSpec();
+    }
+
+    public VmDeviceUpdate(EditableDeviceOnVmStatusField field, boolean enable) 
{
+        typeSpec = new VmDeviceTypeSpec(field);
+        setEnable(enable);
+    }
+
+    public VmDeviceUpdate(VmDeviceGeneralType generalType, VmDeviceType type, 
boolean enable) {
+        typeSpec = new VmDeviceTypeSpec(generalType, type);
+        setEnable(enable);
+    }
+
+    public VmDeviceUpdate(VmDeviceGeneralType generalType, VmDeviceType type, 
boolean readOnly, boolean enable) {
+        typeSpec = new VmDeviceTypeSpec(generalType, type, readOnly);
+        setEnable(enable);
+    }
+
+    public VmDeviceUpdate(VmDeviceGeneralType generalType, VmDeviceType type, 
VmDevice device) {
+        typeSpec = new VmDeviceTypeSpec(generalType, type);
+        setEnable(device != null);
+        setDevice(device);
+    }
+
+    public VmDeviceUpdate(VmDeviceGeneralType generalType, VmDeviceType type, 
boolean readOnly, VmDevice device) {
+        typeSpec = new VmDeviceTypeSpec(generalType, type, readOnly);
+        setEnable(device != null);
+        setDevice(device);
+    }
+
+    public VmDeviceGeneralType getGeneralType() {
+        return typeSpec.getGeneralType();
+    }
+
+    public void setType(VmDeviceType type) {
+        typeSpec.setType(type);
+    }
+
+    public void setGeneralType(VmDeviceGeneralType generalType) {
+        typeSpec.setGeneralType(generalType);
+    }
+
+    public VmDeviceType getType() {
+        return typeSpec.getType();
+    }
+
+    public boolean isReadOnly() {
+        return typeSpec.isReadOnly();
+    }
+
+    public void setReadOnly(boolean readOnly) {
+        typeSpec.setReadOnly(readOnly);
+    }
+
+    public boolean isEnable() {
+        return enable;
+    }
+
+    public void setEnable(boolean enable) {
+        this.enable = enable;
+    }
+
+    public VmDevice getDevice() {
+        return device;
+    }
+
+    public void setDevice(VmDevice device) {
+        this.device = device;
+    }
+
+}
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/instancetypes/InstanceTypeManager.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/instancetypes/InstanceTypeManager.java
index 18a562e..3ed8392 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/instancetypes/InstanceTypeManager.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/instancetypes/InstanceTypeManager.java
@@ -330,6 +330,15 @@
             deactivate();
             
getModel().getIsSoundcardEnabled().setEntity(isVmDeviceExists(vmBase.getManagedDeviceMap(),
 VmDeviceType.SOUND.getName()));
             
getModel().getIsConsoleDeviceEnabled().setEntity(isVmDeviceExists(vmBase.getManagedDeviceMap(),
 VmDeviceType.CONSOLE.getName()));
+
+            Set<GraphicsType> graphicsTypeSet = new HashSet<>();
+            for (GraphicsType graphicsType : GraphicsType.values()) {
+                if (isVmDeviceExists(vmBase.getManagedDeviceMap(), 
graphicsType.getCorrespondingDeviceType().getName())) {
+                    graphicsTypeSet.add(graphicsType);
+                }
+            }
+            
getModel().getGraphicsType().setSelectedItem(UnitVmModel.GraphicsTypes.fromGraphicsTypes(graphicsTypeSet));
+
             activate();
         }
 


-- 
To view, visit https://gerrit.ovirt.org/40037
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9cce664ae9fafe2713c014a95b4569b8c7e45f8e
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Shmuel Leib Melamud <smela...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to