From 2a7ac304e940c32f4ba129581cdeb53c0d8e9752 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Mon, 21 Feb 2022 19:20:14 +0530 Subject: [PATCH] Allow specifying disk size, min/max iops for offering linked with custom disk offering --- .../volume/ChangeOfferingForVolumeCmd.java | 4 ++ .../java/com/cloud/vm/UserVmManagerImpl.java | 7 +++ ui/src/views/compute/ScaleVM.vue | 57 ++++++++++++++++++- .../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 5a1d07ef2be5..455e6cb828f0 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 Long getSize() { 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 8b266b948171..8a4d9d308396 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -2034,6 +2034,7 @@ private void changeDiskOfferingForRootVolume(Long vmId, DiskOfferingVO newDiskOf 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)); } @@ -2046,7 +2047,13 @@ private void changeDiskOfferingForRootVolume(Long vmId, DiskOfferingVO newDiskOf 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 0a0caa0cc541..235bfc971179 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" /> + + { + 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 a2c3695356f2..9eae5d3353f5 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) },