Update selected vGpus devices adding the provisioned devices

Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
This commit is contained in:
Francesco Torchia 2024-09-18 00:07:52 +02:00
parent fa545ad134
commit 8117e99b54
No known key found for this signature in database
GPG Key ID: E6D011B7415D4393
3 changed files with 17 additions and 2 deletions

View File

@ -51,5 +51,6 @@ export const HCI = {
PARENT_SRIOV_GPU: 'harvesterhci.io/parentSRIOVGPUDevice',
VM_MAINTENANCE_MODE_STRATEGY: 'harvesterhci.io/maintain-mode-strategy',
NODE_CPU_MANAGER_UPDATE_STATUS: 'harvesterhci.io/cpu-manager-update-status',
CPU_MANAGER: 'cpumanager'
CPU_MANAGER: 'cpumanager',
VM_DEVICE_ALLOCATION_DETAILS: 'harvesterhci.io/deviceAllocationDetails',
};

View File

@ -8,6 +8,7 @@ import remove from 'lodash/remove';
import { set } from '@shell/utils/object';
import { HCI } from '../../../types';
import VGpuDeviceList from './VGpuDeviceList';
import { uniq } from '@shell/utils/array';
export default {
name: 'VirtualMachineVGpuDevices',
@ -45,7 +46,10 @@ export default {
this[key] = res[key];
}
(this.value?.domain?.devices?.gpus || []).forEach(({ name }) => {
uniq([
...(this.value?.domain?.devices?.gpus || []).map(({ name }) => name),
...Object.values(this.vm?.provisionedVGpus).reduce((acc, gpus) => [...acc, ...gpus], [])
]).forEach((name) => {
if (this.enabledDevices.find(device => device?.metadata?.name === name)) {
this.selectedDevices.push(name);
}

View File

@ -1098,6 +1098,16 @@ export default class VirtVm extends HarvesterResource {
return this.spec?.template?.spec?.domain?.devices?.hostDevices || [];
}
get provisionedVGpus() {
try {
const deviceAllocationDetails = JSON.parse(this.metadata?.annotations[HCI_ANNOTATIONS.VM_DEVICE_ALLOCATION_DETAILS] || '{}');
return deviceAllocationDetails?.gpus || {};
} catch (error) {
return {};
}
}
setInstanceLabels(val) {
if ( !this.spec?.template?.metadata?.labels ) {
set(this, 'spec.template.metadata.labels', {});