Skip to content

Commit

Permalink
Merge pull request #976 from harvester/wip-add-virtualSize
Browse files Browse the repository at this point in the history
Take image virtual size into account when creating VMs
  • Loading branch information
tserong authored Aug 16, 2024
2 parents 79bd332 + a0cc74c commit b97bf06
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 10 deletions.
2 changes: 2 additions & 0 deletions pkg/harvester/config/harvester.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {

import {
IMAGE_DOWNLOAD_SIZE,
IMAGE_VIRTUAL_SIZE,
FINGERPRINT,
IMAGE_PROGRESS,
SNAPSHOT_TARGET_VOLUME,
Expand Down Expand Up @@ -220,6 +221,7 @@ export function init($plugin, store) {
NAMESPACE_COL,
IMAGE_PROGRESS,
IMAGE_DOWNLOAD_SIZE,
IMAGE_VIRTUAL_SIZE,
AGE
]);
virtualType({
Expand Down
8 changes: 8 additions & 0 deletions pkg/harvester/config/table-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 10 additions & 0 deletions pkg/harvester/detail/harvesterhci.io.virtualmachineimage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export default {
return this.value?.downSize;
},
virtualSize() {
return this.value?.virtualSize;
},
url() {
return this.value?.spec?.url || '-';
},
Expand Down Expand Up @@ -100,6 +104,12 @@ export default {
</div>
</div>
<div class="row">
<div class="col span-12">
<LabelValue :name="t('harvester.image.virtualSize')" :value="virtualSize" class="mb-20" />
</div>
</div>
<div class="row">
<div class="col span-12">
<LabelValue :name="t('nameNsDescription.description.label')" :value="description" class="mb-20" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions pkg/harvester/l10n/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ harvester:
forceStop: Force Stop
tableHeaders:
size: Size
virtualSize: Virtual Size
progress: Progress
message: Message
phase: Phase
Expand Down Expand Up @@ -698,6 +699,7 @@ harvester:
basics: Basics
url: URL
size: Size
virtualSize: Virtual Size
urlTip: 'supports the <code>raw</code> and <code>qcow2</code> image formats which are supported by <a href="https://www.qemu.org/docs/master/system/images.html#disk-image-file-formats" target="_blank">qemu</a>. Bootable ISO images can also be used and are treated like <code>raw</code> images.'
fileName: File Name
uploadFile: Upload File
Expand Down
28 changes: 25 additions & 3 deletions pkg/harvester/mixins/harvester-vm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
15 changes: 15 additions & 0 deletions pkg/harvester/models/harvesterhci.io.virtualmachineimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b97bf06

Please sign in to comment.