add lock icon in VM list page

This commit is contained in:
andy.lee 2024-09-16 13:54:56 +08:00 committed by Francesco Torchia
parent d06f0ec989
commit 6ce99fad1f
No known key found for this signature in database
GPG Key ID: E6D011B7415D4393
5 changed files with 54 additions and 15 deletions

View File

@ -63,10 +63,7 @@ export default {
imageName() {
const imageList = this.$store.getters['harvester/all'](HCI.IMAGE) || [];
const image = imageList.find( (I) => {
return this.value.rootImageId === I.id;
});
const image = imageList.find( I => this.value.rootImageId === I.id);
return image?.spec?.displayName || 'N/A';
},

View File

@ -640,6 +640,10 @@ harvester:
userTips: The user to be added must already exist; otherwise, the credentials will not take effect.
duplicatedUser: User already exists.
invalidUser: Invalid Username.
lockIconTooltip:
image: Image encrypted
volume: Volume encrypted
both: Image encrypted and volume encrypted
input:
name: Name
memory: Memory

View File

@ -1,9 +1,7 @@
<script>
import ResourceTable from '@shell/components/ResourceTable';
import LinkDetail from '@shell/components/formatter/LinkDetail';
import { STATE, AGE, NAME, NAMESPACE } from '@shell/config/table-headers';
import { NODE, POD } from '@shell/config/types';
import { PVC, PV, NODE, POD } from '@shell/config/types';
import { allHash } from '@shell/utils/promise';
import Loading from '@shell/components/Loading';
@ -60,7 +58,6 @@ export default {
components: {
Loading,
HarvesterVmState,
LinkDetail,
ConsoleBar,
ResourceTable
},
@ -77,6 +74,9 @@ export default {
const _hash = {
vms: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.VM }),
pod: this.$store.dispatch(`${ inStore }/findAll`, { type: POD }),
pvcs: this.$store.dispatch(`${ inStore }/findAll`, { type: PVC }),
pvs: this.$store.dispatch(`${ inStore }/findAll`, { type: PV }),
images: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.IMAGE }),
restore: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.RESTORE }),
backups: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.BACKUP }),
};
@ -169,6 +169,20 @@ export default {
await this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.VMIM });
this['allVMIs'] = vmis;
},
methods: {
lockIconTooltipMessage(row) {
if (row.isVMImageEncrypted && row.isVolumeEncrypted) {
return this.t('harvester.virtualMachine.lockIconTooltip.both');
} else if (row.isVMImageEncrypted) {
return this.t('harvester.virtualMachine.lockIconTooltip.image');
} else if (row.isVolumeEncrypted) {
return this.t('harvester.virtualMachine.lockIconTooltip.volume');
}
return '';
}
}
};
</script>
@ -194,11 +208,16 @@ export default {
<template cell:name="scope">
<div class="name-console">
<LinkDetail v-if="scope.row.type !== HCI.VMI" v-model:value="scope.row.metadata.name" :row="scope.row" />
<router-link
v-if="scope.row.type !== HCI.VMI"
:to="scope.row.detailLocation"
>
{{ scope.row.metadata.name }}
<i v-if="lockIconTooltipMessage(scope.row)" v-tooltip="lockIconTooltipMessage(scope.row)" class="icon icon-lock" />
</router-link>
<span v-else>
{{ scope.row.metadata.name }}
</span>
<ConsoleBar :resource="scope.row" class="console mr-10 ml-10" />
</div>
</template>

View File

@ -214,11 +214,7 @@ export default class HciPv extends HarvesterResource {
}
get isEncrypted() {
const inStore = this.$rootGetters['currentProduct'].inStore;
const longhornVolume = this.$rootGetters[`${ inStore }/all`](LONGHORN.VOLUMES).find(v => v.metadata?.name === this.spec?.volumeName);
return longhornVolume?.spec.encrypted || false;
return this.relatedPV?.spec.csi.volumeAttributes.encrypted || false;
}
get longhornVolume() {

View File

@ -574,6 +574,29 @@ export default class VirtVm extends HarvesterResource {
return vmis.find(VMI => VMI.id === this.id);
}
get isVMImageEncrypted() {
const inStore = this.productInStore;
const imageList = this.$rootGetters[`${ inStore }/all`](HCI.IMAGE);
const rootImage = imageList.find(image => this.rootImageId === image.id);
return rootImage?.isEncrypted || false;
}
get isVolumeEncrypted() {
const inStore = this.productInStore;
const pvcs = this.$rootGetters[`${ inStore }/all`](PVC);
// filter out the root image PVC
const nonRootImagePVCs = pvcs.filter(pvc => !pvc.metadata.annotations[HCI_ANNOTATIONS.IMAGE_ID]);
const volumeClaimNames = this.spec.template.spec.volumes?.map(v => v.persistentVolumeClaim?.claimName).map(v => v) || [];
const pvcVolumes = nonRootImagePVCs.filter(pvc => volumeClaimNames.includes(pvc.metadata.name));
// if any non-rootImage PCV volume is encrypted, return true, otherwise return false
return pvcVolumes.some(pvcVol => pvcVol.isEncrypted) ;
}
get isError() {
const conditions = get(this.vmi, 'status.conditions');
const vmiFailureCond = findBy(conditions, 'type', 'Failure');