mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2025-12-13 13:11:43 +00:00
* refactor: rename hotplug volume * feat: add hotplug NIC * feat: add hot unplug * refactor: rename NIC * feat: get latest status * feat: disable not ready options * feat: filter out system networks * refactor: update wordings --------- Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>
102 lines
2.2 KiB
JavaScript
102 lines
2.2 KiB
JavaScript
import SteveModel from '@shell/plugins/steve/steve-class';
|
|
import { HCI } from '@shell/config/labels-annotations';
|
|
import { NETWORK_TYPE } from '../config/types';
|
|
|
|
const { UNTAGGED, OVERLAY, L2TRUNK_VLAN } = NETWORK_TYPE;
|
|
|
|
export default class NetworkAttachmentDef extends SteveModel {
|
|
applyDefaults() {
|
|
const spec = this.spec || {
|
|
config: JSON.stringify({
|
|
cniVersion: '0.3.1',
|
|
name: '',
|
|
type: 'bridge',
|
|
bridge: '',
|
|
promiscMode: true,
|
|
vlan: '',
|
|
ipam: {}
|
|
})
|
|
};
|
|
|
|
this.spec = spec;
|
|
}
|
|
|
|
get parseConfig() {
|
|
try {
|
|
return JSON.parse(this.spec.config) || {};
|
|
} catch (err) {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
get isSystem() {
|
|
const systemNamespaces = this.$rootGetters['systemNamespaces'];
|
|
|
|
if (systemNamespaces.includes(this.metadata?.namespace)) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
get isIpamStatic() {
|
|
return this.parseConfig.ipam?.type === 'static';
|
|
}
|
|
|
|
get clusterNetwork() {
|
|
return this?.metadata?.labels?.[HCI.CLUSTER_NETWORK];
|
|
}
|
|
|
|
get vlanType() {
|
|
const labels = this.metadata?.labels || {};
|
|
const type = labels[HCI.NETWORK_TYPE];
|
|
|
|
return type;
|
|
}
|
|
|
|
get vlanId() {
|
|
return this.vlanType === UNTAGGED || this.vlanType === OVERLAY || this.vlanType === L2TRUNK_VLAN ? 'N/A' : this.parseConfig.vlan;
|
|
}
|
|
|
|
get customValidationRules() {
|
|
const rules = [
|
|
{
|
|
nullable: false,
|
|
path: 'metadata.name',
|
|
required: true,
|
|
minLength: 1,
|
|
maxLength: 63,
|
|
translationKey: 'harvester.fields.name'
|
|
}
|
|
];
|
|
|
|
return rules;
|
|
}
|
|
|
|
get connectivity() {
|
|
const annotations = this.metadata?.annotations || {};
|
|
const route = annotations[HCI.NETWORK_ROUTE];
|
|
let config = {};
|
|
|
|
if (this.vlanType === UNTAGGED || this.vlanType === OVERLAY || this.vlanType === L2TRUNK_VLAN) {
|
|
return 'N/A';
|
|
}
|
|
|
|
try {
|
|
config = JSON.parse(route || '{}');
|
|
} catch {
|
|
return 'invalid';
|
|
}
|
|
|
|
const connectivity = config.connectivity;
|
|
|
|
if (connectivity === 'false') {
|
|
return 'inactive';
|
|
} else if (connectivity === 'true') {
|
|
return 'active';
|
|
} else {
|
|
return connectivity;
|
|
}
|
|
}
|
|
}
|