mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2025-12-13 13:11:43 +00:00
Refactoring devices models
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
This commit is contained in:
parent
890686741f
commit
2ec5ebb373
@ -7,7 +7,7 @@ import CompatibilityMatrix from '../CompatibilityMatrix';
|
||||
import DeviceList from './DeviceList';
|
||||
|
||||
import remove from 'lodash/remove';
|
||||
import { get, set } from '@shell/utils/object';
|
||||
import { set } from '@shell/utils/object';
|
||||
import { HCI } from '../../../types';
|
||||
import DeviceList from './DeviceList';
|
||||
import CompatibilityMatrix from './CompatibilityMatrix';
|
||||
@ -123,9 +123,8 @@ export default {
|
||||
if (vm.metadata.name === this.vm?.metadata?.name) {
|
||||
return inUse;
|
||||
}
|
||||
const devices = get(vm, 'spec.template.spec.domain.devices.hostDevices') || [];
|
||||
|
||||
devices.forEach((device) => {
|
||||
vm.hostDevices.forEach((device) => {
|
||||
inUse[device.name] = { usedBy: [vm.metadata.name] };
|
||||
});
|
||||
|
||||
@ -136,19 +135,14 @@ export default {
|
||||
},
|
||||
|
||||
devicesByNode() {
|
||||
const out = {};
|
||||
return this.enabledDevices?.reduce((acc, device) => {
|
||||
const name = device.status?.nodeName;
|
||||
|
||||
this.enabledDevices.forEach((deviceCRD) => {
|
||||
const nodeName = deviceCRD.status?.nodeName;
|
||||
|
||||
if (!out[nodeName]) {
|
||||
out[nodeName] = [deviceCRD];
|
||||
} else {
|
||||
out[nodeName].push(deviceCRD);
|
||||
}
|
||||
});
|
||||
|
||||
return out;
|
||||
return name ? {
|
||||
...acc,
|
||||
[name]: [...(acc[name] || []), device],
|
||||
} : acc;
|
||||
}, {});
|
||||
},
|
||||
|
||||
// determine which nodes contain all devices selected
|
||||
|
||||
@ -9,7 +9,7 @@ import CompatibilityMatrix from '../CompatibilityMatrix';
|
||||
import DeviceList from './DeviceList';
|
||||
|
||||
import remove from 'lodash/remove';
|
||||
import { get, set } from '@shell/utils/object';
|
||||
import { set } from '@shell/utils/object';
|
||||
|
||||
export default {
|
||||
name: 'VirtualMachineUSBDevices',
|
||||
@ -120,9 +120,8 @@ export default {
|
||||
if (vm.metadata.name === this.vm?.metadata?.name) {
|
||||
return inUse;
|
||||
}
|
||||
const devices = get(vm, 'spec.template.spec.domain.devices.hostDevices') || [];
|
||||
|
||||
devices.forEach((device) => {
|
||||
vm.hostDevices.forEach((device) => {
|
||||
inUse[device.name] = { usedBy: [vm.metadata.name] };
|
||||
});
|
||||
|
||||
@ -133,19 +132,14 @@ export default {
|
||||
},
|
||||
|
||||
devicesByNode() {
|
||||
const out = {};
|
||||
return this.enabledDevices?.reduce((acc, device) => {
|
||||
const name = device.status?.nodeName;
|
||||
|
||||
this.enabledDevices.forEach((deviceCRD) => {
|
||||
const nodeName = deviceCRD.status?.nodeName;
|
||||
|
||||
if (!out[nodeName]) {
|
||||
out[nodeName] = [deviceCRD];
|
||||
} else {
|
||||
out[nodeName].push(deviceCRD);
|
||||
}
|
||||
});
|
||||
|
||||
return out;
|
||||
return name ? {
|
||||
...acc,
|
||||
[name]: [...(acc[name] || []), device],
|
||||
} : acc;
|
||||
}, {});
|
||||
},
|
||||
|
||||
compatibleNodes() {
|
||||
|
||||
@ -5,7 +5,7 @@ import LabeledSelect from '@shell/components/form/LabeledSelect';
|
||||
import Banner from '@components/Banner/Banner.vue';
|
||||
|
||||
import remove from 'lodash/remove';
|
||||
import { get, set } from '@shell/utils/object';
|
||||
import { set } from '@shell/utils/object';
|
||||
import { HCI } from '../../../types';
|
||||
import VGpuDeviceList from './VGpuDeviceList';
|
||||
|
||||
@ -89,9 +89,8 @@ export default {
|
||||
if (vm.metadata.name === this.vm?.metadata?.name) {
|
||||
return inUse;
|
||||
}
|
||||
const devices = get(vm, 'spec.template.spec.domain.devices.hostDevices') || [];
|
||||
|
||||
devices.forEach((device) => {
|
||||
vm.hostDevices.forEach((device) => {
|
||||
inUse[device.name] = { usedBy: [vm.metadata.name] };
|
||||
});
|
||||
|
||||
@ -102,19 +101,14 @@ export default {
|
||||
},
|
||||
|
||||
devicesByNode() {
|
||||
const out = {};
|
||||
return this.enabledDevices?.reduce((acc, device) => {
|
||||
const name = device.spec?.nodeName;
|
||||
|
||||
this.enabledDevices.forEach((deviceCRD) => {
|
||||
const nodeName = deviceCRD.spec?.nodeName;
|
||||
|
||||
if (!out[nodeName]) {
|
||||
out[nodeName] = [deviceCRD];
|
||||
} else {
|
||||
out[nodeName].push(deviceCRD);
|
||||
}
|
||||
});
|
||||
|
||||
return out;
|
||||
return name ? {
|
||||
...acc,
|
||||
[name]: [...(acc[name] || []), device],
|
||||
} : acc;
|
||||
}, {});
|
||||
},
|
||||
|
||||
compatibleNodes() {
|
||||
|
||||
@ -1078,6 +1078,10 @@ export default class VirtVm extends HarvesterResource {
|
||||
});
|
||||
}
|
||||
|
||||
get hostDevices() {
|
||||
return this.spec?.template?.spec?.domain?.devices?.hostDevices || [];
|
||||
}
|
||||
|
||||
setInstanceLabels(val) {
|
||||
if ( !this.spec?.template?.metadata?.labels ) {
|
||||
set(this, 'spec.template.metadata.labels', {});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user