harvester-ui-extension/pkg/harvester/models/k8s.cni.cncf.io.networkattachmentdefinition.js
mergify[bot] c19341bec9
feat: support for HotPlugNICs from Kubevirt (#582) (#594)
* 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

---------


(cherry picked from commit f9bff21e840885a120679864a0ef312163bd48a7)

Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>
Co-authored-by: Yiya Chen <yiya.chen@suse.com>
2025-11-11 11:46:43 +08:00

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;
}
}
}