harvester-ui-extension/pkg/harvester/models/harvesterhci.io.blockdevice.js
andy.lee 18bfbbaac1 fix unable to add/delete new hard disk
Signed-off-by: andy.lee <andy.lee@suse.com>
(cherry picked from commit cbb66175f6dda835f557dd098103fc1d78b53468)
2025-02-07 03:23:49 +00:00

74 lines
1.8 KiB
JavaScript

import { HCI } from '../types';
import HarvesterResource from './harvester';
export default class HciBlockDevice extends HarvesterResource {
get childParts() {
const inStore = this.$rootGetters['currentProduct'].inStore;
const bds = this.$rootGetters[`${ inStore }/all`](HCI.BLOCK_DEVICE);
const parts = bds.filter((b) => {
return b.status?.deviceStatus?.parentDevice === this.spec?.devPath &&
b.spec.nodeName === this.spec.nodeName;
});
return parts;
}
get isChildPartProvisioned() {
const parts = this.childParts.filter((p) => p.isProvisioned) || [];
return parts.length > 0;
}
get provisionPhase() {
const label = this?.status?.provisionPhase;
let color = '';
let icon = '';
switch (label) {
case 'Provisioned':
color = 'bg-success';
icon = 'icon-checkmark';
break;
case 'Unprovisioning':
color = 'bg-warning';
icon = 'icon-warning';
break;
case 'NotProvisioned':
color = 'bg-error';
icon = 'icon-warning';
break;
default:
break;
}
return {
label,
color,
icon,
};
}
get displayName() {
return this.status?.deviceStatus?.devPath || this?.metadata?.name;
}
get isFormatting() {
const conditions = this?.status?.conditions || [];
const formatting = conditions.find((c) => c.type === 'Formatting') || {};
return formatting.status === 'True';
}
get isProvisioned() {
// spec.fileSystem.provisioned is deprecated
return this.spec?.fileSystem?.provisioned || this.spec?.provision;
}
// Overwrite cleanForSave() in shell/plugins/steve/steve-class.js as it deleted status object in harvesterhci.io.blockdevice CRD
// but /v1/harvester/harvesterhci.io.blockdevices/longhorn-system/{id} API requires status object
cleanForSave(data) {
return data;
}
}