diff --git a/pkg/harvester/config/harvester.js b/pkg/harvester/config/harvester.js index 3d54eb0c1e8..4cb4ecee538 100644 --- a/pkg/harvester/config/harvester.js +++ b/pkg/harvester/config/harvester.js @@ -28,6 +28,7 @@ import { import { IMAGE_DOWNLOAD_SIZE, + IMAGE_VIRTUAL_SIZE, FINGERPRINT, IMAGE_PROGRESS, SNAPSHOT_TARGET_VOLUME, @@ -220,6 +221,7 @@ export function init($plugin, store) { NAMESPACE_COL, IMAGE_PROGRESS, IMAGE_DOWNLOAD_SIZE, + IMAGE_VIRTUAL_SIZE, AGE ]); virtualType({ diff --git a/pkg/harvester/config/table-headers.js b/pkg/harvester/config/table-headers.js index ecd7afa808c..fa0c42bfcb4 100644 --- a/pkg/harvester/config/table-headers.js +++ b/pkg/harvester/config/table-headers.js @@ -11,6 +11,14 @@ export const IMAGE_DOWNLOAD_SIZE = { width: 120 }; +export const IMAGE_VIRTUAL_SIZE = { + name: 'virtualSize', + labelKey: 'harvester.tableHeaders.virtualSize', + value: 'virtualSize', + sort: 'status.virtualSize', + width: 120 +}; + export const IMAGE_PROGRESS = { name: 'Uploaded', labelKey: 'tableHeaders.progress', diff --git a/pkg/harvester/detail/harvesterhci.io.virtualmachineimage/index.vue b/pkg/harvester/detail/harvesterhci.io.virtualmachineimage/index.vue index fcb523d3a15..98677d4e27c 100644 --- a/pkg/harvester/detail/harvesterhci.io.virtualmachineimage/index.vue +++ b/pkg/harvester/detail/harvesterhci.io.virtualmachineimage/index.vue @@ -35,6 +35,10 @@ export default { return this.value?.downSize; }, + virtualSize() { + return this.value?.virtualSize; + }, + url() { return this.value?.spec?.url || '-'; }, @@ -100,6 +104,12 @@ export default { +
+
+ +
+
+
diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue index 3f5f9e094a3..68b46bb2881 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVolume/type/vmImage.vue @@ -140,15 +140,24 @@ export default { onImageChange() { const imageResource = this.$store.getters['harvester/all'](HCI.IMAGE)?.find( I => this.value.image === I.id); + const isIsoImage = /iso$/i.test(imageResource?.imageSuffix); + const imageSize = Math.max(imageResource?.status?.size, imageResource?.status?.virtualSize); - if (this.idx === 0) { - if (/iso$/i.test(imageResource?.imageSuffix)) { - this.$set(this.value, 'type', 'cd-rom'); - this.$set(this.value, 'bus', 'sata'); - } else { - this.$set(this.value, 'type', 'disk'); - this.$set(this.value, 'bus', 'virtio'); + if (isIsoImage) { + this.$set(this.value, 'type', 'cd-rom'); + this.$set(this.value, 'bus', 'sata'); + } else { + this.$set(this.value, 'type', 'disk'); + this.$set(this.value, 'bus', 'virtio'); + } + + if (imageSize) { + let imageSizeGiB = Math.ceil(imageSize / 1024 / 1024 / 1024); + + if (!isIsoImage) { + imageSizeGiB = Math.max(imageSizeGiB, 10); } + this.$set(this.value, 'size', `${ imageSizeGiB }Gi`); } this.update(); diff --git a/pkg/harvester/l10n/en-us.yaml b/pkg/harvester/l10n/en-us.yaml index 5bc93214246..55169d1233d 100644 --- a/pkg/harvester/l10n/en-us.yaml +++ b/pkg/harvester/l10n/en-us.yaml @@ -159,6 +159,7 @@ harvester: forceStop: Force Stop tableHeaders: size: Size + virtualSize: Virtual Size progress: Progress message: Message phase: Phase @@ -698,6 +699,7 @@ harvester: basics: Basics url: URL size: Size + virtualSize: Virtual Size urlTip: 'supports the raw and qcow2 image formats which are supported by qemu. Bootable ISO images can also be used and are treated like raw images.' fileName: File Name uploadFile: Upload File diff --git a/pkg/harvester/mixins/harvester-vm/index.js b/pkg/harvester/mixins/harvester-vm/index.js index ea31a5a3213..17f0b729c6c 100644 --- a/pkg/harvester/mixins/harvester-vm/index.js +++ b/pkg/harvester/mixins/harvester-vm/index.js @@ -412,15 +412,37 @@ export default { let out = []; if (_disks.length === 0) { + let bus = 'virtio'; + let type = HARD_DISK; + let size = '10Gi'; + + const imageResource = this.images.find( I => this.imageId === I.id); + const isIsoImage = /iso$/i.test(imageResource?.imageSuffix); + const imageSize = Math.max(imageResource?.status?.size, imageResource?.status?.virtualSize); + + if (isIsoImage) { + bus = 'sata'; + type = CD_ROM; + } + + if (imageSize) { + let imageSizeGiB = Math.ceil(imageSize / 1024 / 1024 / 1024); + + if (!isIsoImage) { + imageSizeGiB = Math.max(imageSizeGiB, 10); + } + size = `${ imageSizeGiB }Gi`; + } + out.push({ id: randomStr(5), source: SOURCE_TYPE.IMAGE, name: 'disk-0', accessMode: 'ReadWriteMany', - bus: 'virtio', + bus, volumeName: '', - size: '10Gi', - type: HARD_DISK, + size, + type, storageClassName: '', image: this.imageId, volumeMode: 'Block', diff --git a/pkg/harvester/models/harvesterhci.io.virtualmachineimage.js b/pkg/harvester/models/harvesterhci.io.virtualmachineimage.js index 47d9cb2e6d5..5480a74c675 100644 --- a/pkg/harvester/models/harvesterhci.io.virtualmachineimage.js +++ b/pkg/harvester/models/harvesterhci.io.virtualmachineimage.js @@ -168,6 +168,21 @@ export default class HciVmImage extends HarvesterResource { }); } + get virtualSize() { + const virtualSize = this.status?.virtualSize; + + if (!virtualSize) { + return '-'; + } + + return formatSi(virtualSize, { + increment: 1024, + maxPrecision: 2, + suffix: 'B', + firstSuffix: 'B', + }); + } + getStatusConditionOfType(type, defaultValue = []) { const conditions = Array.isArray(get(this, 'status.conditions')) ? this.status.conditions : defaultValue;