Allow specifying disk size, min/max iops for offering linked with custom disk offering (#6018)

This commit is contained in:
Pearl Dsilva 2022-03-05 08:41:25 +05:30 committed by GitHub
parent 3a74ec78be
commit 4d54e8e84c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 4 deletions

View File

@ -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;
}

View File

@ -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");

View File

@ -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

View File

@ -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)
},