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

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


The following commit(s) were added to refs/heads/main by this push:
     new 4d54e8e  Allow specifying disk size, min/max iops for offering linked 
with custom disk offering (#6018)
4d54e8e is described below

commit 4d54e8e84c11fbe9a9215972da1b1bda8f4ab275
Author: Pearl Dsilva <[email protected]>
AuthorDate: Sat Mar 5 08:41:25 2022 +0530

    Allow specifying disk size, min/max iops for offering linked with custom 
disk offering (#6018)
---
 .../user/volume/ChangeOfferingForVolumeCmd.java    |  4 ++
 .../main/java/com/cloud/vm/UserVmManagerImpl.java  |  7 +++
 ui/src/views/compute/ScaleVM.vue                   | 57 +++++++++++++++++++++-
 ui/src/views/compute/wizard/DiskSizeSelection.vue  |  4 +-
 4 files changed, 68 insertions(+), 4 deletions(-)

diff --git 
a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ChangeOfferingForVolumeCmd.java
 
b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ChangeOfferingForVolumeCmd.java
index 5a1d07e..455e6cb 100644
--- 
a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ChangeOfferingForVolumeCmd.java
+++ 
b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ChangeOfferingForVolumeCmd.java
@@ -104,6 +104,10 @@ public class ChangeOfferingForVolumeCmd extends 
BaseAsyncCmd implements UserCmd
         return size;
     }
 
+    public void setSize(Long size) {
+        this.size = size;
+    }
+
     public Long getMinIops() {
         return minIops;
     }
diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java 
b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
index 879b1e1..ad16555 100644
--- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
@@ -2042,6 +2042,7 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
                 Long maxIopsInNewDiskOffering = null;
                 boolean autoMigrate = false;
                 boolean shrinkOk = false;
+                Long rootDiskSize = null;
                 if (customParameters.containsKey(ApiConstants.MIN_IOPS)) {
                     minIopsInNewDiskOffering = 
Long.parseLong(customParameters.get(ApiConstants.MIN_IOPS));
                 }
@@ -2054,7 +2055,13 @@ public class UserVmManagerImpl extends ManagerBase 
implements UserVmManager, Vir
                 if (customParameters.containsKey(ApiConstants.SHRINK_OK)) {
                     shrinkOk = 
Boolean.parseBoolean(customParameters.get(ApiConstants.SHRINK_OK));
                 }
+                if (customParameters.containsKey(ApiConstants.ROOT_DISK_SIZE)) 
{
+                    rootDiskSize = 
Long.parseLong(customParameters.get(ApiConstants.ROOT_DISK_SIZE));
+                }
                 ChangeOfferingForVolumeCmd changeOfferingForVolumeCmd = new 
ChangeOfferingForVolumeCmd(rootVolumeOfVm.getId(), newDiskOffering.getId(), 
minIopsInNewDiskOffering, maxIopsInNewDiskOffering, autoMigrate, shrinkOk);
+                if (rootDiskSize != null) {
+                    changeOfferingForVolumeCmd.setSize(rootDiskSize);
+                }
                 Volume result = 
_volumeService.changeDiskOfferingForVolume(changeOfferingForVolumeCmd);
                 if (result == null) {
                     throw new CloudRuntimeException("Failed to change disk 
offering of the root volume");
diff --git a/ui/src/views/compute/ScaleVM.vue b/ui/src/views/compute/ScaleVM.vue
index 0a0caa0..235bfc9 100644
--- a/ui/src/views/compute/ScaleVM.vue
+++ b/ui/src/views/compute/ScaleVM.vue
@@ -53,6 +53,16 @@
       @update-compute-cpuspeed="updateFieldValue"
       @update-compute-memory="updateFieldValue" />
 
+    <disk-size-selection
+      v-if="selectedDiskOffering && (selectedDiskOffering.iscustomized || 
selectedDiskOffering.iscustomizediops)"
+      :inputDecorator="rootDiskSizeKey"
+      :minDiskSize="minDiskSize"
+      :rootDiskSelected="selectedDiskOffering"
+      :isCustomized="selectedDiskOffering.iscustomized"
+      @handler-error="handlerError"
+      @update-disk-size="updateFieldValue"
+      @update-root-disk-iops-value="updateIOPSValue"/>
+
     <a-form-item :label="$t('label.automigrate.volume')">
       <tooltip-label slot="label" :title="$t('label.automigrate.volume')" 
:tooltip="apiParams.automigrate.description"/>
       <a-switch
@@ -72,12 +82,14 @@
 import { api } from '@/api'
 import ComputeOfferingSelection from 
'@views/compute/wizard/ComputeOfferingSelection'
 import ComputeSelection from '@views/compute/wizard/ComputeSelection'
+import DiskSizeSelection from '@views/compute/wizard/DiskSizeSelection'
 
 export default {
   name: 'ScaleVM',
   components: {
     ComputeOfferingSelection,
-    ComputeSelection
+    ComputeSelection,
+    DiskSizeSelection
   },
   props: {
     resource: {
@@ -91,6 +103,7 @@ export default {
       offeringsMap: {},
       offerings: [],
       selectedOffering: {},
+      selectedDiskOffering: {},
       autoMigrate: true,
       total: 0,
       params: { id: this.resource.id },
@@ -98,7 +111,11 @@ export default {
       cpuNumberKey: 'details[0].cpuNumber',
       cpuSpeedKey: 'details[0].cpuSpeed',
       memoryKey: 'details[0].memory',
-      fixedOfferingKvm: false
+      rootDiskSizeKey: 'details[0].rootdisksize',
+      minIopsKey: 'details[0].minIops',
+      maxIopsKey: 'details[0].maxIops',
+      fixedOfferingKvm: false,
+      minDiskSize: 0
     }
   },
   beforeCreate () {
@@ -162,14 +179,37 @@ export default {
       if (this.resource.state === 'Running') {
         return this.resource.cpuspeed
       }
+      this.getMinDiskSize()
       return this.selectedOffering?.serviceofferingdetails?.cpuspeed * 1 || 1
     },
+    getTemplate () {
+      return new Promise((resolve, reject) => {
+        api('listTemplates', {
+          templatefilter: 'all',
+          id: this.resource.templateid
+        }).then(response => {
+          var template = response?.listtemplatesresponse?.template?.[0] || null
+          resolve(template)
+        }).catch(error => {
+          reject(error)
+        })
+      })
+    },
+    async getMinDiskSize () {
+      const template = await this.getTemplate()
+      this.minDiskSize = Math.ceil(template?.size / (1024 * 1024 * 1024) || 0)
+    },
     getMessage () {
       if (this.resource.hypervisor === 'VMware') {
         return this.$t('message.read.admin.guide.scaling.up')
       }
       return this.$t('message.change.offering.confirm')
     },
+    updateIOPSValue (input, value) {
+      console.log(input)
+      const key = input === 'minIops' ? this.minIopsKey : this.maxIopsKey
+      this.params[key] = value
+    },
     updateComputeOffering (id) {
       // Delete custom details
       delete this.params[this.cpuNumberKey]
@@ -178,6 +218,16 @@ export default {
 
       this.params.serviceofferingid = id
       this.selectedOffering = this.offeringsMap[id]
+      api('listDiskOfferings', {
+        id: this.selectedOffering.diskofferingid
+      }).then(response => {
+        const diskOfferings = response.listdiskofferingsresponse.diskoffering 
|| []
+        if (this.offerings) {
+          this.selectedDiskOffering = diskOfferings[0]
+        }
+      }).catch(error => {
+        this.$notifyError(error)
+      })
       this.params.automigrate = this.autoMigrate
     },
     updateFieldValue (name, value) {
@@ -186,6 +236,9 @@ export default {
     closeAction () {
       this.$emit('close-action')
     },
+    handlerError (error) {
+      this.error = error
+    },
     handleSubmit () {
       if (this.loading) return
       this.loading = true
diff --git a/ui/src/views/compute/wizard/DiskSizeSelection.vue 
b/ui/src/views/compute/wizard/DiskSizeSelection.vue
index a2c3695..9eae5d3 100644
--- a/ui/src/views/compute/wizard/DiskSizeSelection.vue
+++ b/ui/src/views/compute/wizard/DiskSizeSelection.vue
@@ -109,9 +109,9 @@ export default {
     fillValue () {
       this.inputValue = this.minDiskSize
       if (this.inputDecorator === 'rootdisksize') {
-        this.inputValue = this.preFillContent.rootdisksize ? 
this.preFillContent.rootdisksize : this.minDiskSize
+        this.inputValue = this.preFillContent?.rootdisksize ? 
this.preFillContent.rootdisksize : this.minDiskSize
       } else if (this.inputDecorator === 'size') {
-        this.inputValue = this.preFillContent.size ? this.preFillContent.size 
: this.minDiskSize
+        this.inputValue = this.preFillContent?.size ? this.preFillContent.size 
: this.minDiskSize
       }
       this.$emit('update-disk-size', this.inputDecorator, this.inputValue)
     },

Reply via email to