1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

F #5753: Expose memory resize mode on Sunstone (#2387)

This commit is contained in:
Frederick Borges 2022-11-29 13:21:05 +01:00 committed by GitHub
parent 820970b182
commit d917a59e2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 117 additions and 4 deletions

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import { number } from 'yup'
import { number, string } from 'yup'
import {
generateModificationInputs,
@ -23,13 +23,21 @@ import {
} from 'client/components/Forms/VmTemplate/CreateForm/Steps/General/capacityUtils'
import { Translate } from 'client/components/HOC'
import { formatNumberByCurrency } from 'client/models/Helper'
import { Field } from 'client/utils'
import { T, HYPERVISORS, VmTemplateFeatures } from 'client/constants'
import { Field, arrayToOptions } from 'client/utils'
import {
T,
HYPERVISORS,
VmTemplateFeatures,
INPUT_TYPES,
MEMORY_RESIZE_OPTIONS,
} from 'client/constants'
const commonValidation = number()
.positive()
.default(() => undefined)
const { vcenter, lxc, firecracker } = HYPERVISORS
// --------------------------------------------------------
// MEMORY fields
// --------------------------------------------------------
@ -43,7 +51,7 @@ export const MEMORY = generateCapacityInput({
.integer()
.required()
.when('HYPERVISOR', (hypervisor, schema) =>
hypervisor === HYPERVISORS.vcenter ? schema.isDivisibleBy(4) : schema
hypervisor === vcenter ? schema.isDivisibleBy(4) : schema
),
})
@ -192,3 +200,42 @@ export const DISK_COST = generateCostCapacityInput({
*/
export const SHOWBACK_FIELDS = (features) =>
[MEMORY_COST, !features?.hide_cpu && CPU_COST, DISK_COST].filter(Boolean)
/** @type {Field} Memory resize mode field */
export const MEMORY_RESIZE_MODE_FIELD = {
name: 'MEMORY_RESIZE_MODE',
label: T.MemoryResizeMode,
type: INPUT_TYPES.SELECT,
notOnHypervisors: [lxc, firecracker, vcenter],
dependOf: ['HYPERVISOR', '$general.HYPERVISOR'],
values: arrayToOptions(Object.keys(MEMORY_RESIZE_OPTIONS), {
addEmpty: false,
getText: (option) => option,
getValue: (option) => MEMORY_RESIZE_OPTIONS[option],
}),
validation: string().default(() => MEMORY_RESIZE_OPTIONS[T.Ballooning]),
grid: { md: 6 },
}
/** @type {Field} Memory slots field */
export const MEMORY_SLOTS_FIELD = {
name: 'MEMORY_SLOTS',
label: T.MemorySlots,
type: INPUT_TYPES.TEXT,
notOnHypervisors: [lxc, firecracker, vcenter],
dependOf: MEMORY_RESIZE_MODE_FIELD.name,
htmlType: (resizeMode) =>
resizeMode === MEMORY_RESIZE_OPTIONS[T.Hotplug]
? 'number'
: INPUT_TYPES.HIDDEN,
validation: number().default(() => undefined),
grid: { md: 6 },
}
/**
* @returns {Field[]} List of memory resize fields
*/
export const MEMORY_RESIZE_FIELDS = [
MEMORY_RESIZE_MODE_FIELD,
MEMORY_SLOTS_FIELD,
].filter(Boolean)

View File

@ -25,6 +25,7 @@ import {
CPU_FIELDS,
VCPU_FIELDS,
SHOWBACK_FIELDS,
MEMORY_RESIZE_FIELDS,
} from './capacitySchema'
import { FIELDS as VM_GROUP_FIELDS } from './vmGroupSchema'
import { FIELDS as OWNERSHIP_FIELDS } from './ownershipSchema'
@ -62,6 +63,10 @@ const SECTIONS = (hypervisor, isUpdate, features) =>
legend: T.Memory,
fields: filterFieldsByHypervisor(MEMORY_FIELDS, hypervisor),
},
{
id: 'capacity',
fields: filterFieldsByHypervisor(MEMORY_RESIZE_FIELDS, hypervisor),
},
!features?.hide_cpu && {
id: 'capacity',
legend: T.PhysicalCpu,

View File

@ -32,6 +32,7 @@ import {
encodeBase64,
getUnknownAttributes,
} from 'client/utils'
import { T, MEMORY_RESIZE_OPTIONS } from 'client/constants'
/**
* Encodes the start script value to base64 if it is not already encoded.
@ -122,6 +123,13 @@ const Steps = createSteps([General, ExtraConfiguration, CustomVariables], {
!isCapacity && (extraTemplate.CONTEXT[upperName] = `$${upperName}`)
})
if (
general?.MEMORY_RESIZE_MODE === MEMORY_RESIZE_OPTIONS[T.Ballooning] &&
general?.MEMORY_SLOTS
) {
delete general.MEMORY_SLOTS
}
return jsonToXml({
...customVariables,
...extraTemplate,

View File

@ -690,6 +690,10 @@ module.exports = {
AllowUsersToModifyVirtualCpu:
"Allow users to modify this template's default Virtual CPU on instantiate",
EnableHotResize: 'Enable hot resize',
Hotplug: 'Hotplug',
Ballooning: 'Ballooning',
MemoryResizeMode: 'Memory resize mode',
MemorySlots: 'Memory slots',
/* VM Template schema - VM Group */
AssociateToVMGroup: 'Associate VM to a VM Group',
/* VM Template schema - vCenter */

View File

@ -135,3 +135,9 @@ export const NIC_HARDWARE_STR = {
[NIC_HARDWARE.PCI_PASSTHROUGH_AUTOMATIC]: T.PCIPassthroughAutomatic,
[NIC_HARDWARE.PCI_PASSTHROUGH_MANUAL]: T.PCIPassthroughManual,
}
/** @enum {string} Memory resize options */
export const MEMORY_RESIZE_OPTIONS = {
[T.Ballooning]: 'BALLOONING',
[T.Hotplug]: 'HOTPLUG',
}

View File

@ -307,6 +307,20 @@ define(function(require) {
$("."+classname+"_modify_type", context).change();
});
$("#MEMORY_RESIZE_MODE", context).on('change', function(){
switch (this.value) {
case 'BALLOONING':
$("#MEMORY_SLOTS", context).val("")
$("#memory_slots_div", context).hide()
break;
case 'HOTPLUG':
$("#memory_slots_div", context).show()
break;
default:
break;
}
})
}
/**

View File

@ -132,6 +132,35 @@
</div>
</div>
</div>
<div class="only_kvm row">
<div class="medium-6 small-12 columns">
<div class="row">
<div class="small-12 columns">
<label class="" for="MEMORY_RESIZE_MODE">
{{tr "Memory Resize Mode"}}
</label>
</div>
<div class="small-12 columns">
<select id="MEMORY_RESIZE_MODE" wizard_field="MEMORY_RESIZE_MODE" >
<option selected value="BALLOONING">{{tr "Ballooning"}}</option>
<option value="HOTPLUG">{{tr "Hotplug"}}</option>
</select>
</div>
</div>
</div>
<div class="medium-6 small-12 columns" id="memory_slots_div" hidden>
<div class="row">
<div class="small-12 columns">
<label class="" for="MEMORY_SLOTS">
{{tr "Memory Slots"}}
</label>
</div>
<div class="small-12 columns">
<input type="number" id="MEMORY_SLOTS" wizard_field="MEMORY_SLOTS"/>
</div>
</div>
</div>
</div>
<div class="row">
<div class="medium-7 small-12 columns">
<div class="row">