Skip to content

Commit

Permalink
fix: disk format can be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyblargon committed Jan 3, 2024
1 parent 0b0c911 commit 953450a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
9 changes: 7 additions & 2 deletions proxmox/config_qemu_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,18 @@ func (qemuDisk) mapToStruct(diskData string, settings map[string]interface{}, li
}
if len(pathParts) > 1 {
diskNameAndFormat := strings.Split(pathParts[len(pathParts)-1], ".")
if len(diskNameAndFormat) == 2 {
disk.Format = QemuDiskFormat(diskNameAndFormat[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
80 changes: 80 additions & 0 deletions proxmox/config_qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,26 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) {
Storage: "test2",
}}}}},
},
{name: "Disks Ide Disk Format default",
input: map[string]interface{}{"ide2": "test:100/vm-100-disk-2"},
output: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_2: &QemuIdeStorage{Disk: &QemuIdeDisk{
Backup: true,
Format: QemuDiskFormat_Raw,
Id: uint2,
Replicate: true,
Storage: "test",
}}}}},
},
{name: "Disks Ide Disk Format raw",
input: map[string]interface{}{"ide3": "test:100/vm-100-disk-2.raw"},
output: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_3: &QemuIdeStorage{Disk: &QemuIdeDisk{
Backup: true,
Format: QemuDiskFormat_Raw,
Id: uint2,
Replicate: true,
Storage: "test",
}}}}},
},
{name: "Disks Ide Disk iops_rd",
input: map[string]interface{}{"ide2": "test2:100/vm-100-disk-53.qcow2,iops_rd=12"},
output: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_2: &QemuIdeStorage{Disk: &QemuIdeDisk{
Expand Down Expand Up @@ -3003,6 +3023,26 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) {
Storage: "test2",
}}}}},
},
{name: "Disks Sata Disk Format default",
input: map[string]interface{}{"sata0": "test:100/vm-100-disk-2"},
output: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Disk: &QemuSataDisk{
Backup: true,
Format: QemuDiskFormat_Raw,
Id: uint2,
Replicate: true,
Storage: "test",
}}}}},
},
{name: "Disks Sata Disk Format raw",
input: map[string]interface{}{"sata1": "test:100/vm-100-disk-2.raw"},
output: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_1: &QemuSataStorage{Disk: &QemuSataDisk{
Backup: true,
Format: QemuDiskFormat_Raw,
Id: uint2,
Replicate: true,
Storage: "test",
}}}}},
},
{name: "Disks Sata Disk iops_rd",
input: map[string]interface{}{"sata0": "test2:100/vm-100-disk-47.qcow2,iops_rd=10"},
output: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Disk: &QemuSataDisk{
Expand Down Expand Up @@ -3525,6 +3565,26 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) {
Storage: "test",
}}}}},
},
{name: "Disks Scsi Disk Format default",
input: map[string]interface{}{"scsi6": "test:100/vm-100-disk-2"},
output: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_6: &QemuScsiStorage{Disk: &QemuScsiDisk{
Backup: true,
Format: QemuDiskFormat_Raw,
Id: uint2,
Replicate: true,
Storage: "test",
}}}}},
},
{name: "Disks Scsi Disk Format raw",
input: map[string]interface{}{"scsi7": "test:100/vm-100-disk-2.raw"},
output: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_7: &QemuScsiStorage{Disk: &QemuScsiDisk{
Backup: true,
Format: QemuDiskFormat_Raw,
Id: uint2,
Replicate: true,
Storage: "test",
}}}}},
},
{name: "Disks Scsi Disk iops_rd",
input: map[string]interface{}{"scsi6": "test:100/vm-100-disk-2.qcow2,iops_rd=10"},
output: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_6: &QemuScsiStorage{Disk: &QemuScsiDisk{
Expand Down Expand Up @@ -4083,6 +4143,26 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) {
Storage: "test2",
}}}}},
},
{name: "Disks VirtIO Disk Format default",
input: map[string]interface{}{"virtio7": "test:100/vm-100-disk-2"},
output: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_7: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{
Backup: true,
Format: QemuDiskFormat_Raw,
Id: uint2,
Replicate: true,
Storage: "test",
}}}}},
},
{name: "Disks VirtIO Disk Format raw",
input: map[string]interface{}{"virtio8": "test:100/vm-100-disk-2.raw"},
output: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_8: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{
Backup: true,
Format: QemuDiskFormat_Raw,
Id: uint2,
Replicate: true,
Storage: "test",
}}}}},
},
{name: "Disks VirtIO Disk iops_rd",
input: map[string]interface{}{"virtio6": "test2:100/vm-100-disk-31.qcow2,iops_rd=10"},
output: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_6: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{
Expand Down

0 comments on commit 953450a

Please sign in to comment.