diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/General/capacitySchema.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/General/capacitySchema.js index 237c7288ab..ba4884ac3b 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/General/capacitySchema.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/General/capacitySchema.js @@ -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) diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/General/schema.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/General/schema.js index f3a8a53824..44c0ca1fff 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/General/schema.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/General/schema.js @@ -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, diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/index.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/index.js index d510496b08..4770c59f9f 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/index.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/index.js @@ -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, diff --git a/src/fireedge/src/client/constants/translates.js b/src/fireedge/src/client/constants/translates.js index 2c0c12d119..47d8712c16 100644 --- a/src/fireedge/src/client/constants/translates.js +++ b/src/fireedge/src/client/constants/translates.js @@ -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 */ diff --git a/src/fireedge/src/client/constants/vmTemplate.js b/src/fireedge/src/client/constants/vmTemplate.js index a54e3ffd9d..606437fd97 100644 --- a/src/fireedge/src/client/constants/vmTemplate.js +++ b/src/fireedge/src/client/constants/vmTemplate.js @@ -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', +} diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js index cb8e71690d..51134bcc1b 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create.js @@ -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; + } + }) } /** diff --git a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create/html.hbs b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create/html.hbs index 1bb49c1a88..efb3b511c4 100644 --- a/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create/html.hbs +++ b/src/sunstone/public/app/tabs/templates-tab/form-panels/create/wizard-tabs/general/capacity-create/html.hbs @@ -132,6 +132,35 @@ +