mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
M #~: Fix CPU capacity with cpu_factor (#2291)
(cherry picked from commit de731ec3e260520144421109fc0e7ff522e61240)
This commit is contained in:
parent
62c265b502
commit
2785daf89b
@ -29,6 +29,8 @@ import { getActionsAvailable as getSectionsAvailable } from 'client/models/Helpe
|
||||
import { generateKey } from 'client/utils'
|
||||
import { T, RESOURCE_NAMES, VmTemplate } from 'client/constants'
|
||||
|
||||
let generalFeatures
|
||||
|
||||
export const STEP_ID = 'general'
|
||||
|
||||
const Content = ({ isUpdate }) => {
|
||||
@ -42,6 +44,8 @@ const Content = ({ isUpdate }) => {
|
||||
const dialog = dialogs?.create_dialog
|
||||
const sectionsAvailable = getSectionsAvailable(dialog, hypervisor)
|
||||
|
||||
generalFeatures = features
|
||||
|
||||
return (
|
||||
SECTIONS(hypervisor, isUpdate, features)
|
||||
.filter(
|
||||
@ -83,7 +87,7 @@ const General = (vmTemplate) => {
|
||||
resolver: (formData) => {
|
||||
const hypervisor = formData?.[STEP_ID]?.HYPERVISOR ?? initialHypervisor
|
||||
|
||||
return SCHEMA(hypervisor, isUpdate)
|
||||
return SCHEMA(hypervisor, isUpdate, generalFeatures)
|
||||
},
|
||||
optionsValidate: { abortEarly: false },
|
||||
content: () => Content({ isUpdate }),
|
||||
|
@ -96,11 +96,13 @@ const SECTIONS = (hypervisor, isUpdate, features) =>
|
||||
|
||||
/**
|
||||
* @param {HYPERVISORS} [hypervisor] - Template hypervisor
|
||||
* @param {boolean} [isUpdate] - If `true`, the form is being updated
|
||||
* @param {VmTemplateFeatures} [features] - Features
|
||||
* @returns {BaseSchema} Step schema
|
||||
*/
|
||||
const SCHEMA = (hypervisor) =>
|
||||
const SCHEMA = (hypervisor, isUpdate, features) =>
|
||||
getObjectSchemaFromFields(
|
||||
SECTIONS(hypervisor)
|
||||
SECTIONS(hypervisor, isUpdate, features)
|
||||
.map(({ fields }) => fields)
|
||||
.flat()
|
||||
)
|
||||
|
@ -13,13 +13,14 @@
|
||||
* See the License for the specific language governing permissions and *
|
||||
* limitations under the License. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
import { useMemo } from 'react'
|
||||
import { useMemo, useEffect } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { useViews } from 'client/features/Auth'
|
||||
import { useFormContext } from 'react-hook-form'
|
||||
import { scaleVcpuByCpuFactor } from 'client/models/VirtualMachine'
|
||||
import FormWithSchema from 'client/components/Forms/FormWithSchema'
|
||||
import useStyles from 'client/components/Forms/VmTemplate/InstantiateForm/Steps/BasicConfiguration/styles'
|
||||
|
||||
import {
|
||||
SCHEMA,
|
||||
SECTIONS,
|
||||
@ -27,24 +28,44 @@ import {
|
||||
import { getActionsAvailable as getSectionsAvailable } from 'client/models/Helper'
|
||||
import { T, RESOURCE_NAMES, VmTemplate } from 'client/constants'
|
||||
|
||||
let generalFeatures
|
||||
|
||||
export const STEP_ID = 'configuration'
|
||||
|
||||
const Content = ({ vmTemplate }) => {
|
||||
const classes = useStyles()
|
||||
const { view, getResourceView } = useViews()
|
||||
const { getValues, setValue } = useFormContext()
|
||||
|
||||
const resource = RESOURCE_NAMES.VM_TEMPLATE
|
||||
const { features, dialogs } = getResourceView(resource)
|
||||
|
||||
const sections = useMemo(() => {
|
||||
const hypervisor = vmTemplate?.TEMPLATE?.HYPERVISOR
|
||||
const resource = RESOURCE_NAMES.VM_TEMPLATE
|
||||
const { features, dialogs } = getResourceView(resource)
|
||||
const dialog = dialogs?.instantiate_dialog
|
||||
const sectionsAvailable = getSectionsAvailable(dialog, hypervisor)
|
||||
|
||||
generalFeatures = features
|
||||
|
||||
return SECTIONS(vmTemplate, features).filter(
|
||||
({ id, required }) => required || sectionsAvailable.includes(id)
|
||||
)
|
||||
}, [view])
|
||||
|
||||
useEffect(() => {
|
||||
if (vmTemplate?.TEMPLATE?.VCPU && features?.cpu_factor) {
|
||||
const oldValues = {
|
||||
...getValues(),
|
||||
}
|
||||
oldValues.configuration.CPU = `${scaleVcpuByCpuFactor(
|
||||
vmTemplate.TEMPLATE.VCPU,
|
||||
features.cpu_factor
|
||||
)}`
|
||||
|
||||
setValue(`${STEP_ID}`, oldValues)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
{sections.map(({ id, legend, fields }) => (
|
||||
@ -74,7 +95,7 @@ Content.propTypes = {
|
||||
const BasicConfiguration = (vmTemplate) => ({
|
||||
id: STEP_ID,
|
||||
label: T.Configuration,
|
||||
resolver: () => SCHEMA(vmTemplate),
|
||||
resolver: () => SCHEMA(vmTemplate, generalFeatures),
|
||||
optionsValidate: { abortEarly: false },
|
||||
content: (props) => Content({ ...props, vmTemplate }),
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user