Skip to content

Commit

Permalink
fix: add missing support for disk syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyblargon committed Jan 3, 2024
1 parent 953450a commit 02f3404
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
27 changes: 13 additions & 14 deletions proxmox/config_qemu_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions proxmox/config_qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 02f3404

Please sign in to comment.