Tomas Jelinek has uploaded a new change for review.

Change subject: engine: Model the smartcard as a device
......................................................................

engine: Model the smartcard as a device

Since the VDSM models the smartcard as a device, the engine
has been updated to model the smartcard as a device in
vm_device table too.

This is the firts phase - it does not remove the
is_smartcard_enabled from the vm_static.

Change-Id: I92c88b64f3efdf6e5b6fa829ac4b0dac47868e4a
Signed-off-by: Tomas Jelinek <tjeli...@redhat.com>
---
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/AddVmFromScratchCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/smartcard/SmartcardSpecParams.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/utils/VmDeviceCommonUtils.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceType.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
8 files changed, 105 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/02/10302/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 1288a48..eeb7934 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
@@ -13,13 +13,13 @@
 import org.ovirt.engine.core.bll.command.utils.StorageDomainSpaceChecker;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
 import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter;
-import org.ovirt.engine.core.bll.quota.QuotaStorageDependent;
 import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter;
+import org.ovirt.engine.core.bll.quota.QuotaStorageDependent;
 import org.ovirt.engine.core.bll.snapshots.SnapshotsManager;
+import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.bll.utils.VmDeviceUtils;
 import org.ovirt.engine.core.bll.validator.StorageDomainValidator;
 import org.ovirt.engine.core.common.AuditLogType;
-import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.common.VdcObjectType;
 import 
org.ovirt.engine.core.common.action.CreateSnapshotFromTemplateParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromScratchCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromScratchCommand.java
index 4c316c0..bcd8add 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromScratchCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmFromScratchCommand.java
@@ -5,7 +5,9 @@
 import java.util.List;
 
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
+import org.ovirt.engine.core.bll.smartcard.SmartcardSpecParams;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
+import org.ovirt.engine.core.bll.utils.VmDeviceUtils;
 import org.ovirt.engine.core.common.VdcObjectType;
 import org.ovirt.engine.core.common.action.AddImageFromScratchParameters;
 import org.ovirt.engine.core.common.action.AddVmFromScratchParameters;
@@ -15,9 +17,12 @@
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatus;
 import org.ovirt.engine.core.common.businessentities.StorageDomainType;
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.businessentities.storage_domains;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.errors.VdcBllErrors;
+import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.NGuid;
 import org.ovirt.engine.core.dal.VdcBllMessages;
@@ -35,6 +40,24 @@
 
     protected AddVmFromScratchCommand(Guid commandId) {
         super(commandId);
+    }
+
+    @Override
+    public VdcReturnValueBase executeAction() {
+        VdcReturnValueBase res = super.executeAction();
+        if (getParameters().getVm().isSmartcardEnabled()) {
+            addSmartcardDevice(getParameters().getVm());
+        }
+        return res;
+    }
+
+    protected void addSmartcardDevice(VM vm) {
+        VmDeviceUtils.addManagedDevice(new VmDeviceId(Guid.NewGuid(), 
getParameters().getVmId()),
+                VmDeviceType.SMARTCARD,
+                VmDeviceType.SMARTCARD,
+                new SmartcardSpecParams(),
+                true,
+                false);
     }
 
     @Override
@@ -69,8 +92,8 @@
         }
 
         Disk defBootDisk = null;
-        for(Disk disk : getVmDisks()) {
-            if(disk.isBoot()) {
+        for (Disk disk : getVmDisks()) {
+            if (disk.isBoot()) {
                 defBootDisk = disk;
                 break;
             }
@@ -82,7 +105,7 @@
                     disk.setBoot(false);
             }
         }
-        return (!disks.isEmpty()) ? 
ConcreteAddVmImages(((DiskImage)disks.get(0)).getImageId()) : true;
+        return (!disks.isEmpty()) ? ConcreteAddVmImages(((DiskImage) 
disks.get(0)).getImageId()) : true;
     }
 
     protected boolean ConcreteAddVmImages(Guid itGuid) {
@@ -92,16 +115,16 @@
             for (Disk diskInfo : getVmDisks()) {
                 VdcReturnValueBase tmpRetValue = null;
                 AddImageFromScratchParameters tempVar = new 
AddImageFromScratchParameters(itGuid, getParameters()
-                            .getVmStaticData().getId(), (DiskImage) diskInfo);
+                        .getVmStaticData().getId(), (DiskImage) diskInfo);
                 
tempVar.setStorageDomainId(this.getStorageDomainId().getValue());
                 tempVar.setVmSnapshotId(getVmSnapshotId());
                 tempVar.setParentCommand(VdcActionType.AddVmFromScratch);
                 tempVar.setEntityId(getParameters().getEntityId());
                 tempVar.setParentParameters(getParameters());
                 tmpRetValue = Backend.getInstance().runInternalAction(
-                                VdcActionType.AddImageFromScratch,
-                                tempVar,
-                                
ExecutionHandler.createDefaultContexForTasks(getExecutionContext()));
+                        VdcActionType.AddImageFromScratch,
+                        tempVar,
+                        
ExecutionHandler.createDefaultContexForTasks(getExecutionContext()));
                 if (!tmpRetValue.getSucceeded()) {
                     log.error("AddVmFromScratchCommand::ConcreteAddVmImages: 
AddImageFromScratch Command failed.");
                     ret = false;
@@ -129,9 +152,9 @@
             addCanDoActionMessage(VdcBllMessages.VM_CLUSTER_IS_NOT_VALID);
         } else {
             result = 
ImagesHandler.CheckImagesConfiguration(getStorageDomainId().getValue(),
-                                                            getParameters()
-                                                                           
.getDiskInfoList(),
-                                                            
getReturnValue().getCanDoActionMessages());
+                    getParameters()
+                            .getDiskInfoList(),
+                    getReturnValue().getCanDoActionMessages());
         }
 
         if (!result) {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java
index 28c0b24..90df2c1 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java
@@ -7,6 +7,7 @@
 import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter;
 import org.ovirt.engine.core.bll.quota.QuotaSanityParameter;
 import org.ovirt.engine.core.bll.quota.QuotaVdsDependent;
+import org.ovirt.engine.core.bll.utils.VmDeviceUtils;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.UpdateVmTemplateParameters;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
@@ -99,6 +100,8 @@
 
     private void UpdateVmTemplate() {
         DbFacade.getInstance().getVmTemplateDao().update(getVmTemplate());
+        // also update the smartcard device
+        VmDeviceUtils.updateSmartcardDevice(getVmTemplateId(), 
getParameters().getVmTemplateData().isSmartcardEnabled());
     }
 
     @Override
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/smartcard/SmartcardSpecParams.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/smartcard/SmartcardSpecParams.java
new file mode 100644
index 0000000..ef72aca
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/smartcard/SmartcardSpecParams.java
@@ -0,0 +1,14 @@
+package org.ovirt.engine.core.bll.smartcard;
+
+import java.util.HashMap;
+
+public class SmartcardSpecParams extends HashMap<String, Object> {
+
+    private static final long serialVersionUID = 4548406604400880935L;
+
+    public SmartcardSpecParams() {
+        put("mode", "passthrough");
+        put("type", "spicevmc");
+    }
+
+}
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 c63f15d..e328b60 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
@@ -11,6 +11,7 @@
 
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.VmHandler;
+import org.ovirt.engine.core.bll.smartcard.SmartcardSpecParams;
 import org.ovirt.engine.core.common.action.VmManagementParametersBase;
 import org.ovirt.engine.core.common.businessentities.BaseDisk;
 import org.ovirt.engine.core.common.businessentities.Disk;
@@ -81,6 +82,37 @@
             updateMemoryBalloon(oldVmBase, entity, params.isBalloonEnabled());
 
             updateAudioDevice(oldVm, entity);
+            updateSmartcardDevice(oldVm, entity);
+        }
+    }
+
+    private static void updateSmartcardDevice(VM oldVm, VmBase newVm) {
+        if (newVm.isSmartcardEnabled() == oldVm.isSmartcardEnabled()) {
+            // the smartcard device did not changed, do nothing
+            return;
+        }
+
+        updateSmartcardDevice(newVm.getId(), newVm.isSmartcardEnabled());
+    }
+
+    public static void updateSmartcardDevice(Guid vmId, boolean 
smartcardEnabled) {
+        if (!smartcardEnabled) {
+            List<VmDevice> vmDevices =
+                    DbFacade.getInstance()
+                            .getVmDeviceDao()
+                            .getVmDeviceByVmIdTypeAndDevice(vmId,
+                                    VmDeviceType.SMARTCARD.getName(),
+                                    VmDeviceType.SMARTCARD.getName());
+            for (VmDevice device : vmDevices) {
+                dao.remove(device.getId());
+            }
+        } else {
+            VmDeviceUtils.addManagedDevice(new VmDeviceId(Guid.NewGuid(), 
vmId),
+                    VmDeviceType.SMARTCARD,
+                    VmDeviceType.SMARTCARD,
+                    new SmartcardSpecParams(),
+                    true,
+                    false);
         }
     }
 
@@ -209,6 +241,8 @@
             }
             else if (VmDeviceType.BALLOON.getName().equals(device.getType())){
                 specParams.put(VdsProperties.Model, VdsProperties.Virtio);
+            } else if 
(VmDeviceType.SMARTCARD.getName().equals(device.getType())) {
+                specParams = new SmartcardSpecParams();
             }
             device.setId(new VmDeviceId(id, dstId));
             device.setSpecParams(specParams);
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java
index 4784021..716ed28 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/VmDeviceCommonUtils.java
@@ -285,6 +285,7 @@
     public static boolean isSpecialDevice(String device, String type) {
         return (VmDeviceType.SOUND.getName().equals(type) ||
                 VmDeviceType.USB.getName().equals(device) ||
+                (VmDeviceType.SMARTCARD.getName().equals(device) && 
VmDeviceType.SMARTCARD.getName().equals(type)) ||
                 (VmDeviceType.SPICEVMC.getName().equals(device) && 
VmDeviceType.REDIR.getName().equals(type)) || (VmDeviceType.MEMBALLOON.getName()
                         .equals(device) && 
VmDeviceType.BALLOON.getName().equals(type)));
     }
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 a2c676f..a466960 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
@@ -17,6 +17,7 @@
     ICH6("ich6"),
     AC97("ac97"),
     MEMBALLOON("memballoon"),
+    SMARTCARD("smartcard"),
     BALLOON("balloon"),
     OTHER("other", "0"),
     UNKNOWN("unknown", "-1");
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 e43f320..947d48d 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
@@ -583,6 +583,23 @@
     protected void buildVmUsbDevices() {
         buildVmUsbControllers();
         buildVmUsbSlots();
+        buildSmartcardDevice();
+    }
+
+    private void buildSmartcardDevice() {
+        List<VmDevice> vmDevices =
+                DbFacade.getInstance()
+                        .getVmDeviceDao()
+                        .getVmDeviceByVmIdTypeAndDevice(vm.getId(),
+                                VmDeviceType.SMARTCARD.getName(),
+                                VmDeviceType.SMARTCARD.getName());
+
+        for (VmDevice vmDevice : vmDevices) {
+            XmlRpcStruct struct = new XmlRpcStruct();
+            struct.add(VdsProperties.Type, vmDevice.getType());
+            struct.add(VdsProperties.Device, vmDevice.getType());
+            addDevice(struct, vmDevice, null);
+        }
     }
 
     @Override


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I92c88b64f3efdf6e5b6fa829ac4b0dac47868e4a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Tomas Jelinek <tjeli...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to