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

B OpenNebula/one#6757: Add missing boot order (#3325)

Signed-off-by: Victor Hansson <vhansson@opennebula.io>
Co-authored-by: Tino Vázquez <cvazquez@opennebula.io>
This commit is contained in:
vichansson 2024-12-11 14:58:00 +02:00 committed by GitHub
parent 5aebf691e3
commit 983d797ff0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 63 additions and 16 deletions

View File

@ -15,20 +15,23 @@
* ------------------------------------------------------------------------- */
import { ReactElement, useMemo } from 'react'
import PropTypes from 'prop-types'
import { Stack } from '@mui/material'
import { Stack, FormControl } from '@mui/material'
import Legend from 'client/components/Forms/Legend'
import { BootOrder } from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration'
import FormWithSchema from 'client/components/Forms/FormWithSchema'
import { SECTIONS } from 'client/components/Forms/Vm/UpdateConfigurationForm/booting/schema'
import { HYPERVISORS } from 'client/constants'
import { HYPERVISORS, T } from 'client/constants'
/**
* @param {object} props - Component props
* @param {HYPERVISORS} props.hypervisor - VM hypervisor
* @param {object} props.oneConfig - Config of oned.conf
* @param {boolean} props.adminGroup - User is admin or not
* @param {object} props.vm - VM template
* @returns {ReactElement} OS section component
*/
const OsSection = ({ hypervisor, oneConfig, adminGroup }) => {
const OsSection = ({ hypervisor, oneConfig, adminGroup, vm }) => {
const enableBootOrder = !!vm?.TEMPLATE?.DISK || !!vm?.TEMPLATE?.NIC
const sections = useMemo(
() => SECTIONS({ hypervisor, oneConfig, adminGroup }),
[hypervisor]
@ -40,6 +43,15 @@ const OsSection = ({ hypervisor, oneConfig, adminGroup }) => {
gap="1em"
sx={{ gridTemplateColumns: { sm: '1fr', md: '1fr 1fr' } }}
>
{enableBootOrder && (
<FormControl
component="fieldset"
sx={{ width: '100%', gridColumn: '1 / span 2', gridRow: '1' }}
>
<Legend title={T.BootOrder} tooltip={T.BootOrderConcept} />
<BootOrder />
</FormControl>
)}
{sections.map(({ id, ...section }) => (
<FormWithSchema key={id} cy={id} {...section} />
))}
@ -51,6 +63,7 @@ OsSection.propTypes = {
hypervisor: PropTypes.string,
oneConfig: PropTypes.object,
adminGroup: PropTypes.bool,
vm: PropTypes.object,
}
export default OsSection

View File

@ -37,9 +37,10 @@ import { T, HYPERVISORS } from 'client/constants'
* @param {HYPERVISORS} props.hypervisor - VM hypervisor
* @param {object} props.oneConfig - OpenNEbula configuration
* @param {boolean} props.adminGroup - If the user is admin
* @param {object} props.vm - VM template
* @returns {ReactElement} Form content component
*/
const Content = ({ hypervisor, oneConfig, adminGroup }) => {
const Content = ({ hypervisor, oneConfig, adminGroup, vm }) => {
const {
formState: { errors },
} = useFormContext()
@ -55,6 +56,7 @@ const Content = ({ hypervisor, oneConfig, adminGroup }) => {
hypervisor={hypervisor}
oneConfig={oneConfig}
adminGroup={adminGroup}
vm={vm}
/>
),
error: !!errors?.OS,
@ -107,6 +109,7 @@ Content.propTypes = {
hypervisor: PropTypes.string,
oneConfig: PropTypes.object,
adminGroup: PropTypes.bool,
vm: PropTypes.object,
}
export default Content

View File

@ -15,6 +15,7 @@
* ------------------------------------------------------------------------- */
import { reach } from 'yup'
import { set } from 'lodash'
import { SCHEMA } from 'client/components/Forms/Vm/UpdateConfigurationForm/schema'
import ContentForm from 'client/components/Forms/Vm/UpdateConfigurationForm/content'
import {
@ -30,7 +31,8 @@ const UpdateConfigurationForm = createForm(SCHEMA, undefined, {
const template = vmTemplate?.TEMPLATE ?? {}
const context = template?.CONTEXT ?? {}
const backupConfig = vmTemplate?.BACKUPS?.BACKUP_CONFIG ?? {}
const bootOrder = template?.OS?.BOOT
const nics = [].concat(template?.NIC ?? []).flat()
const knownTemplate = schema.cast(
{ ...vmTemplate, ...template },
{ stripUnknown: true, context: { ...template } }
@ -72,16 +74,40 @@ const UpdateConfigurationForm = createForm(SCHEMA, undefined, {
...getUnknownAttributes(backupConfig, knownBackupConfig),
}
// Easy compatibility with the bootOrder component by specifying the same form paths as in the VM Template
!!bootOrder && set(knownTemplate, 'extra.OS.BOOT', bootOrder)
!!template?.DISK &&
set(
knownTemplate,
'extra.DISK',
template?.DISK?.map((disk) => ({
...disk,
NAME: `DISK${disk?.DISK_ID}`,
}))
)
!!nics?.length && set(knownTemplate, 'extra.NIC', nics)
return knownTemplate
},
transformBeforeSubmit: (formData) => {
const { extra, ...restFormData } = formData
// Encode script on base 64, if needed, on context section
if (isBase64(formData?.CONTEXT?.START_SCRIPT)) {
formData.CONTEXT.START_SCRIPT_BASE64 = formData?.CONTEXT?.START_SCRIPT
delete formData?.CONTEXT?.START_SCRIPT
} else {
delete formData?.CONTEXT?.START_SCRIPT_BASE64
const updatedFormData = {
...restFormData,
OS: {
...restFormData.OS,
BOOT: extra?.OS?.BOOT || restFormData.OS?.BOOT,
},
}
if (isBase64(updatedFormData?.CONTEXT?.START_SCRIPT)) {
updatedFormData.CONTEXT.START_SCRIPT_BASE64 =
updatedFormData?.CONTEXT?.START_SCRIPT
delete updatedFormData?.CONTEXT?.START_SCRIPT
} else {
delete updatedFormData?.CONTEXT?.START_SCRIPT_BASE64
}
return updatedFormData
},
})

View File

@ -131,7 +131,9 @@ const BootOrder = () => {
const nics = useMemo(() => {
const nicId = `${EXTRA_ID}.${NIC_ID[0]}`
const nicValues = getValues([nicId]).flat()
const nicValues = getValues([nicId])
.flat()
.filter((nic) => !!nic) // Strips internal undefined
return (
nicValues?.map((nic, idx) => ({
@ -139,7 +141,7 @@ const BootOrder = () => {
NAME: (
<>
<NetworkIcon />
{[nic?.NAME, nic.NETWORK].filter(Boolean).join(': ')}
{[nic?.NAME, nic?.NETWORK].filter(Boolean).join(': ')}
</>
),
})) ?? []

View File

@ -107,4 +107,4 @@ const TAB = {
export default TAB
export { reorderBootAfterRemove, BOOT_ORDER_NAME }
export { reorderBootAfterRemove, BOOT_ORDER_NAME, BootOrder }

View File

@ -29,7 +29,9 @@ import Storage from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraCo
import Networking from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/networking'
import Placement from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/placement'
import ScheduleAction from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/scheduleAction'
import Booting from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/booting'
import Booting, {
BootOrder,
} from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/booting'
import Context from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context'
import Pci from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/pci'
import InputOutput from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput'
@ -214,4 +216,5 @@ Content.propTypes = {
isVrouter: PropTypes.bool,
}
export { BootOrder }
export default ExtraConfiguration

View File

@ -135,7 +135,7 @@ const VmConfigurationTab = ({
},
form: () =>
UpdateConfigurationForm({
stepProps: { hypervisor, oneConfig, adminGroup },
stepProps: { hypervisor, oneConfig, adminGroup, vm },
initialValues: vm,
}),
onSubmit: handleUpdateConf,