From cb9880f3a459d78b3a804e876061f0887f8972ca Mon Sep 17 00:00:00 2001 From: vichansson Date: Fri, 30 Oct 2026 13:59:56 +0200 Subject: [PATCH] F OpenNebula/one#8205: Show intersecting EVC opts (#4655) * Cluster creation dialog's EVC selector now only shows the intersecting CPU models from the selected hosts table. Signed-off-by: Victor Hansson --- .../src/modules/models/Host/general.js | 58 ++++++++++++------- .../Forms/CreateForm/Steps/Hosts/schema.js | 16 +++-- 2 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/fireedge/src/modules/models/Host/general.js b/src/fireedge/src/modules/models/Host/general.js index 0d2bb27c06..897e112da1 100644 --- a/src/fireedge/src/modules/models/Host/general.js +++ b/src/fireedge/src/modules/models/Host/general.js @@ -25,8 +25,6 @@ import { STATES, } from '@ConstantsModule' -import { uniq } from 'lodash' - /** * Returns information about the host state. * @@ -128,32 +126,48 @@ export const getPciDevices = (host) => * Returns list of KVM CPU Models available from the host pool. * * @param {Host[]} hosts - Hosts - * @param {boolean} common - If true, returns only common models + * @param {boolean} common - If true, returns the intersecting models between the set of hosts * @returns {Array} List of KVM CPU Models from the pool */ export const getKvmCpuModels = (hosts = [], common = false) => { - const hostData = hosts - .filter( - (host) => - host?.TEMPLATE?.HYPERVISOR === HYPERVISORS.kvm || - host?.TEMPLATE?.HYPERVISOR === HYPERVISORS.dummy - ) - .map((host) => host.TEMPLATE?.KVM_CPU_MODELS?.split(' ')) - .flat() - .filter(Boolean) + const cpuModels = hosts + .filter((host) => { + const t = host?.TEMPLATE + + return ( + t?.HYPERVISOR === HYPERVISORS.kvm || t?.HYPERVISOR === HYPERVISORS.dummy + ) + }) + .map((host) => { + let models = host?.TEMPLATE?.KVM_CPU_MODELS + + if (models == null || typeof models !== 'string') { + models = '' + } + + return models?.split(' ') + }) if (common) { - const hostDataFiltered = hostData.filter(Boolean) - if (!hostDataFiltered.length || hosts.length > hostDataFiltered.length) - return [] + let shortest = [] + for (const list of cpuModels) { + if (list.length && (!shortest.length || list.length < shortest.length)) { + shortest = list + } + } - return uniq(hostDataFiltered) + const modelSets = cpuModels.map((l) => new Set(l)) + + const modelIntersection = shortest.filter((cpuModel) => + modelSets.every((s) => s.has(cpuModel)) + ) + + return modelIntersection } - const hostDataFlatted = hostData.flat() + const allCpuModels = cpuModels.flat() - // Removes the repeated - return [...new Set(hostDataFlatted)] + return [...new Set(allCpuModels)] } /** @@ -185,7 +199,11 @@ export const getKvmCpuFeatures = (hosts = []) => { */ export const getKvmMachines = (hosts = []) => { const machineTypes = hosts - .filter((host) => host?.TEMPLATE?.HYPERVISOR === HYPERVISORS.kvm || host?.TEMPLATE?.HYPERVISOR === HYPERVISORS.dummy) + .filter( + (host) => + host?.TEMPLATE?.HYPERVISOR === HYPERVISORS.kvm || + host?.TEMPLATE?.HYPERVISOR === HYPERVISORS.dummy + ) .map((host) => host.TEMPLATE?.KVM_MACHINES?.split(' ') ?? []) .flat() diff --git a/src/fireedge/src/modules/resources/Cluster/Forms/CreateForm/Steps/Hosts/schema.js b/src/fireedge/src/modules/resources/Cluster/Forms/CreateForm/Steps/Hosts/schema.js index c6f8a68e23..7b9ff22ccf 100644 --- a/src/fireedge/src/modules/resources/Cluster/Forms/CreateForm/Steps/Hosts/schema.js +++ b/src/fireedge/src/modules/resources/Cluster/Forms/CreateForm/Steps/Hosts/schema.js @@ -49,15 +49,19 @@ const EVC_MODE = { } } }, + // IDs values: (selectedHosts = []) => { let options = [] - const { data: hosts = [] } = HostAPI.useGetHostsQuery() + const { data: hosts = [] } = HostAPI.useGetHostsQuery(undefined, { + selectFromResult: (result) => ({ + ...result, + data: [] + .concat(result?.data) + ?.filter((host) => selectedHosts?.includes(host?.ID)), + }), + }) - if (selectedHosts.length) { - const selectedHostsSet = new Set(selectedHosts) - const dataHosts = hosts.filter((host) => selectedHostsSet.has(host?.ID)) - options = getKvmCpuModels(dataHosts, true) - } + options = getKvmCpuModels(hosts, true) return arrayToOptions(options, { addEmpty: true,