From 02f34049005252e384b6ba82d641d91bce07a397 Mon Sep 17 00:00:00 2001 From: Tinyblargon <76069640+Tinyblargon@users.noreply.github.com> Date: Wed, 3 Jan 2024 20:42:42 +0000 Subject: [PATCH] fix: add missing support for disk syntax --- proxmox/config_qemu_disk.go | 27 +++++++++++++-------------- proxmox/config_qemu_test.go | 16 ++++++++-------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/proxmox/config_qemu_disk.go b/proxmox/config_qemu_disk.go index 62d2464c..fc5fa684 100644 --- a/proxmox/config_qemu_disk.go +++ b/proxmox/config_qemu_disk.go @@ -304,6 +304,7 @@ func (qemuDisk) mapToStruct(diskData string, settings map[string]interface{}, li } else { // storage:110/base-110-disk-1.qcow2/100/vm-100-disk-0.qcow2 // storage:100/vm-100-disk-0.qcow2 + // storage:vm-100-disk-0 diskAndPath := strings.Split(diskData, ":") disk.Storage = diskAndPath[0] if len(diskAndPath) == 2 { @@ -319,20 +320,18 @@ func (qemuDisk) mapToStruct(diskData string, settings map[string]interface{}, li disk.LinkedDiskId = &tmpDiskIdPointer } } - if len(pathParts) > 1 { - diskNameAndFormat := strings.Split(pathParts[len(pathParts)-1], ".") - if len(diskNameAndFormat) > 0 { - tmp := strings.Split(diskNameAndFormat[0], "-") - if len(tmp) > 1 { - tmpDiskId, _ := strconv.Atoi(tmp[len(tmp)-1]) - disk.Id = uint(tmpDiskId) - } - // set disk format, default to raw - if len(diskNameAndFormat) == 2 { - disk.Format = QemuDiskFormat(diskNameAndFormat[1]) - } else { - disk.Format = QemuDiskFormat_Raw - } + diskNameAndFormat := strings.Split(pathParts[len(pathParts)-1], ".") + if len(diskNameAndFormat) > 0 { + tmp := strings.Split(diskNameAndFormat[0], "-") + if len(tmp) > 1 { + tmpDiskId, _ := strconv.Atoi(tmp[len(tmp)-1]) + disk.Id = uint(tmpDiskId) + } + // set disk format, default to raw + if len(diskNameAndFormat) == 2 { + disk.Format = QemuDiskFormat(diskNameAndFormat[1]) + } else { + disk.Format = QemuDiskFormat_Raw } } } diff --git a/proxmox/config_qemu_test.go b/proxmox/config_qemu_test.go index e161b8cf..da5e2f5f 100644 --- a/proxmox/config_qemu_test.go +++ b/proxmox/config_qemu_test.go @@ -2490,7 +2490,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks Ide Disk Format default", - input: map[string]interface{}{"ide2": "test:100/vm-100-disk-2"}, + input: map[string]interface{}{"ide2": "test:vm-100-disk-2"}, output: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_2: &QemuIdeStorage{Disk: &QemuIdeDisk{ Backup: true, Format: QemuDiskFormat_Raw, @@ -2500,7 +2500,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks Ide Disk Format raw", - input: map[string]interface{}{"ide3": "test:100/vm-100-disk-2.raw"}, + input: map[string]interface{}{"ide3": "test:vm-100-disk-2.raw"}, output: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_3: &QemuIdeStorage{Disk: &QemuIdeDisk{ Backup: true, Format: QemuDiskFormat_Raw, @@ -3024,7 +3024,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks Sata Disk Format default", - input: map[string]interface{}{"sata0": "test:100/vm-100-disk-2"}, + input: map[string]interface{}{"sata0": "test:vm-100-disk-2"}, output: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Disk: &QemuSataDisk{ Backup: true, Format: QemuDiskFormat_Raw, @@ -3034,7 +3034,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks Sata Disk Format raw", - input: map[string]interface{}{"sata1": "test:100/vm-100-disk-2.raw"}, + input: map[string]interface{}{"sata1": "test:vm-100-disk-2.raw"}, output: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_1: &QemuSataStorage{Disk: &QemuSataDisk{ Backup: true, Format: QemuDiskFormat_Raw, @@ -3566,7 +3566,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks Scsi Disk Format default", - input: map[string]interface{}{"scsi6": "test:100/vm-100-disk-2"}, + input: map[string]interface{}{"scsi6": "test:vm-100-disk-2"}, output: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_6: &QemuScsiStorage{Disk: &QemuScsiDisk{ Backup: true, Format: QemuDiskFormat_Raw, @@ -3576,7 +3576,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks Scsi Disk Format raw", - input: map[string]interface{}{"scsi7": "test:100/vm-100-disk-2.raw"}, + input: map[string]interface{}{"scsi7": "test:vm-100-disk-2.raw"}, output: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_7: &QemuScsiStorage{Disk: &QemuScsiDisk{ Backup: true, Format: QemuDiskFormat_Raw, @@ -4144,7 +4144,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks VirtIO Disk Format default", - input: map[string]interface{}{"virtio7": "test:100/vm-100-disk-2"}, + input: map[string]interface{}{"virtio7": "test:vm-100-disk-2"}, output: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_7: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{ Backup: true, Format: QemuDiskFormat_Raw, @@ -4154,7 +4154,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks VirtIO Disk Format raw", - input: map[string]interface{}{"virtio8": "test:100/vm-100-disk-2.raw"}, + input: map[string]interface{}{"virtio8": "test:vm-100-disk-2.raw"}, output: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_8: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{ Backup: true, Format: QemuDiskFormat_Raw,