mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-31 01:47:11 +03:00
F OpenNebula/one#6136: Unit size on images and templates (#2666)
This commit is contained in:
parent
f0756c0b4d
commit
a131bbfa93
@ -25,6 +25,7 @@ import {
|
||||
INPUT_TYPES,
|
||||
IMAGE_TYPES_STR,
|
||||
IMAGE_TYPES_FOR_IMAGES,
|
||||
UNITS,
|
||||
} from 'client/constants'
|
||||
|
||||
export const IMAGE_LOCATION_TYPES = {
|
||||
@ -157,7 +158,7 @@ export const SIZE = {
|
||||
htmlType: htmlType(IMAGE_LOCATION_TYPES.EMPTY, true),
|
||||
label: T.Size,
|
||||
type: INPUT_TYPES.TEXT,
|
||||
tooltip: T.ImageSize,
|
||||
tooltip: T.ImageSizeUnit,
|
||||
validation: number()
|
||||
.positive()
|
||||
.default(() => undefined)
|
||||
@ -166,7 +167,29 @@ export const SIZE = {
|
||||
then: (schema) => schema.required(),
|
||||
otherwise: (schema) => schema.strip(),
|
||||
}),
|
||||
grid: { md: 12 },
|
||||
grid: { md: 9 },
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Field} size field
|
||||
* ISSUE#6136: Add unit size. Use only MB, GB, and TB (other values do not apply to create image).
|
||||
*/
|
||||
export const SIZEUNIT = {
|
||||
name: 'SIZEUNIT',
|
||||
dependOf: IMAGE_LOCATION_FIELD.name,
|
||||
htmlType: htmlType(IMAGE_LOCATION_TYPES.EMPTY, true),
|
||||
label: T.SizeUnit,
|
||||
type: INPUT_TYPES.SELECT,
|
||||
tooltip: T.SizeUnitTooltip,
|
||||
values: arrayToOptions([UNITS.MB, UNITS.GB, UNITS.TB], {
|
||||
addEmpty: false,
|
||||
getText: (type) => type,
|
||||
getValue: (type) => type,
|
||||
}),
|
||||
validation: string()
|
||||
.trim()
|
||||
.default(() => UNITS.MB),
|
||||
grid: { xs: 12, md: 3 },
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,6 +204,7 @@ export const FIELDS = [
|
||||
PATH_FIELD,
|
||||
UPLOAD_FIELD,
|
||||
SIZE,
|
||||
SIZEUNIT,
|
||||
]
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ import CustomAttributes, {
|
||||
STEP_ID as CUSTOM_ID,
|
||||
} from 'client/components/Forms/Image/CreateForm/Steps/CustomAttributes'
|
||||
|
||||
import { createSteps, cloneObject, set } from 'client/utils'
|
||||
import { createSteps, cloneObject, set, convertToMB } from 'client/utils'
|
||||
|
||||
const Steps = createSteps(
|
||||
[General, Datastore, AdvancedOptions, CustomAttributes],
|
||||
@ -46,6 +46,14 @@ const Steps = createSteps(
|
||||
set(generalData, 'UPLOAD', undefined)
|
||||
set(generalData, 'IMAGE_LOCATION', undefined)
|
||||
|
||||
// ISSUE#6136: Convert size to MB (because XML API uses only MB) and delete sizeunit field (no needed on XML API)
|
||||
set(
|
||||
generalData,
|
||||
'SIZE',
|
||||
convertToMB(generalData.SIZE, generalData.SIZEUNIT)
|
||||
)
|
||||
set(generalData, 'SIZEUNIT', undefined)
|
||||
|
||||
return {
|
||||
template: {
|
||||
...custom,
|
||||
|
@ -21,20 +21,46 @@ import {
|
||||
filterFieldsByHypervisor,
|
||||
arrayToOptions,
|
||||
} from 'client/utils'
|
||||
import { T, INPUT_TYPES, HYPERVISORS, SERVER_CONFIG } from 'client/constants'
|
||||
import {
|
||||
T,
|
||||
INPUT_TYPES,
|
||||
HYPERVISORS,
|
||||
SERVER_CONFIG,
|
||||
UNITS,
|
||||
} from 'client/constants'
|
||||
|
||||
const { vcenter } = HYPERVISORS
|
||||
|
||||
/** @type {Field} Size field */
|
||||
const SIZE = {
|
||||
name: 'SIZE',
|
||||
label: [T.SizeOnUnits, 'MB'],
|
||||
tooltip: T.SizeConcept,
|
||||
label: [T.Size, 'MB'],
|
||||
type: INPUT_TYPES.TEXT,
|
||||
htmlType: 'number',
|
||||
validation: number()
|
||||
.required()
|
||||
.default(() => undefined),
|
||||
grid: { xs: 12, md: 3 },
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Field} size field
|
||||
* ISSUE#6136: Add unit size. Use only MB, GB, and TB (other values do not apply to create image).
|
||||
*/
|
||||
export const SIZEUNIT = {
|
||||
name: 'SIZEUNIT',
|
||||
label: T.SizeUnit,
|
||||
type: INPUT_TYPES.SELECT,
|
||||
tooltip: T.SizeUnitTooltip,
|
||||
values: arrayToOptions([UNITS.MB, UNITS.GB, UNITS.TB], {
|
||||
addEmpty: false,
|
||||
getText: (type) => type,
|
||||
getValue: (type) => type,
|
||||
}),
|
||||
validation: string()
|
||||
.trim()
|
||||
.default(() => UNITS.MB),
|
||||
grid: { xs: 12, md: 3 },
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,7 +123,10 @@ const FILESYSTEM = {
|
||||
* @returns {Field[]} List of fields
|
||||
*/
|
||||
export const FIELDS = (hypervisor) =>
|
||||
filterFieldsByHypervisor([SIZE, TYPE, FORMAT, FILESYSTEM], hypervisor)
|
||||
filterFieldsByHypervisor(
|
||||
[SIZE, SIZEUNIT, TYPE, FORMAT, FILESYSTEM],
|
||||
hypervisor
|
||||
)
|
||||
|
||||
/**
|
||||
* @param {HYPERVISORS} hypervisor - hypervisor
|
||||
|
@ -19,7 +19,7 @@ import BasicConfiguration, {
|
||||
import AdvancedOptions, {
|
||||
STEP_ID as ADVANCED_ID,
|
||||
} from 'client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions'
|
||||
import { mapUserInputs, createSteps } from 'client/utils'
|
||||
import { mapUserInputs, createSteps, convertToMB } from 'client/utils'
|
||||
|
||||
const Steps = createSteps([BasicConfiguration, AdvancedOptions], {
|
||||
transformInitialValue: (disk = {}, schema) => ({
|
||||
@ -35,6 +35,10 @@ const Steps = createSteps([BasicConfiguration, AdvancedOptions], {
|
||||
const { [BASIC_ID]: configuration = {}, [ADVANCED_ID]: advanced = {} } =
|
||||
formData ?? {}
|
||||
|
||||
// ISSUE#6136: Convert size to MB (because XML API uses only MB) and delete sizeunit field (no needed on XML API)
|
||||
configuration.SIZE = convertToMB(configuration.SIZE, configuration.SIZEUNIT)
|
||||
delete configuration.SIZEUNIT
|
||||
|
||||
return { ...mapUserInputs(advanced), ...mapUserInputs(configuration) }
|
||||
},
|
||||
})
|
||||
|
@ -28,6 +28,7 @@ import {
|
||||
MEMORY_RESIZE_OPTIONS,
|
||||
T,
|
||||
VmTemplateFeatures,
|
||||
UNITS,
|
||||
} from 'client/constants'
|
||||
import { formatNumberByCurrency } from 'client/models/Helper'
|
||||
import { Field, arrayToOptions } from 'client/utils'
|
||||
@ -45,8 +46,8 @@ const { vcenter, lxc, firecracker } = HYPERVISORS
|
||||
/** @type {Field} Memory field */
|
||||
export const MEMORY = generateCapacityInput({
|
||||
name: 'MEMORY',
|
||||
label: [T.MemoryWithUnit, '(MB)'],
|
||||
tooltip: T.MemoryConcept,
|
||||
label: T.Memory,
|
||||
tooltip: T.MemoryConceptWithoutUnit,
|
||||
validation: commonValidation
|
||||
.integer()
|
||||
.required()
|
||||
@ -55,6 +56,26 @@ export const MEMORY = generateCapacityInput({
|
||||
),
|
||||
})
|
||||
|
||||
/**
|
||||
* @type {Field} size field
|
||||
* ISSUE#6136: Add unit size. Use only MB, GB, and TB (other values do not apply to create image).
|
||||
*/
|
||||
export const MEMORYUNIT = () => ({
|
||||
name: 'MEMORYUNIT',
|
||||
label: T.MemoryUnit,
|
||||
tooltip: T.MemoryConceptUnit,
|
||||
type: INPUT_TYPES.SELECT,
|
||||
grid: { md: 3 },
|
||||
values: arrayToOptions([UNITS.MB, UNITS.GB, UNITS.TB], {
|
||||
addEmpty: false,
|
||||
getText: (type) => type,
|
||||
getValue: (type) => type,
|
||||
}),
|
||||
validation: string()
|
||||
.trim()
|
||||
.default(() => UNITS.MB),
|
||||
})
|
||||
|
||||
/** @type {Field[]} Hot resize on memory field */
|
||||
export const HR_MEMORY_FIELDS = generateHotResizeInputs(
|
||||
{ name: 'MEMORY_HOT_ADD_ENABLED' },
|
||||
@ -69,7 +90,12 @@ export const HR_MEMORY_FIELDS = generateHotResizeInputs(
|
||||
export const MOD_MEMORY_FIELDS = generateModificationInputs(MEMORY.name)
|
||||
|
||||
/** @type {Field[]} List of memory fields */
|
||||
export const MEMORY_FIELDS = [MEMORY, ...HR_MEMORY_FIELDS, ...MOD_MEMORY_FIELDS]
|
||||
export const MEMORY_FIELDS = [
|
||||
MEMORY,
|
||||
MEMORYUNIT,
|
||||
...HR_MEMORY_FIELDS,
|
||||
...MOD_MEMORY_FIELDS,
|
||||
]
|
||||
|
||||
// --------------------------------------------------------
|
||||
// CPU fields
|
||||
|
@ -31,6 +31,7 @@ import {
|
||||
isBase64,
|
||||
encodeBase64,
|
||||
getUnknownAttributes,
|
||||
convertToMB,
|
||||
} from 'client/utils'
|
||||
import { T, MEMORY_RESIZE_OPTIONS } from 'client/constants'
|
||||
|
||||
@ -130,6 +131,10 @@ const Steps = createSteps([General, ExtraConfiguration, CustomVariables], {
|
||||
delete general.MEMORY_SLOTS
|
||||
}
|
||||
|
||||
// ISSUE#6136: Convert size to MB (because XML API uses only MB) and delete sizeunit field (no needed on XML API)
|
||||
general.MEMORY = convertToMB(general.MEMORY, general.MEMORYUNIT)
|
||||
delete general.MEMORYUNIT
|
||||
|
||||
return jsonToXml({
|
||||
...customVariables,
|
||||
...extraTemplate,
|
||||
|
@ -415,6 +415,7 @@ module.exports = {
|
||||
Upload: 'Upload',
|
||||
EmptyDisk: 'Empty disk image',
|
||||
ImageSize: 'Image size, in Megabytes',
|
||||
ImageSizeUnit: 'Image size',
|
||||
Vd: 'Virtio',
|
||||
Sd: 'SCSI/SATA',
|
||||
Hd: 'Parallel ATA (IDE)',
|
||||
@ -588,6 +589,8 @@ module.exports = {
|
||||
Name: 'Name',
|
||||
State: 'State',
|
||||
Size: 'Size',
|
||||
SizeUnit: 'Unit size',
|
||||
SizeUnitTooltip: 'Choose unit of size',
|
||||
SizeOnUnits: 'Size on %s',
|
||||
Description: 'Description',
|
||||
RegistrationTime: 'Registration time',
|
||||
@ -677,6 +680,7 @@ module.exports = {
|
||||
Sockets: 'Sockets',
|
||||
Memory: 'Memory',
|
||||
MemoryWithUnit: 'Memory %s',
|
||||
MemoryUnit: 'Unit memory',
|
||||
Cost: 'Cost',
|
||||
CostEachMonth: '%s / month',
|
||||
CostCpu: 'Cost / CPU',
|
||||
@ -817,6 +821,8 @@ module.exports = {
|
||||
AllowUsersToModifyMemory:
|
||||
"Allow users to modify this template's default memory on instantiate",
|
||||
MemoryConcept: 'Amount of RAM required for the VM, in Megabytes',
|
||||
MemoryConceptWithoutUnit: 'Amount of RAM required for the VM',
|
||||
MemoryConceptUnit: 'Choose unit of memory',
|
||||
CpuConcept: `
|
||||
Percentage of CPU divided by 100 required for the
|
||||
Virtual Machine. Half a processor is written 0.5`,
|
||||
|
@ -25,3 +25,4 @@ export * from 'client/utils/storage'
|
||||
export * from 'client/utils/string'
|
||||
export * from 'client/utils/number'
|
||||
export * from 'client/utils/translation'
|
||||
export * from 'client/utils/units'
|
||||
|
41
src/fireedge/src/client/utils/units.js
Normal file
41
src/fireedge/src/client/utils/units.js
Normal file
@ -0,0 +1,41 @@
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems *
|
||||
* *
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
|
||||
* not use this file except in compliance with the License. You may obtain *
|
||||
* a copy of the License at *
|
||||
* *
|
||||
* http://www.apache.org/licenses/LICENSE-2.0 *
|
||||
* *
|
||||
* Unless required by applicable law or agreed to in writing, software *
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, *
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
|
||||
* See the License for the specific language governing permissions and *
|
||||
* limitations under the License. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* File to define functions that do something about units
|
||||
*/
|
||||
|
||||
import { UNITS } from 'client/constants'
|
||||
|
||||
/**
|
||||
* Converts some MB, GB or TB to MB.
|
||||
*
|
||||
* @param {number} value - Numeric value
|
||||
* @param {string} unit - Type of unit (MB, GB or TB)
|
||||
* @returns {number} Value in MB
|
||||
*/
|
||||
export const convertToMB = (value, unit) => {
|
||||
switch (unit) {
|
||||
case UNITS.MB:
|
||||
return value
|
||||
case UNITS.GB:
|
||||
return value * 1024
|
||||
case UNITS.TB:
|
||||
return value * 1024 * 1024
|
||||
default:
|
||||
return value
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user