1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

M #-: Fix issue about cpu when a regular user instaniate a vm ()

Signed-off-by: David Carracedo <dcarracedo@opennebula.io>
This commit is contained in:
David 2024-05-24 15:14:25 +02:00 committed by GitHub
parent 3fd8268ddc
commit ef24877637
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 22 deletions
src/fireedge/src/client
components/Forms/VmTemplate/InstantiateForm/Steps/BasicConfiguration
containers/VmTemplates
utils/parser

View File

@ -14,7 +14,7 @@
* limitations under the License. *
* ------------------------------------------------------------------------- */
import PropTypes from 'prop-types'
import { useEffect, useMemo } from 'react'
import { useMemo } from 'react'
import FormWithSchema from 'client/components/Forms/FormWithSchema'
import {
@ -25,8 +25,6 @@ import useStyles from 'client/components/Forms/VmTemplate/InstantiateForm/Steps/
import { RESOURCE_NAMES, T, VmTemplate } from 'client/constants'
import { useViews } from 'client/features/Auth'
import { getActionsAvailable as getSectionsAvailable } from 'client/models/Helper'
import { scaleVcpuByCpuFactor } from 'client/models/VirtualMachine'
import { useFormContext } from 'react-hook-form'
let generalFeatures
@ -35,7 +33,6 @@ export const STEP_ID = 'general'
const Content = ({ vmTemplate, oneConfig, adminGroup }) => {
const classes = useStyles()
const { view, getResourceView } = useViews()
const { getValues, setValue } = useFormContext()
const resource = RESOURCE_NAMES.VM_TEMPLATE
const { features, dialogs } = getResourceView(resource)
@ -52,20 +49,6 @@ const Content = ({ vmTemplate, oneConfig, adminGroup }) => {
)
}, [view])
useEffect(() => {
if (vmTemplate?.TEMPLATE?.VCPU && features?.cpu_factor) {
const oldValues = {
...getValues(),
}
oldValues.general.CPU = `${scaleVcpuByCpuFactor(
vmTemplate.TEMPLATE.VCPU,
features.cpu_factor
)}`
setValue(`${STEP_ID}`, oldValues)
}
}, [])
return (
<div className={classes.root}>
{sections.map(({ id, legend, fields }) => (

View File

@ -32,13 +32,13 @@ import {
} from 'client/components/FormStepper'
import { InstantiateForm } from 'client/components/Forms/VmTemplate'
import { useSystemData } from 'client/features/Auth'
import { useSystemData, useViews } from 'client/features/Auth'
import { jsonToXml } from 'client/models/Helper'
import {
filterTemplateData,
transformActionsInstantiate,
} from 'client/utils/parser'
import { TAB_FORM_MAP } from 'client/constants'
import { TAB_FORM_MAP, RESOURCE_NAMES } from 'client/constants'
const _ = require('lodash')
@ -84,6 +84,11 @@ function InstantiateVmTemplate() {
useGetUsersQuery(undefined, { refetchOnMountOrArgChange: false })
useGetGroupsQuery(undefined, { refetchOnMountOrArgChange: false })
// Features of the view
const { getResourceView } = useViews()
const resource = RESOURCE_NAMES.VM_TEMPLATE
const { features } = getResourceView(resource)
const onSubmit = async (templates) => {
try {
// Get current state and modified fields
@ -110,7 +115,11 @@ function InstantiateVmTemplate() {
)
// Every action that is not an human action
transformActionsInstantiate(filteredTemplate, apiTemplateData)
transformActionsInstantiate(
filteredTemplate,
apiTemplateData,
features
)
// Convert template to xml
const xmlFinal = jsonToXml(filteredTemplate)

View File

@ -17,6 +17,7 @@ import _, { cloneDeep, merge, get } from 'lodash'
import { convertToMB, isBase64 } from 'client/utils'
import { MEMORY_RESIZE_OPTIONS, T } from 'client/constants'
import { transformXmlString } from 'client/models/Helper'
import { scaleVcpuByCpuFactor } from 'client/models/VirtualMachine'
// Attributes that will be always modify with the value of the form (except Storage, Network and PCI sections)
const alwaysIncludeAttributes = {
@ -674,10 +675,16 @@ const transformActionsCreate = (template) => {
*
* @param {object} template - Template with data
* @param {object} original - Initial values of the template
* @param {object} features - Features from the user's view
*/
const transformActionsInstantiate = (template, original) => {
const transformActionsInstantiate = (template, original, features) => {
transformActionsCommon(template)
// Calculate CPU is needed
if (template?.VCPU && features?.cpu_factor) {
template.CPU = scaleVcpuByCpuFactor(template.VCPU, features.cpu_factor)
}
original?.TEMPLATE?.OS &&
template?.OS &&
(template.OS = {