Skip to content

Commit 765f166

Browse files
Prefill custom compute offering for VMware import
1 parent a0aafe2 commit 765f166

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

ui/src/views/tools/ImportUnmanagedInstance.vue

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@
279279
@select-compute-item="($event) => updateComputeOffering($event)"
280280
@handle-search-filter="($event) => fetchComputeOfferings($event)" />
281281
<compute-selection
282+
:key="computeSelectionKey"
282283
class="row-element"
283284
v-if="computeOffering && (computeOffering.iscustomized || computeOffering.iscustomizediops)"
284285
:isCustomized="computeOffering.iscustomized"
@@ -287,7 +288,7 @@
287288
:cpuSpeedInputDecorator="cpuSpeedKey"
288289
:memoryInputDecorator="memoryKey"
289290
:computeOfferingId="computeOffering.id"
290-
:preFillContent="resource"
291+
:preFillContent="computeOfferingPreFillContent"
291292
:isConstrained="'serviceofferingdetails' in computeOffering"
292293
:minCpu="getMinCpu()"
293294
:maxCpu="getMaxCpu()"
@@ -765,6 +766,23 @@ export default {
765766
}
766767
}
767768
return nics
769+
},
770+
computeOfferingPreFillContent () {
771+
return {
772+
...this.resource,
773+
cpunumber: this.getCustomCpuNumberDefault(),
774+
cpuspeed: this.getCPUSpeed(),
775+
memory: this.getCustomMemoryDefault()
776+
}
777+
},
778+
computeSelectionKey () {
779+
const preFill = this.computeOfferingPreFillContent
780+
return [
781+
this.computeOffering?.id || 'offering',
782+
preFill.cpunumber || 'cpu',
783+
preFill.cpuspeed || 'speed',
784+
preFill.memory || 'memory'
785+
].join('-')
768786
}
769787
},
770788
watch: {
@@ -865,14 +883,26 @@ export default {
865883
}
866884
return 'serviceofferingdetails' in this.computeOffering ? this.computeOffering.serviceofferingdetails.maxmemory * 1 : Number.MAX_SAFE_INTEGER
867885
},
886+
clampCustomValue (value, min, max) {
887+
if (value === undefined || value === null || isNaN(value)) {
888+
return min
889+
}
890+
return Math.min(Math.max(value * 1, min), max)
891+
},
892+
getCustomCpuNumberDefault () {
893+
return this.clampCustomValue(this.resource?.cpunumber, this.getMinCpu(), this.getMaxCpu())
894+
},
895+
getCustomMemoryDefault () {
896+
return this.clampCustomValue(this.resource?.memory, this.getMinMemory(), this.getMaxMemory())
897+
},
868898
getCPUSpeed () {
869899
if (!this.computeOffering) {
870-
return 0
900+
return 2000
871901
}
872902
if (this.computeOffering.cpuspeed) {
873903
return this.computeOffering.cpuspeed * 1
874904
}
875-
return this.resource.cpuspeed * 1 || 0
905+
return this.resource.cpuspeed * 1 || 2000
876906
},
877907
fetchOptions (param, name, exclude) {
878908
if (exclude && exclude.length > 0) {

0 commit comments

Comments
 (0)