This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch 4.15
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.15 by this push:
     new 5f734f7  vmware: Disk controller vmware deploy as is (#5006)
5f734f7 is described below

commit 5f734f718eb80cfccc83604892b20ec6068e6589
Author: Spaceman1984 <[email protected]>
AuthorDate: Wed May 19 11:03:16 2021 +0200

    vmware: Disk controller vmware deploy as is (#5006)
    
    Fixes #4344
---
 .../hypervisor/vmware/resource/VmwareResource.java | 46 ++--------------------
 .../main/java/com/cloud/vm/UserVmManagerImpl.java  |  7 ++++
 ui/src/components/view/DetailSettings.vue          | 11 ++++--
 3 files changed, 18 insertions(+), 46 deletions(-)

diff --git 
a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
 
b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index b5bfa98..4702dce 100644
--- 
a/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ 
b/plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -2067,9 +2067,7 @@ public class VmwareResource implements 
StoragePoolResource, ServerResource, Vmwa
                 }
 
                 VirtualMachineDiskInfo matchingExistingDisk = 
getMatchingExistingDisk(diskInfoBuilder, vol, hyperHost, context);
-                controllerKey = getDiskController(matchingExistingDisk, vol, 
vmSpec, ideControllerKey, scsiControllerKey);
-                String diskController = getDiskController(vmMo, 
matchingExistingDisk, vol, controllerInfo);
-
+                String diskController = getDiskController(vmMo, 
matchingExistingDisk, vol, controllerInfo, deployAsIs);
                 if (DiskControllerType.getType(diskController) == 
DiskControllerType.osdefault) {
                     diskController = vmMo.getRecommendedDiskController(null);
                 }
@@ -3273,47 +3271,9 @@ public class VmwareResource implements 
StoragePoolResource, ServerResource, Vmwa
         return null;
     }
 
-    private int getDiskController(VirtualMachineDiskInfo matchingExistingDisk, 
DiskTO vol, VirtualMachineTO vmSpec, int ideControllerKey, int 
scsiControllerKey) {
-
-        int controllerKey;
-        if (matchingExistingDisk != null) {
-            s_logger.info("Chose disk controller based on existing 
information: " + matchingExistingDisk.getDiskDeviceBusName());
-            if (matchingExistingDisk.getDiskDeviceBusName().startsWith("ide"))
-                return ideControllerKey;
-            else
-                return scsiControllerKey;
-        }
-
-        if (vol.getType() == Volume.Type.ROOT) {
-            Map<String, String> vmDetails = vmSpec.getDetails();
-            if (vmDetails != null && 
vmDetails.get(VmDetailConstants.ROOT_DISK_CONTROLLER) != null) {
-                if 
(vmDetails.get(VmDetailConstants.ROOT_DISK_CONTROLLER).equalsIgnoreCase("scsi"))
 {
-                    s_logger.info("Chose disk controller for vol " + 
vol.getType() + " -> scsi, based on root disk controller settings: "
-                            + 
vmDetails.get(VmDetailConstants.ROOT_DISK_CONTROLLER));
-                    controllerKey = scsiControllerKey;
-                } else {
-                    s_logger.info("Chose disk controller for vol " + 
vol.getType() + " -> ide, based on root disk controller settings: "
-                            + 
vmDetails.get(VmDetailConstants.ROOT_DISK_CONTROLLER));
-                    controllerKey = ideControllerKey;
-                }
-            } else {
-                s_logger.info("Chose disk controller for vol " + vol.getType() 
+ " -> scsi. due to null root disk controller setting");
-                controllerKey = scsiControllerKey;
-            }
-
-        } else {
-            // DATA volume always use SCSI device
-            s_logger.info("Chose disk controller for vol " + vol.getType() + " 
-> scsi");
-            controllerKey = scsiControllerKey;
-        }
-
-        return controllerKey;
-    }
-
-    private String getDiskController(VirtualMachineMO vmMo, 
VirtualMachineDiskInfo matchingExistingDisk, DiskTO vol, Pair<String, String> 
controllerInfo) throws Exception {
-        int controllerKey;
+    private String getDiskController(VirtualMachineMO vmMo, 
VirtualMachineDiskInfo matchingExistingDisk, DiskTO vol, Pair<String, String> 
controllerInfo, boolean deployAsIs) throws Exception {
         DiskControllerType controllerType = DiskControllerType.none;
-        if (matchingExistingDisk != null) {
+        if (deployAsIs && matchingExistingDisk != null) {
             String currentBusName = 
matchingExistingDisk.getDiskDeviceBusName();
             if (currentBusName != null) {
                 s_logger.info("Chose disk controller based on existing 
information: " + currentBusName);
diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java 
b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
index b4ef74f..0784d50 100644
--- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
@@ -2521,6 +2521,13 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
         String extraConfig = cmd.getExtraConfig();
 
         UserVmVO vmInstance = _vmDao.findById(cmd.getId());
+        if (MapUtils.isNotEmpty(details) || cmd.isCleanupDetails()) {
+            VMTemplateVO template = 
_templateDao.findById(vmInstance.getTemplateId());
+            if (template != null && template.isDeployAsIs()) {
+                throw new CloudRuntimeException("Detail settings are read from 
OVA, it cannot be changed by API call.");
+            }
+        }
+
         long accountId = vmInstance.getAccountId();
 
         if (isDisplayVm != null && isDisplayVm != vmInstance.isDisplay()) {
diff --git a/ui/src/components/view/DetailSettings.vue 
b/ui/src/components/view/DetailSettings.vue
index 9bb72ff..2571bed 100644
--- a/ui/src/components/view/DetailSettings.vue
+++ b/ui/src/components/view/DetailSettings.vue
@@ -80,11 +80,12 @@
           slot="actions"
           v-if="!disableSettings && 'updateTemplate' in $store.getters.apis &&
             'updateVirtualMachine' in $store.getters.apis && isAdminOrOwner() 
&& allowEditOfDetail(item.name)">
-          <tootip-button :tooltip="$t('label.cancel')" 
@click="hideEditDetail(index)" v-if="item.edit" iconType="close-circle" 
iconTwoToneColor="#f5222d" />
-          <tootip-button :tooltip="$t('label.ok')" 
@click="updateDetail(index)" v-if="item.edit" iconType="check-circle" 
iconTwoToneColor="#52c41a" />
+          <tooltip-button :tooltip="$t('label.cancel')" 
@click="hideEditDetail(index)" v-if="item.edit" iconType="close-circle" 
iconTwoToneColor="#f5222d" />
+          <tooltip-button :tooltip="$t('label.ok')" 
@click="updateDetail(index)" v-if="item.edit" iconType="check-circle" 
iconTwoToneColor="#52c41a" />
           <tooltip-button
             :tooltip="$t('label.edit')"
             icon="edit"
+            :disabled="deployasistemplate === true"
             v-if="!item.edit"
             @click="showEditDetail(index)" />
         </div>
@@ -99,7 +100,7 @@
             :cancelText="$t('label.no')"
             placement="left"
           >
-            <tooltip-button :tooltip="$t('label.delete')" type="danger" 
icon="delete" />
+            <tooltip-button :tooltip="$t('label.delete')" 
:disabled="deployasistemplate === true" type="danger" icon="delete" />
           </a-popconfirm>
         </div>
       </a-list-item>
@@ -130,6 +131,7 @@ export default {
       newValue: '',
       loading: false,
       resourceType: 'UserVm',
+      deployasistemplate: false,
       error: false
     }
   },
@@ -163,6 +165,9 @@ export default {
         this.detailOptions = 
json.listdetailoptionsresponse.detailoptions.details
       })
       this.disableSettings = (this.$route.meta.name === 'vm' && 
this.resource.state !== 'Stopped')
+      api('listTemplates', { templatefilter: 'all', id: 
this.resource.templateid }).then(json => {
+        this.deployasistemplate = 
json.listtemplatesresponse.template[0].deployasis
+      })
     },
     filterOrReadOnlyDetails () {
       for (var i = 0; i < this.details.length; i++) {

Reply via email to