import React, { useState } from 'react'; import { Button, Title, Divider, PageSection } from '@patternfly/react-core'; import { translate as __ } from 'foremanReact/common/I18n'; import PropTypes from 'prop-types'; import InputField from '../common/FormInputs'; import ProxmoxComputeSelectors from '../ProxmoxComputeSelectors'; import CPUFlagsModal from './components/CPUFlagsModal'; const cpuFlagsHash = [ { key: 'md_clear', label: 'md-clear' }, { key: 'pcid', label: 'pcid' }, { key: 'spectre', label: 'spec-ctrl' }, { key: 'ssbd', label: 'ssbd' }, { key: 'ibpb', label: 'ibpb' }, { key: 'virt_ssbd', label: 'virt-ssbd' }, { key: 'amd_ssbd', label: 'amd-ssbd' }, { key: 'amd_no_ssb', label: 'amd-no-ssb' }, { key: 'pdpe1gb', label: 'pdpe1gb' }, { key: 'hv_tlbflush', label: 'hv-tlbflush' }, { key: 'hv_evmcs', label: 'hv-evmcs' }, { key: 'aes', label: 'aes' }, ]; const cpuFlagDescriptions = { md_clear: __( 'Required to let the guest OS know if MDS is mitigated correctly' ), pcid: __( 'Meltdown fix cost reduction on Westmere, Sandy-, and IvyBridge Intel CPUs' ), spectre: __('Allows improved Spectre mitigation with Intel CPUs'), ssbd: __('Protection for "Speculative Store Bypass" for Intel models'), ibpb: __('Allows improved Spectre mitigation with AMD CPUs'), virt_ssbd: __( 'Basis for "Speculative Store Bypass" protection for AMD models' ), amd_ssbd: __( 'Improves Spectre mitigation performance with AMD CPUs, best used with "virt-ssbd"' ), amd_no_ssb: __( 'Notifies guest OS that host is not vulnerable for Spectre on AMD CPUs' ), pdpe1gb: __('Allow guest OS to use 1GB size pages, if host HW supports it'), hv_tlbflush: __( 'Improve performance in overcommitted Windows guests. May lead to guest bluescreens on old CPUs.' ), hv_evmcs: __( 'Improve performance for nested virtualization. Only supported on Intel CPUs.' ), aes: __('Activate AES instruction set for HW accelaration.'), }; const filterAndAddDescriptions = hardware => cpuFlagsHash.reduce((acc, { key, label }) => { if (key in hardware) { acc[key] = { ...hardware[key], description: cpuFlagDescriptions[key] || '', label, }; } return acc; }, {}); const ProxmoxServerHardware = ({ hardware }) => { const [hw, setHw] = useState(hardware); const [isModalOpen, setIsModalOpen] = useState(false); const handleChange = e => { const { name, type, checked, value: targetValue } = e.target; let value; if (type === 'checkbox') { value = checked ? '1' : '0'; } else { value = targetValue; } const updatedKey = Object.keys(hw).find(key => hw[key].name === name); setHw(prevHw => ({ ...prevHw, [updatedKey]: { ...prevHw[updatedKey], value }, })); }; const handleModalToggle = _event => { setIsModalOpen(prevIsModalOpen => !prevIsModalOpen); }; const cpuFlags = filterAndAddDescriptions(hw); return (