From c3bd7b7b2747f7877aa3045fb30f3c18d1a1f3d5 Mon Sep 17 00:00:00 2001 From: Tinyblargon <76069640+Tinyblargon@users.noreply.github.com> Date: Wed, 21 Jun 2023 19:56:10 +0000 Subject: [PATCH 1/4] test: added for api `wwn` setting --- proxmox/config_qemu_test.go | 532 ++++++++++++++++++++++-------------- 1 file changed, 332 insertions(+), 200 deletions(-) diff --git a/proxmox/config_qemu_test.go b/proxmox/config_qemu_test.go index 68f7a8f3..96acaf96 100644 --- a/proxmox/config_qemu_test.go +++ b/proxmox/config_qemu_test.go @@ -67,16 +67,17 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: uint89, BurstDuration: 4, Concurrent: uint23}, }, }, - Cache: QemuDiskCache_DirectSync, - Discard: true, - EmulateSSD: true, - Format: format_Raw, - Replicate: true, - Serial: "558485ef-478", - Size: 32, - Storage: "Test", - }}}}}, - output: map[string]interface{}{"ide0": "Test:32,aio=native,cache=directsync,discard=on,format=raw,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,serial=558485ef-478,ssd=1"}, + Cache: QemuDiskCache_DirectSync, + Discard: true, + EmulateSSD: true, + Format: format_Raw, + Replicate: true, + Serial: "558485ef-478", + Size: 32, + Storage: "Test", + WorldWideName: "0x5000D31000C9876F", + }}}}}, + output: map[string]interface{}{"ide0": "Test:32,aio=native,cache=directsync,discard=on,format=raw,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,serial=558485ef-478,ssd=1,wwn=0x5000D31000C9876F"}, }, {name: "Create Disks.Ide.Disk_X.Disk.AsyncIO", config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_1: &QemuIdeStorage{Disk: &QemuIdeDisk{AsyncIO: QemuDiskAsyncIO_Native}}}}}, @@ -186,6 +187,10 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_0: &QemuIdeStorage{Disk: &QemuIdeDisk{Storage: "Test"}}}}}, output: map[string]interface{}{"ide0": "Test:0,backup=0,replicate=0"}, }, + {name: "Create Disks.Ide.Disk_X.Disk.WorldWideName", + config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_0: &QemuIdeStorage{Disk: &QemuIdeDisk{WorldWideName: "0x5001234000F876AB"}}}}}, + output: map[string]interface{}{"ide0": ",backup=0,replicate=0,wwn=0x5001234000F876AB"}, + }, // Create Disks.Ide.Disk_X.Passthrough {name: "Create Disks.Ide.Disk_X.Passthrough All", config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_0: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{ @@ -201,14 +206,15 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: uint89, BurstDuration: 4, Concurrent: uint23}, }, }, - Cache: QemuDiskCache_Unsafe, - Discard: true, - EmulateSSD: true, - File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", - Replicate: true, - Serial: "test-serial_757465-gdg", + Cache: QemuDiskCache_Unsafe, + Discard: true, + EmulateSSD: true, + File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", + Replicate: true, + Serial: "test-serial_757465-gdg", + WorldWideName: "0x500CBA2000D76543", }}}}}, - output: map[string]interface{}{"ide0": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=threads,cache=unsafe,discard=on,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,serial=test-serial_757465-gdg,ssd=1"}, + output: map[string]interface{}{"ide0": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=threads,cache=unsafe,discard=on,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,serial=test-serial_757465-gdg,ssd=1,wwn=0x500CBA2000D76543"}, }, {name: "Create Disks.Ide.Disk_X.Passthrough.AsyncIO", config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_1: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{AsyncIO: QemuDiskAsyncIO_Threads}}}}}, @@ -310,6 +316,10 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_3: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{Serial: "test-serial_757465-gdg"}}}}}, output: map[string]interface{}{"ide3": ",backup=0,replicate=0,serial=test-serial_757465-gdg"}, }, + {name: "Create Disks.Ide.Disk_X.Passthrough.WorldWideName", + config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_3: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{WorldWideName: "0x500FED1000B65432"}}}}}, + output: map[string]interface{}{"ide3": ",backup=0,replicate=0,wwn=0x500FED1000B65432"}, + }, // Create Disks.Sata {name: "Create Disks.Sata.Disk_X.Disk_X.CdRom none", config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{CdRom: &QemuCdRom{}}}}}, @@ -342,16 +352,17 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: uint89, BurstDuration: 4, Concurrent: uint23}, }, }, - Cache: QemuDiskCache_Unsafe, - Discard: true, - EmulateSSD: true, - Format: QemuDiskFormat_Qcow2, - Replicate: true, - Serial: "ab_C-12_3", - Size: 32, - Storage: "Test", - }}}}}, - output: map[string]interface{}{"sata0": "Test:32,aio=native,cache=unsafe,discard=on,format=qcow2,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,serial=ab_C-12_3,ssd=1"}, + Cache: QemuDiskCache_Unsafe, + Discard: true, + EmulateSSD: true, + Format: QemuDiskFormat_Qcow2, + Replicate: true, + Serial: "ab_C-12_3", + Size: 32, + Storage: "Test", + WorldWideName: "0x5009876000A321DC", + }}}}}, + output: map[string]interface{}{"sata0": "Test:32,aio=native,cache=unsafe,discard=on,format=qcow2,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,serial=ab_C-12_3,ssd=1,wwn=0x5009876000A321DC"}, }, {name: "Create Disks.Sata.Disk_X.Disk.AsyncIO", config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Disk: &QemuSataDisk{AsyncIO: QemuDiskAsyncIO_Native}}}}}, @@ -461,6 +472,10 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_5: &QemuSataStorage{Disk: &QemuSataDisk{Storage: "Test"}}}}}, output: map[string]interface{}{"sata5": "Test:0,backup=0,replicate=0"}, }, + {name: "Create Disks.Sata.Disk_X.Disk.WorldWideName", + config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Disk: &QemuSataDisk{WorldWideName: "0x500DCBA500E23456"}}}}}, + output: map[string]interface{}{"sata0": ",backup=0,replicate=0,wwn=0x500DCBA500E23456"}, + }, // Create Disks.Sata.Disk_X.Passthrough {name: "Create Disks.Sata.Disk_X.Passthrough All", config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Passthrough: &QemuSataPassthrough{ @@ -476,14 +491,15 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: uint89, BurstDuration: 4, Concurrent: uint23}, }, }, - Cache: QemuDiskCache_Unsafe, - Discard: true, - EmulateSSD: true, - File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", - Replicate: true, - Serial: "test-serial_757465-gdg", + Cache: QemuDiskCache_Unsafe, + Discard: true, + EmulateSSD: true, + File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", + Replicate: true, + Serial: "test-serial_757465-gdg", + WorldWideName: "0x5007892000C4321A", }}}}}, - output: map[string]interface{}{"sata0": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=threads,cache=unsafe,discard=on,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,serial=test-serial_757465-gdg,ssd=1"}, + output: map[string]interface{}{"sata0": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=threads,cache=unsafe,discard=on,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,serial=test-serial_757465-gdg,ssd=1,wwn=0x5007892000C4321A"}, }, {name: "Create Disks.Sata.Disk_X.Passthrough.AsyncIO", config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_1: &QemuSataStorage{Passthrough: &QemuSataPassthrough{AsyncIO: QemuDiskAsyncIO_Threads}}}}}, @@ -585,6 +601,10 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_5: &QemuSataStorage{Passthrough: &QemuSataPassthrough{Serial: "test-serial_757465-gdg"}}}}}, output: map[string]interface{}{"sata5": ",backup=0,replicate=0,serial=test-serial_757465-gdg"}, }, + {name: "Create Disks.Sata.Disk_X.Passthrough.WorldWideName", + config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_5: &QemuSataStorage{Passthrough: &QemuSataPassthrough{WorldWideName: "0x5001ABE000987654"}}}}}, + output: map[string]interface{}{"sata5": ",backup=0,replicate=0,wwn=0x5001ABE000987654"}, + }, // Create Disks.Scsi {name: "Create Disks.Scsi.CdRom none", config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_0: &QemuScsiStorage{CdRom: &QemuCdRom{}}}}}, @@ -617,18 +637,19 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: uint89, BurstDuration: 4, Concurrent: uint23}, }, }, - Cache: QemuDiskCache_DirectSync, - Discard: true, - EmulateSSD: true, - Format: format_Raw, - IOThread: true, - ReadOnly: true, - Replicate: true, - Serial: "558485ef-478", - Size: 32, - Storage: "Test", - }}}}}, - output: map[string]interface{}{"scsi0": "Test:32,aio=native,cache=directsync,discard=on,format=raw,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,iothread=1,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,ro=1,serial=558485ef-478,ssd=1"}, + Cache: QemuDiskCache_DirectSync, + Discard: true, + EmulateSSD: true, + Format: format_Raw, + IOThread: true, + ReadOnly: true, + Replicate: true, + Serial: "558485ef-478", + Size: 32, + Storage: "Test", + WorldWideName: "0x500D567800BAC321", + }}}}}, + output: map[string]interface{}{"scsi0": "Test:32,aio=native,cache=directsync,discard=on,format=raw,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,iothread=1,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,ro=1,serial=558485ef-478,ssd=1,wwn=0x500D567800BAC321"}, }, {name: "Create Disks.Scsi.Disk_X.Disk.AsyncIO", config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_1: &QemuScsiStorage{Disk: &QemuScsiDisk{AsyncIO: QemuDiskAsyncIO_Native}}}}}, @@ -746,6 +767,10 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_26: &QemuScsiStorage{Disk: &QemuScsiDisk{Storage: "Test"}}}}}, output: map[string]interface{}{"scsi26": "Test:0,backup=0,replicate=0"}, }, + {name: "Create Disks.Scsi.Disk_X.Disk.WorldWideName", + config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_27: &QemuScsiStorage{Disk: &QemuScsiDisk{WorldWideName: "0x500EF32100D76589"}}}}}, + output: map[string]interface{}{"scsi27": ",backup=0,replicate=0,wwn=0x500EF32100D76589"}, + }, // Create Disks.Scsi.Passthrough {name: "Create Disks.Scsi.Disk_X.Passthrough All", config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_0: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{ @@ -761,16 +786,17 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: uint89, BurstDuration: 4, Concurrent: uint23}, }, }, - Cache: QemuDiskCache_Unsafe, - Discard: true, - EmulateSSD: true, - File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", - IOThread: true, - ReadOnly: true, - Replicate: true, - Serial: "test-serial_757465-gdg", - }}}}}, - output: map[string]interface{}{"scsi0": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=threads,cache=unsafe,discard=on,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,iothread=1,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,ro=1,serial=test-serial_757465-gdg,ssd=1"}, + Cache: QemuDiskCache_Unsafe, + Discard: true, + EmulateSSD: true, + File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", + IOThread: true, + ReadOnly: true, + Replicate: true, + Serial: "test-serial_757465-gdg", + WorldWideName: "0x500BCA3000F09876", + }}}}}, + output: map[string]interface{}{"scsi0": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=threads,cache=unsafe,discard=on,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,iothread=1,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,ro=1,serial=test-serial_757465-gdg,ssd=1,wwn=0x500BCA3000F09876"}, }, {name: "Create Disks.Scsi.Disk_X.Passthrough.AsyncIO", config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_1: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{AsyncIO: QemuDiskAsyncIO_Threads}}}}}, @@ -880,6 +906,10 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_25: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{Serial: "test-serial_757465-gdg"}}}}}, output: map[string]interface{}{"scsi25": ",backup=0,replicate=0,serial=test-serial_757465-gdg"}, }, + {name: "Create Disks.Scsi.Disk_X.Passthrough.WorldWideName", + config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_25: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{WorldWideName: "0x5004DC0100E239C7"}}}}}, + output: map[string]interface{}{"scsi25": ",backup=0,replicate=0,wwn=0x5004DC0100E239C7"}, + }, // Create Disks.VirtIO {name: "Create Disks.VirtIO.Disk_X.CdRom none", config: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_0: &QemuVirtIOStorage{CdRom: &QemuCdRom{}}}}}, @@ -912,17 +942,18 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: uint89, BurstDuration: 4, Concurrent: uint23}, }, }, - Cache: QemuDiskCache_DirectSync, - Discard: true, - Format: format_Raw, - IOThread: true, - ReadOnly: true, - Replicate: true, - Serial: "558485ef-478", - Size: 32, - Storage: "Test", - }}}}}, - output: map[string]interface{}{"virtio0": "Test:32,aio=native,cache=directsync,discard=on,format=raw,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,iothread=1,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,ro=1,serial=558485ef-478"}, + Cache: QemuDiskCache_DirectSync, + Discard: true, + Format: format_Raw, + IOThread: true, + ReadOnly: true, + Replicate: true, + Serial: "558485ef-478", + Size: 32, + Storage: "Test", + WorldWideName: "0x500A7B0800F345D2", + }}}}}, + output: map[string]interface{}{"virtio0": "Test:32,aio=native,cache=directsync,discard=on,format=raw,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,iothread=1,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,ro=1,serial=558485ef-478,wwn=0x500A7B0800F345D2"}, }, {name: "Create Disks.VirtIO.Disk_X.Disk.AsyncIO", config: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_1: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{AsyncIO: QemuDiskAsyncIO_Native}}}}}, @@ -1044,6 +1075,10 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { config: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_9: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{Storage: "Test"}}}}}, output: map[string]interface{}{"virtio9": "Test:0,backup=0,replicate=0"}, }, + {name: "Create Disks.VirtIO.Disk_X.Disk.WorldWideName", + config: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_10: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{WorldWideName: "0x5005FED000B87632"}}}}}, + output: map[string]interface{}{"virtio10": ",backup=0,replicate=0,wwn=0x5005FED000B87632"}, + }, // Create Disks.VirtIO.Disk_X.Passthrough {name: "Create Disks.VirtIO.Disk_X.Passthrough All", config: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_0: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{ @@ -1059,15 +1094,16 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: uint89, BurstDuration: 4, Concurrent: uint23}, }, }, - Cache: QemuDiskCache_Unsafe, - Discard: true, - File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", - IOThread: true, - ReadOnly: true, - Replicate: true, - Serial: "test-serial_757465-gdg", + Cache: QemuDiskCache_Unsafe, + Discard: true, + File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", + IOThread: true, + ReadOnly: true, + Replicate: true, + Serial: "test-serial_757465-gdg", + WorldWideName: "0x500C329500A1EFAB", }}}}}, - output: map[string]interface{}{"virtio0": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=threads,cache=unsafe,discard=on,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,iothread=1,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,ro=1,serial=test-serial_757465-gdg"}, + output: map[string]interface{}{"virtio0": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=threads,cache=unsafe,discard=on,iops_rd=34,iops_rd_max=78,iops_rd_max_length=3,iops_wr=23,iops_wr_max=89,iops_wr_max_length=4,iothread=1,mbps_rd=10.30,mbps_rd_max=99.20,mbps_wr=45.23,mbps_wr_max=79.23,ro=1,serial=test-serial_757465-gdg,wwn=0x500C329500A1EFAB"}, }, {name: "Create Disks.VirtIO.Disk_X.Passthrough.AsyncIO", config: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_1: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{AsyncIO: QemuDiskAsyncIO_Threads}}}}}, @@ -1173,6 +1209,10 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) { config: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_7: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{Serial: "test-serial_757465-gdg"}}}}}, output: map[string]interface{}{"virtio7": ",backup=0,replicate=0,serial=test-serial_757465-gdg"}, }, + {name: "Create Disks.VirtIO.Disk_X.Passthrough.WorldWideName", + config: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_8: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{WorldWideName: "0x500D41A600C67853"}}}}}, + output: map[string]interface{}{"virtio8": ",backup=0,replicate=0,wwn=0x500D41A600C67853"}, + }, // Create Iso {name: "Create Iso", config: &ConfigQemu{Iso: &IsoFile{Storage: "test", File: "file.iso"}}, @@ -2349,7 +2389,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks Ide Disk ALL", - input: map[string]interface{}{"ide1": "test2:100/vm-100-disk-53.qcow2,aio=io_uring,backup=0,cache=writethrough,discard=on,iops_rd=12,iops_rd_max=13,iops_rd_max_length=4,iops_wr=15,iops_wr_max=14,iops_wr_max_length=5,mbps_rd=1.46,mbps_rd_max=3.57,mbps_wr=2.68,mbps_wr_max=4.55,replicate=0,serial=disk-9763,size=1032G,ssd=1"}, + input: map[string]interface{}{"ide1": "test2:100/vm-100-disk-53.qcow2,aio=io_uring,backup=0,cache=writethrough,discard=on,iops_rd=12,iops_rd_max=13,iops_rd_max_length=4,iops_wr=15,iops_wr_max=14,iops_wr_max_length=5,mbps_rd=1.46,mbps_rd_max=3.57,mbps_wr=2.68,mbps_wr_max=4.55,replicate=0,serial=disk-9763,size=1032G,ssd=1,wwn=0x500F753600A987E1"}, output: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_1: &QemuIdeStorage{Disk: &QemuIdeDisk{ AsyncIO: QemuDiskAsyncIO_IOuring, Backup: false, @@ -2363,19 +2403,20 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: 14, BurstDuration: 5, Concurrent: 15}, }, }, - Cache: QemuDiskCache_WriteThrough, - Discard: true, - EmulateSSD: true, - Format: QemuDiskFormat_Qcow2, - Id: uint53, - Replicate: false, - Serial: "disk-9763", - Size: 1032, - Storage: "test2", + Cache: QemuDiskCache_WriteThrough, + Discard: true, + EmulateSSD: true, + Format: QemuDiskFormat_Qcow2, + Id: uint53, + Replicate: false, + Serial: "disk-9763", + Size: 1032, + Storage: "test2", + WorldWideName: "0x500F753600A987E1", }}}}}, }, {name: "Disks Ide Disk ALL LinkedClone", - input: map[string]interface{}{"ide1": "test2:110/base-110-disk-1.qcow2/100/vm-100-disk-53.qcow2,aio=io_uring,backup=0,cache=writethrough,discard=on,iops_rd=12,iops_rd_max=13,iops_rd_max_length=4,iops_wr=15,iops_wr_max=14,iops_wr_max_length=5,mbps_rd=1.46,mbps_rd_max=3.57,mbps_wr=2.68,mbps_wr_max=4.55,replicate=0,serial=disk-9763,size=1032G,ssd=1"}, + input: map[string]interface{}{"ide1": "test2:110/base-110-disk-1.qcow2/100/vm-100-disk-53.qcow2,aio=io_uring,backup=0,cache=writethrough,discard=on,iops_rd=12,iops_rd_max=13,iops_rd_max_length=4,iops_wr=15,iops_wr_max=14,iops_wr_max_length=5,mbps_rd=1.46,mbps_rd_max=3.57,mbps_wr=2.68,mbps_wr_max=4.55,replicate=0,serial=disk-9763,size=1032G,ssd=1,wwn=0x500679CE00B1DAF4"}, output: &ConfigQemu{ LinkedVmId: 110, Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_1: &QemuIdeStorage{Disk: &QemuIdeDisk{ @@ -2391,16 +2432,17 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: 14, BurstDuration: 5, Concurrent: 15}, }, }, - Cache: QemuDiskCache_WriteThrough, - Discard: true, - EmulateSSD: true, - Format: QemuDiskFormat_Qcow2, - Id: uint53, - LinkedDiskId: &uint1, - Replicate: false, - Serial: "disk-9763", - Size: 1032, - Storage: "test2", + Cache: QemuDiskCache_WriteThrough, + Discard: true, + EmulateSSD: true, + Format: QemuDiskFormat_Qcow2, + Id: uint53, + LinkedDiskId: &uint1, + Replicate: false, + Serial: "disk-9763", + Size: 1032, + Storage: "test2", + WorldWideName: "0x500679CE00B1DAF4", }}}}}, }, {name: "Disks Ide Disk aio", @@ -2610,6 +2652,17 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { Storage: "test2", }}}}}, }, + {name: "Disks Ide Disk wwn", + input: map[string]interface{}{"ide1": "test2:100/vm-100-disk-53.qcow2,wwn=0x500DB82100C6FA59"}, + output: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_1: &QemuIdeStorage{Disk: &QemuIdeDisk{ + Backup: true, + Format: QemuDiskFormat_Qcow2, + Id: uint53, + Replicate: true, + Storage: "test2", + WorldWideName: "0x500DB82100C6FA59", + }}}}}, + }, // Disks Ide Passthrough {name: "Disks Ide Passthrough", input: map[string]interface{}{"ide0": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8"}, @@ -2620,7 +2673,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks Ide Passthrough All", - input: map[string]interface{}{"ide1": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=threads,backup=0,cache=unsafe,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,serial=disk-9763,size=1G,ssd=1"}, + input: map[string]interface{}{"ide1": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=threads,backup=0,cache=unsafe,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,serial=disk-9763,size=1G,ssd=1,wwn=0x500CBE4300D978A6"}, output: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_1: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{ AsyncIO: QemuDiskAsyncIO_Threads, Backup: false, @@ -2634,13 +2687,14 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: 13, BurstDuration: 5, Concurrent: 11}, }, }, - Cache: QemuDiskCache_Unsafe, - Discard: true, - EmulateSSD: true, - File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", - Replicate: false, - Serial: "disk-9763", - Size: 1, + Cache: QemuDiskCache_Unsafe, + Discard: true, + EmulateSSD: true, + File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", + Replicate: false, + Serial: "disk-9763", + Size: 1, + WorldWideName: "0x500CBE4300D978A6", }}}}}, }, {name: "Disks Ide Passthrough aio", @@ -2803,6 +2857,15 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { Replicate: true, }}}}}, }, + {name: "Disks Ide Passthrough wwn", + input: map[string]interface{}{"ide1": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,wwn=0x5005AC1200F643B8"}, + output: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_1: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{ + Backup: true, + File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", + Replicate: true, + WorldWideName: "0x5005AC1200F643B8", + }}}}}, + }, // Disks Sata CdRom {name: "Disks Sata CdRom none", input: map[string]interface{}{"sata5": "none,media=cdrom"}, @@ -2840,7 +2903,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks Sata Disk ALL", - input: map[string]interface{}{"sata1": "test2:100/vm-100-disk-47.qcow2,aio=native,backup=0,cache=none,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,serial=disk-9763,size=32G,ssd=1"}, + input: map[string]interface{}{"sata1": "test2:100/vm-100-disk-47.qcow2,aio=native,backup=0,cache=none,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,serial=disk-9763,size=32G,ssd=1,wwn=0x500DFA8900E3C641"}, output: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_1: &QemuSataStorage{Disk: &QemuSataDisk{ AsyncIO: QemuDiskAsyncIO_Native, Backup: false, @@ -2854,19 +2917,20 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: 13, BurstDuration: 5, Concurrent: 11}, }, }, - Cache: QemuDiskCache_None, - Discard: true, - EmulateSSD: true, - Format: QemuDiskFormat_Qcow2, - Id: uint47, - Replicate: false, - Serial: "disk-9763", - Size: 32, - Storage: "test2", + Cache: QemuDiskCache_None, + Discard: true, + EmulateSSD: true, + Format: QemuDiskFormat_Qcow2, + Id: uint47, + Replicate: false, + Serial: "disk-9763", + Size: 32, + Storage: "test2", + WorldWideName: "0x500DFA8900E3C641", }}}}}, }, {name: "Disks Sata Disk ALL LinkedClone", - input: map[string]interface{}{"sata1": "test2:110/base-110-disk-1.qcow2/100/vm-100-disk-47.qcow2,aio=native,backup=0,cache=none,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,serial=disk-9763,size=32G,ssd=1"}, + input: map[string]interface{}{"sata1": "test2:110/base-110-disk-1.qcow2/100/vm-100-disk-47.qcow2,aio=native,backup=0,cache=none,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,serial=disk-9763,size=32G,ssd=1,wwn=0x5003B97600A8F2D4"}, output: &ConfigQemu{ LinkedVmId: 110, Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_1: &QemuSataStorage{Disk: &QemuSataDisk{ @@ -2882,16 +2946,17 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: 13, BurstDuration: 5, Concurrent: 11}, }, }, - Cache: QemuDiskCache_None, - Discard: true, - EmulateSSD: true, - Format: QemuDiskFormat_Qcow2, - Id: uint47, - LinkedDiskId: &uint1, - Replicate: false, - Serial: "disk-9763", - Size: 32, - Storage: "test2", + Cache: QemuDiskCache_None, + Discard: true, + EmulateSSD: true, + Format: QemuDiskFormat_Qcow2, + Id: uint47, + LinkedDiskId: &uint1, + Replicate: false, + Serial: "disk-9763", + Size: 32, + Storage: "test2", + WorldWideName: "0x5003B97600A8F2D4", }}}}}, }, {name: "Disks Sata Disk aio", @@ -3105,6 +3170,17 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { Storage: "test2", }}}}}, }, + {name: "Disks Sata Disk wwn", + input: map[string]interface{}{"sata5": "test2:100/vm-100-disk-47.qcow2,wwn=0x5001E48A00D567C9"}, + output: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_5: &QemuSataStorage{Disk: &QemuSataDisk{ + Backup: true, + Format: QemuDiskFormat_Qcow2, + Id: uint47, + Replicate: true, + Storage: "test2", + WorldWideName: "0x5001E48A00D567C9", + }}}}}, + }, // Disks Sata Passthrough {name: "Disks Sata Passthrough", input: map[string]interface{}{"sata1": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8"}, @@ -3115,7 +3191,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks Sata Passthrough All", - input: map[string]interface{}{"sata1": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=io_uring,backup=0,cache=directsync,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=5,iops_wr=11,iops_wr_max=13,iops_wr_max_length=4,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,serial=disk-9763,size=1G,ssd=1"}, + input: map[string]interface{}{"sata1": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=io_uring,backup=0,cache=directsync,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=5,iops_wr=11,iops_wr_max=13,iops_wr_max_length=4,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,serial=disk-9763,size=1G,ssd=1,wwn=500E9FBC00F2A6D3"}, output: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_1: &QemuSataStorage{Passthrough: &QemuSataPassthrough{ AsyncIO: QemuDiskAsyncIO_IOuring, Backup: false, @@ -3129,13 +3205,14 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: 13, BurstDuration: 4, Concurrent: 11}, }, }, - Cache: QemuDiskCache_DirectSync, - Discard: true, - EmulateSSD: true, - File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", - Replicate: false, - Serial: "disk-9763", - Size: 1, + Cache: QemuDiskCache_DirectSync, + Discard: true, + EmulateSSD: true, + File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", + Replicate: false, + Serial: "disk-9763", + Size: 1, + WorldWideName: "500E9FBC00F2A6D3", }}}}}, }, {name: "Disks Sata Passthrough aio", @@ -3298,6 +3375,15 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { Replicate: true, }}}}}, }, + {name: "Disks Sata Passthrough wwn", + input: map[string]interface{}{"sata5": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,wwn=0x5004D2EF00C8B57A"}, + output: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_5: &QemuSataStorage{Passthrough: &QemuSataPassthrough{ + Backup: true, + File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", + Replicate: true, + WorldWideName: "0x5004D2EF00C8B57A", + }}}}}, + }, // Disks Scsi CdRom {name: "Disks Scsi CdRom none", input: map[string]interface{}{"scsi30": "none,media=cdrom"}, @@ -3335,7 +3421,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks Scsi Disk ALL", - input: map[string]interface{}{"scsi1": "test:100/vm-100-disk-2.qcow2,aio=threads,backup=0,cache=writeback,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,iothread=1,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,ro=1,serial=disk-9763,size=32G,ssd=1"}, + input: map[string]interface{}{"scsi1": "test:100/vm-100-disk-2.qcow2,aio=threads,backup=0,cache=writeback,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,iothread=1,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,ro=1,serial=disk-9763,size=32G,ssd=1,wwn=0x500AF18700E9CD25"}, output: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_1: &QemuScsiStorage{Disk: &QemuScsiDisk{ AsyncIO: QemuDiskAsyncIO_Threads, Backup: false, @@ -3349,21 +3435,22 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: 13, BurstDuration: 5, Concurrent: 11}, }, }, - Cache: QemuDiskCache_WriteBack, - Discard: true, - EmulateSSD: true, - Format: QemuDiskFormat_Qcow2, - Id: uint2, - IOThread: true, - ReadOnly: true, - Replicate: false, - Serial: "disk-9763", - Size: 32, - Storage: "test", + Cache: QemuDiskCache_WriteBack, + Discard: true, + EmulateSSD: true, + Format: QemuDiskFormat_Qcow2, + Id: uint2, + IOThread: true, + ReadOnly: true, + Replicate: false, + Serial: "disk-9763", + Size: 32, + Storage: "test", + WorldWideName: "0x500AF18700E9CD25", }}}}}, }, {name: "Disks Scsi Disk ALL LinkedClone", - input: map[string]interface{}{"scsi1": "test:110/base-110-disk-1.qcow2/100/vm-100-disk-2.qcow2,aio=threads,backup=0,cache=writeback,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,iothread=1,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,ro=1,serial=disk-9763,size=32G,ssd=1"}, + input: map[string]interface{}{"scsi1": "test:110/base-110-disk-1.qcow2/100/vm-100-disk-2.qcow2,aio=threads,backup=0,cache=writeback,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,iothread=1,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,ro=1,serial=disk-9763,size=32G,ssd=1,wwn=0x500879DC00F3BE6A"}, output: &ConfigQemu{ LinkedVmId: 110, Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_1: &QemuScsiStorage{Disk: &QemuScsiDisk{ @@ -3379,18 +3466,19 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: 13, BurstDuration: 5, Concurrent: 11}, }, }, - Cache: QemuDiskCache_WriteBack, - Discard: true, - EmulateSSD: true, - Format: QemuDiskFormat_Qcow2, - Id: uint2, - IOThread: true, - LinkedDiskId: &uint1, - ReadOnly: true, - Replicate: false, - Serial: "disk-9763", - Size: 32, - Storage: "test", + Cache: QemuDiskCache_WriteBack, + Discard: true, + EmulateSSD: true, + Format: QemuDiskFormat_Qcow2, + Id: uint2, + IOThread: true, + LinkedDiskId: &uint1, + ReadOnly: true, + Replicate: false, + Serial: "disk-9763", + Size: 32, + Storage: "test", + WorldWideName: "0x500879DC00F3BE6A", }}}}}, }, {name: "Disks Scsi Disk aio", @@ -3622,6 +3710,17 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { Storage: "test", }}}}}, }, + {name: "Disks Scsi Disk wwn", + input: map[string]interface{}{"scsi19": "test:100/vm-100-disk-2.qcow2,wwn=0x500E265400A1F3D7"}, + output: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_19: &QemuScsiStorage{Disk: &QemuScsiDisk{ + Backup: true, + Format: QemuDiskFormat_Qcow2, + Id: uint2, + Replicate: true, + Storage: "test", + WorldWideName: "0x500E265400A1F3D7", + }}}}}, + }, // Disks Scsi Passthrough {name: "Disks Scsi Passthrough", input: map[string]interface{}{"scsi0": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8"}, @@ -3632,7 +3731,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks Scsi Passthrough All", - input: map[string]interface{}{"scsi1": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=threads,backup=0,cache=none,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,iothread=1,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,ro=1,serial=disk-9763,size=1G,ssd=1"}, + input: map[string]interface{}{"scsi1": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=threads,backup=0,cache=none,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,iothread=1,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,ro=1,serial=disk-9763,size=1G,ssd=1,wwn=500CB15600D8FE32"}, output: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_1: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{ AsyncIO: QemuDiskAsyncIO_Threads, Backup: false, @@ -3646,15 +3745,16 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: 13, BurstDuration: 5, Concurrent: 11}, }, }, - Cache: QemuDiskCache_None, - Discard: true, - EmulateSSD: true, - File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", - IOThread: true, - ReadOnly: true, - Replicate: false, - Serial: "disk-9763", - Size: 1, + Cache: QemuDiskCache_None, + Discard: true, + EmulateSSD: true, + File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", + IOThread: true, + ReadOnly: true, + Replicate: false, + Serial: "disk-9763", + Size: 1, + WorldWideName: "500CB15600D8FE32", }}}}}, }, {name: "Disks Scsi Passthrough aio", @@ -3835,6 +3935,15 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { Replicate: true, }}}}}, }, + {name: "Disks Scsi Passthrough wwn", + input: map[string]interface{}{"scsi19": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,wwn=0x5009A4FC00B7C613"}, + output: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_19: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{ + Backup: true, + File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", + Replicate: true, + WorldWideName: "0x5009A4FC00B7C613", + }}}}}, + }, // VirtIO CdRom {name: "Disks VirtIO CdRom none", input: map[string]interface{}{"virtio11": "none,media=cdrom"}, @@ -3872,7 +3981,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks VirtIO Disk ALL", - input: map[string]interface{}{"virtio1": "test2:100/vm-100-disk-31.qcow2,aio=io_uring,backup=0,cache=directsync,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=2,iops_wr=11,iops_wr_max=13,iops_wr_max_length=3,iothread=1,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,ro=1,serial=disk-9763,size=32G"}, + input: map[string]interface{}{"virtio1": "test2:100/vm-100-disk-31.qcow2,aio=io_uring,backup=0,cache=directsync,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=2,iops_wr=11,iops_wr_max=13,iops_wr_max_length=3,iothread=1,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,ro=1,serial=disk-9763,size=32G,wwn=0x50015B3900F8EAD2"}, output: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_1: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{ AsyncIO: QemuDiskAsyncIO_IOuring, Backup: false, @@ -3886,20 +3995,21 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: 13, BurstDuration: 3, Concurrent: 11}, }, }, - Cache: QemuDiskCache_DirectSync, - Discard: true, - Format: QemuDiskFormat_Qcow2, - Id: uint31, - IOThread: true, - ReadOnly: true, - Replicate: false, - Serial: "disk-9763", - Size: 32, - Storage: "test2", + Cache: QemuDiskCache_DirectSync, + Discard: true, + Format: QemuDiskFormat_Qcow2, + Id: uint31, + IOThread: true, + ReadOnly: true, + Replicate: false, + Serial: "disk-9763", + Size: 32, + Storage: "test2", + WorldWideName: "0x50015B3900F8EAD2", }}}}}, }, {name: "Disks VirtIO Disk ALL LinkedClone", - input: map[string]interface{}{"virtio1": "test2:110/base-110-disk-1.qcow2/100/vm-100-disk-31.qcow2,aio=io_uring,backup=0,cache=directsync,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=2,iops_wr=11,iops_wr_max=13,iops_wr_max_length=3,iothread=1,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,ro=1,serial=disk-9763,size=32G"}, + input: map[string]interface{}{"virtio1": "test2:110/base-110-disk-1.qcow2/100/vm-100-disk-31.qcow2,aio=io_uring,backup=0,cache=directsync,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=2,iops_wr=11,iops_wr_max=13,iops_wr_max_length=3,iothread=1,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,ro=1,serial=disk-9763,size=32G,wwn=0x500FA2D000C69587"}, output: &ConfigQemu{ LinkedVmId: 110, Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_1: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{ @@ -3915,17 +4025,18 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: 13, BurstDuration: 3, Concurrent: 11}, }, }, - Cache: QemuDiskCache_DirectSync, - Discard: true, - Format: QemuDiskFormat_Qcow2, - Id: uint31, - IOThread: true, - LinkedDiskId: &uint1, - ReadOnly: true, - Replicate: false, - Serial: "disk-9763", - Size: 32, - Storage: "test2", + Cache: QemuDiskCache_DirectSync, + Discard: true, + Format: QemuDiskFormat_Qcow2, + Id: uint31, + IOThread: true, + LinkedDiskId: &uint1, + ReadOnly: true, + Replicate: false, + Serial: "disk-9763", + Size: 32, + Storage: "test2", + WorldWideName: "0x500FA2D000C69587", }}}}}, }, {name: "Disks VirtIO Disk aio", @@ -4150,6 +4261,17 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { Storage: "test2", }}}}}, }, + {name: "Disks VirtIO Disk wwn", + input: map[string]interface{}{"virtio2": "test2:100/vm-100-disk-31.qcow2,wwn=0x500D3FAB00B4E672"}, + output: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_2: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{ + Backup: true, + Format: QemuDiskFormat_Qcow2, + Id: uint31, + Replicate: true, + Storage: "test2", + WorldWideName: "0x500D3FAB00B4E672", + }}}}}, + }, // Disks VirtIO Passthrough {name: "Disks VirtIO Passthrough", input: map[string]interface{}{"virtio0": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8"}, @@ -4160,7 +4282,7 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { }}}}}, }, {name: "Disks VirtIO Passthrough ALL", - input: map[string]interface{}{"virtio1": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=native,backup=0,cache=unsafe,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,iothread=1,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,ro=1,serial=disk-9763,size=1G"}, + input: map[string]interface{}{"virtio1": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,aio=native,backup=0,cache=unsafe,discard=on,iops_rd=10,iops_rd_max=12,iops_rd_max_length=4,iops_wr=11,iops_wr_max=13,iops_wr_max_length=5,iothread=1,mbps_rd=1.51,mbps_rd_max=3.51,mbps_wr=2.51,mbps_wr_max=4.51,replicate=0,ro=1,serial=disk-9763,size=1G,wwn=0x500B6ED600F1C945"}, output: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_1: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{ AsyncIO: QemuDiskAsyncIO_Native, Backup: false, @@ -4174,14 +4296,15 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { WriteLimit: QemuDiskBandwidthIopsLimit{Burst: 13, BurstDuration: 5, Concurrent: 11}, }, }, - Cache: QemuDiskCache_Unsafe, - Discard: true, - File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", - IOThread: true, - ReadOnly: true, - Replicate: false, - Serial: "disk-9763", - Size: 1, + Cache: QemuDiskCache_Unsafe, + Discard: true, + File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", + IOThread: true, + ReadOnly: true, + Replicate: false, + Serial: "disk-9763", + Size: 1, + WorldWideName: "0x500B6ED600F1C945", }}}}}, }, {name: "Disks VirtIO Passthrough aio", @@ -4353,6 +4476,15 @@ func Test_ConfigQemu_mapToStruct(t *testing.T) { Size: 1, }}}}}, }, + {name: "Disks VirtIO Passthrough wwn", + input: map[string]interface{}{"virtio2": "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8,wwn=0x5008FA6500D9C8B3"}, + output: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_2: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{ + Backup: true, + File: "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi8", + Replicate: true, + WorldWideName: "0x5008FA6500D9C8B3", + }}}}}, + }, // Iso {name: "Iso", input: map[string]interface{}{"ide2": "local:iso/debian-11.0.0-amd64-netinst.iso,media=cdrom,size=377M"}, From eb08997b596a8a192ced85f51d66e7930ffeb82c Mon Sep 17 00:00:00 2001 From: Tinyblargon <76069640+Tinyblargon@users.noreply.github.com> Date: Wed, 21 Jun 2023 20:00:22 +0000 Subject: [PATCH 2/4] feat: add logic for converting `wwn` Added logic for converting `wwn` between API and struct. --- proxmox/config_qemu_disk.go | 14 ++- proxmox/config_qemu_disk_ide.go | 148 +++++++++++++------------ proxmox/config_qemu_disk_sata.go | 148 +++++++++++++------------ proxmox/config_qemu_disk_scsi.go | 172 +++++++++++++++-------------- proxmox/config_qemu_disk_virtio.go | 160 ++++++++++++++------------- 5 files changed, 337 insertions(+), 305 deletions(-) diff --git a/proxmox/config_qemu_disk.go b/proxmox/config_qemu_disk.go index 8b31db7f..0176e719 100644 --- a/proxmox/config_qemu_disk.go +++ b/proxmox/config_qemu_disk.go @@ -187,8 +187,9 @@ type qemuDisk struct { Serial QemuDiskSerial Size uint // TODO custom type - Storage string // Only set for Disk - Type qemuDiskType + Storage string // Only set for Disk + Type qemuDiskType + WorldWideName QemuWorldWideName } const ( @@ -288,7 +289,9 @@ func (disk qemuDisk) mapToApiValues(vmID, LinkedVmId uint, currentStorage string if disk.Type != virtIO && disk.EmulateSSD { settings = settings + ",ssd=1" } - + if disk.WorldWideName != "" { + settings = settings + ",wwn=" + string(disk.WorldWideName) + } return } @@ -418,6 +421,9 @@ func (qemuDisk) mapToStruct(diskData string, settings map[string]interface{}, li if value, isSet := settings["ssd"]; isSet { disk.EmulateSSD, _ = strconv.ParseBool(value.(string)) } + if value, isSet := settings["wwn"]; isSet { + disk.WorldWideName = QemuWorldWideName(value.(string)) + } return &disk } @@ -1008,6 +1014,8 @@ type qemuUpdateChanges struct { Resize []qemuDiskResize } +type QemuWorldWideName string + func diskSubtypeSet(set bool) error { if set { return errors.New(Error_QemuDisk_MutuallyExclusive) diff --git a/proxmox/config_qemu_disk_ide.go b/proxmox/config_qemu_disk_ide.go index ed019ae3..52b495f5 100644 --- a/proxmox/config_qemu_disk_ide.go +++ b/proxmox/config_qemu_disk_ide.go @@ -6,38 +6,40 @@ import ( ) type QemuIdeDisk struct { - AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` - Backup bool `json:"backup"` - Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` - Cache QemuDiskCache `json:"cache,omitempty"` - Discard bool `json:"discard"` - EmulateSSD bool `json:"emulatessd"` - Format QemuDiskFormat `json:"format"` - Id uint `json:"id"` //Id is only returned and setting it has no effect - LinkedDiskId *uint `json:"linked"` //LinkedClone is only returned and setting it has no effect - Replicate bool `json:"replicate"` - Serial QemuDiskSerial `json:"serial,omitempty"` - Size uint `json:"size"` - Storage string `json:"storage"` + AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` + Backup bool `json:"backup"` + Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` + Cache QemuDiskCache `json:"cache,omitempty"` + Discard bool `json:"discard"` + EmulateSSD bool `json:"emulatessd"` + Format QemuDiskFormat `json:"format"` + Id uint `json:"id"` //Id is only returned and setting it has no effect + LinkedDiskId *uint `json:"linked"` //LinkedClone is only returned and setting it has no effect + Replicate bool `json:"replicate"` + Serial QemuDiskSerial `json:"serial,omitempty"` + Size uint `json:"size"` + Storage string `json:"storage"` + WorldWideName QemuWorldWideName `json:"wwn"` } func (disk *QemuIdeDisk) convertDataStructure() *qemuDisk { return &qemuDisk{ - AsyncIO: disk.AsyncIO, - Backup: disk.Backup, - Bandwidth: disk.Bandwidth, - Cache: disk.Cache, - Discard: disk.Discard, - Disk: true, - EmulateSSD: disk.EmulateSSD, - Format: disk.Format, - Id: disk.Id, - LinkedDiskId: disk.LinkedDiskId, - Replicate: disk.Replicate, - Serial: disk.Serial, - Size: disk.Size, - Storage: disk.Storage, - Type: ide, + AsyncIO: disk.AsyncIO, + Backup: disk.Backup, + Bandwidth: disk.Bandwidth, + Cache: disk.Cache, + Discard: disk.Discard, + Disk: true, + EmulateSSD: disk.EmulateSSD, + Format: disk.Format, + Id: disk.Id, + LinkedDiskId: disk.LinkedDiskId, + Replicate: disk.Replicate, + Serial: disk.Serial, + Size: disk.Size, + Storage: disk.Storage, + Type: ide, + WorldWideName: disk.WorldWideName, } } @@ -135,30 +137,32 @@ func (disks QemuIdeDisks) validate() (numberOfCloudInitDevices uint8, err error) } type QemuIdePassthrough struct { - AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` - Backup bool `json:"backup"` - Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` - Cache QemuDiskCache `json:"cache,omitempty"` - Discard bool `json:"discard"` - EmulateSSD bool `json:"emulatessd"` - File string `json:"file"` - Replicate bool `json:"replicate"` - Serial QemuDiskSerial `json:"serial,omitempty"` - Size uint `json:"size"` //size is only returned and setting it has no effect + AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` + Backup bool `json:"backup"` + Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` + Cache QemuDiskCache `json:"cache,omitempty"` + Discard bool `json:"discard"` + EmulateSSD bool `json:"emulatessd"` + File string `json:"file"` + Replicate bool `json:"replicate"` + Serial QemuDiskSerial `json:"serial,omitempty"` + Size uint `json:"size"` //size is only returned and setting it has no effect + WorldWideName QemuWorldWideName `json:"wwn"` } func (passthrough *QemuIdePassthrough) convertDataStructure() *qemuDisk { return &qemuDisk{ - AsyncIO: passthrough.AsyncIO, - Backup: passthrough.Backup, - Bandwidth: passthrough.Bandwidth, - Cache: passthrough.Cache, - Discard: passthrough.Discard, - EmulateSSD: passthrough.EmulateSSD, - File: passthrough.File, - Replicate: passthrough.Replicate, - Serial: passthrough.Serial, - Type: ide, + AsyncIO: passthrough.AsyncIO, + Backup: passthrough.Backup, + Bandwidth: passthrough.Bandwidth, + Cache: passthrough.Cache, + Discard: passthrough.Discard, + EmulateSSD: passthrough.EmulateSSD, + File: passthrough.File, + Replicate: passthrough.Replicate, + Serial: passthrough.Serial, + Type: ide, + WorldWideName: passthrough.WorldWideName, } } @@ -225,32 +229,34 @@ func (QemuIdeStorage) mapToStruct(param string, LinkedVmId *uint) *QemuIdeStorag } if tmpDisk.File == "" { return &QemuIdeStorage{Disk: &QemuIdeDisk{ - AsyncIO: tmpDisk.AsyncIO, - Backup: tmpDisk.Backup, - Bandwidth: tmpDisk.Bandwidth, - Cache: tmpDisk.Cache, - Discard: tmpDisk.Discard, - EmulateSSD: tmpDisk.EmulateSSD, - Format: tmpDisk.Format, - Id: tmpDisk.Id, - LinkedDiskId: tmpDisk.LinkedDiskId, - Replicate: tmpDisk.Replicate, - Serial: tmpDisk.Serial, - Size: tmpDisk.Size, - Storage: tmpDisk.Storage, + AsyncIO: tmpDisk.AsyncIO, + Backup: tmpDisk.Backup, + Bandwidth: tmpDisk.Bandwidth, + Cache: tmpDisk.Cache, + Discard: tmpDisk.Discard, + EmulateSSD: tmpDisk.EmulateSSD, + Format: tmpDisk.Format, + Id: tmpDisk.Id, + LinkedDiskId: tmpDisk.LinkedDiskId, + Replicate: tmpDisk.Replicate, + Serial: tmpDisk.Serial, + Size: tmpDisk.Size, + Storage: tmpDisk.Storage, + WorldWideName: tmpDisk.WorldWideName, }} } return &QemuIdeStorage{Passthrough: &QemuIdePassthrough{ - AsyncIO: tmpDisk.AsyncIO, - Backup: tmpDisk.Backup, - Bandwidth: tmpDisk.Bandwidth, - Cache: tmpDisk.Cache, - Discard: tmpDisk.Discard, - EmulateSSD: tmpDisk.EmulateSSD, - File: tmpDisk.File, - Replicate: tmpDisk.Replicate, - Serial: tmpDisk.Serial, - Size: tmpDisk.Size, + AsyncIO: tmpDisk.AsyncIO, + Backup: tmpDisk.Backup, + Bandwidth: tmpDisk.Bandwidth, + Cache: tmpDisk.Cache, + Discard: tmpDisk.Discard, + EmulateSSD: tmpDisk.EmulateSSD, + File: tmpDisk.File, + Replicate: tmpDisk.Replicate, + Serial: tmpDisk.Serial, + Size: tmpDisk.Size, + WorldWideName: tmpDisk.WorldWideName, }} } diff --git a/proxmox/config_qemu_disk_sata.go b/proxmox/config_qemu_disk_sata.go index d1c4b584..e4e89c42 100644 --- a/proxmox/config_qemu_disk_sata.go +++ b/proxmox/config_qemu_disk_sata.go @@ -6,38 +6,40 @@ import ( ) type QemuSataDisk struct { - AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` - Backup bool `json:"backup"` - Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` - Cache QemuDiskCache `json:"cache,omitempty"` - Discard bool `json:"discard"` - EmulateSSD bool `json:"emulatessd"` - Format QemuDiskFormat `json:"format"` - Id uint `json:"id"` //Id is only returned and setting it has no effect - LinkedDiskId *uint `json:"linked"` //LinkedClone is only returned and setting it has no effect - Replicate bool `json:"replicate"` - Serial QemuDiskSerial `json:"serial,omitempty"` - Size uint `json:"size"` - Storage string `json:"storage"` + AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` + Backup bool `json:"backup"` + Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` + Cache QemuDiskCache `json:"cache,omitempty"` + Discard bool `json:"discard"` + EmulateSSD bool `json:"emulatessd"` + Format QemuDiskFormat `json:"format"` + Id uint `json:"id"` //Id is only returned and setting it has no effect + LinkedDiskId *uint `json:"linked"` //LinkedClone is only returned and setting it has no effect + Replicate bool `json:"replicate"` + Serial QemuDiskSerial `json:"serial,omitempty"` + Size uint `json:"size"` + Storage string `json:"storage"` + WorldWideName QemuWorldWideName `json:"wwn"` } func (disk *QemuSataDisk) convertDataStructure() *qemuDisk { return &qemuDisk{ - AsyncIO: disk.AsyncIO, - Backup: disk.Backup, - Bandwidth: disk.Bandwidth, - Cache: disk.Cache, - Discard: disk.Discard, - Disk: true, - EmulateSSD: disk.EmulateSSD, - Format: disk.Format, - Id: disk.Id, - LinkedDiskId: disk.LinkedDiskId, - Replicate: disk.Replicate, - Serial: disk.Serial, - Size: disk.Size, - Storage: disk.Storage, - Type: sata, + AsyncIO: disk.AsyncIO, + Backup: disk.Backup, + Bandwidth: disk.Bandwidth, + Cache: disk.Cache, + Discard: disk.Discard, + Disk: true, + EmulateSSD: disk.EmulateSSD, + Format: disk.Format, + Id: disk.Id, + LinkedDiskId: disk.LinkedDiskId, + Replicate: disk.Replicate, + Serial: disk.Serial, + Size: disk.Size, + Storage: disk.Storage, + Type: sata, + WorldWideName: disk.WorldWideName, } } @@ -147,30 +149,32 @@ func (disks QemuSataDisks) validate() (numberOfCloudInitDevices uint8, err error } type QemuSataPassthrough struct { - AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` - Backup bool `json:"backup"` - Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` - Cache QemuDiskCache `json:"cache,omitempty"` - Discard bool `json:"discard"` - EmulateSSD bool `json:"emulatessd"` - File string `json:"file"` - Replicate bool `json:"replicate"` - Serial QemuDiskSerial `json:"serial,omitempty"` - Size uint `json:"size"` //size is only returned and setting it has no effect + AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` + Backup bool `json:"backup"` + Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` + Cache QemuDiskCache `json:"cache,omitempty"` + Discard bool `json:"discard"` + EmulateSSD bool `json:"emulatessd"` + File string `json:"file"` + Replicate bool `json:"replicate"` + Serial QemuDiskSerial `json:"serial,omitempty"` + Size uint `json:"size"` //size is only returned and setting it has no effect + WorldWideName QemuWorldWideName `json:"wwn"` } func (passthrough *QemuSataPassthrough) convertDataStructure() *qemuDisk { return &qemuDisk{ - AsyncIO: passthrough.AsyncIO, - Backup: passthrough.Backup, - Bandwidth: passthrough.Bandwidth, - Cache: passthrough.Cache, - Discard: passthrough.Discard, - EmulateSSD: passthrough.EmulateSSD, - File: passthrough.File, - Replicate: passthrough.Replicate, - Serial: passthrough.Serial, - Type: sata, + AsyncIO: passthrough.AsyncIO, + Backup: passthrough.Backup, + Bandwidth: passthrough.Bandwidth, + Cache: passthrough.Cache, + Discard: passthrough.Discard, + EmulateSSD: passthrough.EmulateSSD, + File: passthrough.File, + Replicate: passthrough.Replicate, + Serial: passthrough.Serial, + Type: sata, + WorldWideName: passthrough.WorldWideName, } } @@ -237,32 +241,34 @@ func (QemuSataStorage) mapToStruct(param string, LinkedVmId *uint) *QemuSataStor } if tmpDisk.File == "" { return &QemuSataStorage{Disk: &QemuSataDisk{ - AsyncIO: tmpDisk.AsyncIO, - Backup: tmpDisk.Backup, - Bandwidth: tmpDisk.Bandwidth, - Cache: tmpDisk.Cache, - Discard: tmpDisk.Discard, - EmulateSSD: tmpDisk.EmulateSSD, - Format: tmpDisk.Format, - Id: tmpDisk.Id, - LinkedDiskId: tmpDisk.LinkedDiskId, - Replicate: tmpDisk.Replicate, - Serial: tmpDisk.Serial, - Size: tmpDisk.Size, - Storage: tmpDisk.Storage, + AsyncIO: tmpDisk.AsyncIO, + Backup: tmpDisk.Backup, + Bandwidth: tmpDisk.Bandwidth, + Cache: tmpDisk.Cache, + Discard: tmpDisk.Discard, + EmulateSSD: tmpDisk.EmulateSSD, + Format: tmpDisk.Format, + Id: tmpDisk.Id, + LinkedDiskId: tmpDisk.LinkedDiskId, + Replicate: tmpDisk.Replicate, + Serial: tmpDisk.Serial, + Size: tmpDisk.Size, + Storage: tmpDisk.Storage, + WorldWideName: tmpDisk.WorldWideName, }} } return &QemuSataStorage{Passthrough: &QemuSataPassthrough{ - AsyncIO: tmpDisk.AsyncIO, - Backup: tmpDisk.Backup, - Bandwidth: tmpDisk.Bandwidth, - Cache: tmpDisk.Cache, - Discard: tmpDisk.Discard, - EmulateSSD: tmpDisk.EmulateSSD, - File: tmpDisk.File, - Replicate: tmpDisk.Replicate, - Serial: tmpDisk.Serial, - Size: tmpDisk.Size, + AsyncIO: tmpDisk.AsyncIO, + Backup: tmpDisk.Backup, + Bandwidth: tmpDisk.Bandwidth, + Cache: tmpDisk.Cache, + Discard: tmpDisk.Discard, + EmulateSSD: tmpDisk.EmulateSSD, + File: tmpDisk.File, + Replicate: tmpDisk.Replicate, + Serial: tmpDisk.Serial, + Size: tmpDisk.Size, + WorldWideName: tmpDisk.WorldWideName, }} } diff --git a/proxmox/config_qemu_disk_scsi.go b/proxmox/config_qemu_disk_scsi.go index 3ad5a1ea..e68ee370 100644 --- a/proxmox/config_qemu_disk_scsi.go +++ b/proxmox/config_qemu_disk_scsi.go @@ -6,42 +6,44 @@ import ( ) type QemuScsiDisk struct { - AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` - Backup bool `json:"backup"` - Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` - Cache QemuDiskCache `json:"cache,omitempty"` - Discard bool `json:"discard"` - EmulateSSD bool `json:"emulatessd"` - Format QemuDiskFormat `json:"format"` - Id uint `json:"id"` //Id is only returned and setting it has no effect - IOThread bool `json:"iothread"` - LinkedDiskId *uint `json:"linked"` //LinkedCloneId is only returned and setting it has no effect - ReadOnly bool `json:"readonly"` - Replicate bool `json:"replicate"` - Serial QemuDiskSerial `json:"serial,omitempty"` - Size uint `json:"size"` - Storage string `json:"storage"` + AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` + Backup bool `json:"backup"` + Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` + Cache QemuDiskCache `json:"cache,omitempty"` + Discard bool `json:"discard"` + EmulateSSD bool `json:"emulatessd"` + Format QemuDiskFormat `json:"format"` + Id uint `json:"id"` //Id is only returned and setting it has no effect + IOThread bool `json:"iothread"` + LinkedDiskId *uint `json:"linked"` //LinkedCloneId is only returned and setting it has no effect + ReadOnly bool `json:"readonly"` + Replicate bool `json:"replicate"` + Serial QemuDiskSerial `json:"serial,omitempty"` + Size uint `json:"size"` + Storage string `json:"storage"` + WorldWideName QemuWorldWideName `json:"wwn"` } func (disk *QemuScsiDisk) convertDataStructure() *qemuDisk { return &qemuDisk{ - AsyncIO: disk.AsyncIO, - Backup: disk.Backup, - Bandwidth: disk.Bandwidth, - Cache: disk.Cache, - Discard: disk.Discard, - Disk: true, - EmulateSSD: disk.EmulateSSD, - Format: disk.Format, - Id: disk.Id, - IOThread: disk.IOThread, - LinkedDiskId: disk.LinkedDiskId, - ReadOnly: disk.ReadOnly, - Replicate: disk.Replicate, - Serial: disk.Serial, - Size: disk.Size, - Storage: disk.Storage, - Type: scsi, + AsyncIO: disk.AsyncIO, + Backup: disk.Backup, + Bandwidth: disk.Bandwidth, + Cache: disk.Cache, + Discard: disk.Discard, + Disk: true, + EmulateSSD: disk.EmulateSSD, + Format: disk.Format, + Id: disk.Id, + IOThread: disk.IOThread, + LinkedDiskId: disk.LinkedDiskId, + ReadOnly: disk.ReadOnly, + Replicate: disk.Replicate, + Serial: disk.Serial, + Size: disk.Size, + Storage: disk.Storage, + Type: scsi, + WorldWideName: disk.WorldWideName, } } @@ -301,34 +303,36 @@ func (disks QemuScsiDisks) validate() (numberOfCloudInitDevices uint8, err error } type QemuScsiPassthrough struct { - AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` - Backup bool `json:"backup"` - Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` - Cache QemuDiskCache `json:"cache,omitempty"` - Discard bool `json:"discard"` - EmulateSSD bool `json:"emulatessd"` - File string `json:"file"` - IOThread bool `json:"iothread"` - ReadOnly bool `json:"readonly"` - Replicate bool `json:"replicate"` - Serial QemuDiskSerial `json:"serial,omitempty"` - Size uint `json:"size"` //size is only returned and setting it has no effect + AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` + Backup bool `json:"backup"` + Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` + Cache QemuDiskCache `json:"cache,omitempty"` + Discard bool `json:"discard"` + EmulateSSD bool `json:"emulatessd"` + File string `json:"file"` + IOThread bool `json:"iothread"` + ReadOnly bool `json:"readonly"` + Replicate bool `json:"replicate"` + Serial QemuDiskSerial `json:"serial,omitempty"` + Size uint `json:"size"` //size is only returned and setting it has no effect + WorldWideName QemuWorldWideName `json:"wwn"` } func (passthrough *QemuScsiPassthrough) convertDataStructure() *qemuDisk { return &qemuDisk{ - AsyncIO: passthrough.AsyncIO, - Backup: passthrough.Backup, - Bandwidth: passthrough.Bandwidth, - Cache: passthrough.Cache, - Discard: passthrough.Discard, - EmulateSSD: passthrough.EmulateSSD, - File: passthrough.File, - IOThread: passthrough.IOThread, - ReadOnly: passthrough.ReadOnly, - Replicate: passthrough.Replicate, - Serial: passthrough.Serial, - Type: scsi, + AsyncIO: passthrough.AsyncIO, + Backup: passthrough.Backup, + Bandwidth: passthrough.Bandwidth, + Cache: passthrough.Cache, + Discard: passthrough.Discard, + EmulateSSD: passthrough.EmulateSSD, + File: passthrough.File, + IOThread: passthrough.IOThread, + ReadOnly: passthrough.ReadOnly, + Replicate: passthrough.Replicate, + Serial: passthrough.Serial, + Type: scsi, + WorldWideName: passthrough.WorldWideName, } } @@ -395,36 +399,38 @@ func (QemuScsiStorage) mapToStruct(param string, LinkedVmId *uint) *QemuScsiStor } if tmpDisk.File == "" { return &QemuScsiStorage{Disk: &QemuScsiDisk{ - AsyncIO: tmpDisk.AsyncIO, - Backup: tmpDisk.Backup, - Bandwidth: tmpDisk.Bandwidth, - Cache: tmpDisk.Cache, - Discard: tmpDisk.Discard, - EmulateSSD: tmpDisk.EmulateSSD, - Format: tmpDisk.Format, - Id: tmpDisk.Id, - IOThread: tmpDisk.IOThread, - LinkedDiskId: tmpDisk.LinkedDiskId, - ReadOnly: tmpDisk.ReadOnly, - Replicate: tmpDisk.Replicate, - Serial: tmpDisk.Serial, - Size: tmpDisk.Size, - Storage: tmpDisk.Storage, + AsyncIO: tmpDisk.AsyncIO, + Backup: tmpDisk.Backup, + Bandwidth: tmpDisk.Bandwidth, + Cache: tmpDisk.Cache, + Discard: tmpDisk.Discard, + EmulateSSD: tmpDisk.EmulateSSD, + Format: tmpDisk.Format, + Id: tmpDisk.Id, + IOThread: tmpDisk.IOThread, + LinkedDiskId: tmpDisk.LinkedDiskId, + ReadOnly: tmpDisk.ReadOnly, + Replicate: tmpDisk.Replicate, + Serial: tmpDisk.Serial, + Size: tmpDisk.Size, + Storage: tmpDisk.Storage, + WorldWideName: tmpDisk.WorldWideName, }} } return &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{ - AsyncIO: tmpDisk.AsyncIO, - Backup: tmpDisk.Backup, - Bandwidth: tmpDisk.Bandwidth, - Cache: tmpDisk.Cache, - Discard: tmpDisk.Discard, - EmulateSSD: tmpDisk.EmulateSSD, - File: tmpDisk.File, - IOThread: tmpDisk.IOThread, - ReadOnly: tmpDisk.ReadOnly, - Replicate: tmpDisk.Replicate, - Serial: tmpDisk.Serial, - Size: tmpDisk.Size, + AsyncIO: tmpDisk.AsyncIO, + Backup: tmpDisk.Backup, + Bandwidth: tmpDisk.Bandwidth, + Cache: tmpDisk.Cache, + Discard: tmpDisk.Discard, + EmulateSSD: tmpDisk.EmulateSSD, + File: tmpDisk.File, + IOThread: tmpDisk.IOThread, + ReadOnly: tmpDisk.ReadOnly, + Replicate: tmpDisk.Replicate, + Serial: tmpDisk.Serial, + Size: tmpDisk.Size, + WorldWideName: tmpDisk.WorldWideName, }} } diff --git a/proxmox/config_qemu_disk_virtio.go b/proxmox/config_qemu_disk_virtio.go index 4962d5e2..40973ca7 100644 --- a/proxmox/config_qemu_disk_virtio.go +++ b/proxmox/config_qemu_disk_virtio.go @@ -6,40 +6,42 @@ import ( ) type QemuVirtIODisk struct { - AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` - Backup bool `json:"backup"` - Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` - Cache QemuDiskCache `json:"cache,omitempty"` - Discard bool `json:"discard"` - Format QemuDiskFormat `json:"format"` - Id uint `json:"id"` //Id is only returned and setting it has no effect - IOThread bool `json:"iothread"` - LinkedDiskId *uint `json:"linked"` //LinkedCloneId is only returned and setting it has no effect - ReadOnly bool `json:"readonly"` - Replicate bool `json:"replicate"` - Serial QemuDiskSerial `json:"serial,omitempty"` - Size uint `json:"size"` - Storage string `json:"storage"` + AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` + Backup bool `json:"backup"` + Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` + Cache QemuDiskCache `json:"cache,omitempty"` + Discard bool `json:"discard"` + Format QemuDiskFormat `json:"format"` + Id uint `json:"id"` //Id is only returned and setting it has no effect + IOThread bool `json:"iothread"` + LinkedDiskId *uint `json:"linked"` //LinkedCloneId is only returned and setting it has no effect + ReadOnly bool `json:"readonly"` + Replicate bool `json:"replicate"` + Serial QemuDiskSerial `json:"serial,omitempty"` + Size uint `json:"size"` + Storage string `json:"storage"` + WorldWideName QemuWorldWideName `json:"wwn"` } func (disk *QemuVirtIODisk) convertDataStructure() *qemuDisk { return &qemuDisk{ - AsyncIO: disk.AsyncIO, - Backup: disk.Backup, - Bandwidth: disk.Bandwidth, - Cache: disk.Cache, - Discard: disk.Discard, - Disk: true, - Format: disk.Format, - Id: disk.Id, - IOThread: disk.IOThread, - LinkedDiskId: disk.LinkedDiskId, - ReadOnly: disk.ReadOnly, - Replicate: disk.Replicate, - Serial: disk.Serial, - Size: disk.Size, - Storage: disk.Storage, - Type: virtIO, + AsyncIO: disk.AsyncIO, + Backup: disk.Backup, + Bandwidth: disk.Bandwidth, + Cache: disk.Cache, + Discard: disk.Discard, + Disk: true, + Format: disk.Format, + Id: disk.Id, + IOThread: disk.IOThread, + LinkedDiskId: disk.LinkedDiskId, + ReadOnly: disk.ReadOnly, + Replicate: disk.Replicate, + Serial: disk.Serial, + Size: disk.Size, + Storage: disk.Storage, + Type: virtIO, + WorldWideName: disk.WorldWideName, } } @@ -209,32 +211,34 @@ func (disks QemuVirtIODisks) validate() (numberOfCloudInitDevices uint8, err err } type QemuVirtIOPassthrough struct { - AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` - Backup bool `json:"backup"` - Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` - Cache QemuDiskCache `json:"cache,omitempty"` - Discard bool `json:"discard"` - File string `json:"file"` - IOThread bool `json:"iothread"` - ReadOnly bool `json:"readonly"` - Replicate bool `json:"replicate"` - Serial QemuDiskSerial `json:"serial,omitempty"` - Size uint `json:"size"` //size is only returned and setting it has no effect + AsyncIO QemuDiskAsyncIO `json:"asyncio,omitempty"` + Backup bool `json:"backup"` + Bandwidth QemuDiskBandwidth `json:"bandwidth,omitempty"` + Cache QemuDiskCache `json:"cache,omitempty"` + Discard bool `json:"discard"` + File string `json:"file"` + IOThread bool `json:"iothread"` + ReadOnly bool `json:"readonly"` + Replicate bool `json:"replicate"` + Serial QemuDiskSerial `json:"serial,omitempty"` + Size uint `json:"size"` //size is only returned and setting it has no effect + WorldWideName QemuWorldWideName `json:"wwn"` } func (passthrough *QemuVirtIOPassthrough) convertDataStructure() *qemuDisk { return &qemuDisk{ - AsyncIO: passthrough.AsyncIO, - Backup: passthrough.Backup, - Bandwidth: passthrough.Bandwidth, - Cache: passthrough.Cache, - Discard: passthrough.Discard, - File: passthrough.File, - IOThread: passthrough.IOThread, - ReadOnly: passthrough.ReadOnly, - Replicate: passthrough.Replicate, - Serial: passthrough.Serial, - Type: virtIO, + AsyncIO: passthrough.AsyncIO, + Backup: passthrough.Backup, + Bandwidth: passthrough.Bandwidth, + Cache: passthrough.Cache, + Discard: passthrough.Discard, + File: passthrough.File, + IOThread: passthrough.IOThread, + ReadOnly: passthrough.ReadOnly, + Replicate: passthrough.Replicate, + Serial: passthrough.Serial, + Type: virtIO, + WorldWideName: passthrough.WorldWideName, } } @@ -301,34 +305,36 @@ func (QemuVirtIOStorage) mapToStruct(param string, LinkedVmId *uint) *QemuVirtIO } if tmpDisk.File == "" { return &QemuVirtIOStorage{Disk: &QemuVirtIODisk{ - AsyncIO: tmpDisk.AsyncIO, - Backup: tmpDisk.Backup, - Bandwidth: tmpDisk.Bandwidth, - Cache: tmpDisk.Cache, - Discard: tmpDisk.Discard, - Format: tmpDisk.Format, - Id: tmpDisk.Id, - IOThread: tmpDisk.IOThread, - LinkedDiskId: tmpDisk.LinkedDiskId, - ReadOnly: tmpDisk.ReadOnly, - Replicate: tmpDisk.Replicate, - Serial: tmpDisk.Serial, - Size: tmpDisk.Size, - Storage: tmpDisk.Storage, + AsyncIO: tmpDisk.AsyncIO, + Backup: tmpDisk.Backup, + Bandwidth: tmpDisk.Bandwidth, + Cache: tmpDisk.Cache, + Discard: tmpDisk.Discard, + Format: tmpDisk.Format, + Id: tmpDisk.Id, + IOThread: tmpDisk.IOThread, + LinkedDiskId: tmpDisk.LinkedDiskId, + ReadOnly: tmpDisk.ReadOnly, + Replicate: tmpDisk.Replicate, + Serial: tmpDisk.Serial, + Size: tmpDisk.Size, + Storage: tmpDisk.Storage, + WorldWideName: tmpDisk.WorldWideName, }} } return &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{ - AsyncIO: tmpDisk.AsyncIO, - Backup: tmpDisk.Backup, - Bandwidth: tmpDisk.Bandwidth, - Cache: tmpDisk.Cache, - Discard: tmpDisk.Discard, - File: tmpDisk.File, - IOThread: tmpDisk.IOThread, - ReadOnly: tmpDisk.ReadOnly, - Replicate: tmpDisk.Replicate, - Serial: tmpDisk.Serial, - Size: tmpDisk.Size, + AsyncIO: tmpDisk.AsyncIO, + Backup: tmpDisk.Backup, + Bandwidth: tmpDisk.Bandwidth, + Cache: tmpDisk.Cache, + Discard: tmpDisk.Discard, + File: tmpDisk.File, + IOThread: tmpDisk.IOThread, + ReadOnly: tmpDisk.ReadOnly, + Replicate: tmpDisk.Replicate, + Serial: tmpDisk.Serial, + Size: tmpDisk.Size, + WorldWideName: tmpDisk.WorldWideName, }} } From 0c3dcc2958491e8e5022e6020fc9c43cde672db2 Mon Sep 17 00:00:00 2001 From: Tinyblargon <76069640+Tinyblargon@users.noreply.github.com> Date: Wed, 21 Jun 2023 21:20:06 +0000 Subject: [PATCH 3/4] test: added for `QemuWorldWideName` --- proxmox/config_qemu_disk_test.go | 22 +++ proxmox/config_qemu_test.go | 140 +++++++++++++----- .../test_data_qemu/type_QemuWorldWideName.go | 112 ++++++++++++++ 3 files changed, 234 insertions(+), 40 deletions(-) create mode 100644 test/data/test_data_qemu/type_QemuWorldWideName.go diff --git a/proxmox/config_qemu_disk_test.go b/proxmox/config_qemu_disk_test.go index 2f5c23ac..4080e082 100644 --- a/proxmox/config_qemu_disk_test.go +++ b/proxmox/config_qemu_disk_test.go @@ -836,3 +836,25 @@ func Test_QemuStorages_markDiskChanges(t *testing.T) { }) } } + +func Test_QemuWorldWideName_Validate(t *testing.T) { + testRunes := struct { + legal []string + illegal []string + }{ + legal: test_data_qemu.QemuWorldWideName_Legal(), + illegal: test_data_qemu.QemuWorldWideName_Illegal(), + } + for _, test := range testRunes.legal { + name := "legal:" + test + t.Run(name, func(*testing.T) { + require.NoError(t, QemuWorldWideName(test).Validate(), name) + }) + } + for _, test := range testRunes.illegal { + name := "illegal:" + test + t.Run(name, func(*testing.T) { + require.Error(t, QemuWorldWideName(test).Validate(), name) + }) + } +} diff --git a/proxmox/config_qemu_test.go b/proxmox/config_qemu_test.go index 96acaf96..5c4ddd8b 100644 --- a/proxmox/config_qemu_test.go +++ b/proxmox/config_qemu_test.go @@ -4649,36 +4649,40 @@ func Test_ConfigQemu_Validate(t *testing.T) { {name: "Valid Disks Disk", input: ConfigQemu{Disks: &QemuStorages{ Ide: &QemuIdeDisks{Disk_0: &QemuIdeStorage{Disk: &QemuIdeDisk{ - AsyncIO: QemuDiskAsyncIO_IOuring, - Bandwidth: BandwidthValid0, - Cache: QemuDiskCache_DirectSync, - Format: QemuDiskFormat_Raw, - Size: 32, - Storage: "test", + AsyncIO: QemuDiskAsyncIO_IOuring, + Bandwidth: BandwidthValid0, + Cache: QemuDiskCache_DirectSync, + Format: QemuDiskFormat_Raw, + Size: 32, + Storage: "test", + WorldWideName: "0x500A1B2C3D4E5F60", }}}, Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Disk: &QemuSataDisk{ - AsyncIO: QemuDiskAsyncIO_Native, - Bandwidth: BandwidthValid1, - Cache: QemuDiskCache_None, - Format: QemuDiskFormat_Cow, - Size: 1, - Storage: "test", + AsyncIO: QemuDiskAsyncIO_Native, + Bandwidth: BandwidthValid1, + Cache: QemuDiskCache_None, + Format: QemuDiskFormat_Cow, + Size: 1, + Storage: "test", + WorldWideName: "0x500F123456789ABC", }}}, Scsi: &QemuScsiDisks{Disk_0: &QemuScsiStorage{Disk: &QemuScsiDisk{ - AsyncIO: QemuDiskAsyncIO_Threads, - Bandwidth: BandwidthValid2, - Cache: QemuDiskCache_WriteBack, - Format: QemuDiskFormat_Qcow2, - Size: 10, - Storage: "test", + AsyncIO: QemuDiskAsyncIO_Threads, + Bandwidth: BandwidthValid2, + Cache: QemuDiskCache_WriteBack, + Format: QemuDiskFormat_Qcow2, + Size: 10, + Storage: "test", + WorldWideName: "0x5009876543210DEF", }}}, VirtIO: &QemuVirtIODisks{Disk_0: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{ - AsyncIO: "", - Bandwidth: BandwidthValid3, - Cache: "", - Format: QemuDiskFormat_Vmdk, - Size: 1024, - Storage: "test", + AsyncIO: "", + Bandwidth: BandwidthValid3, + Cache: "", + Format: QemuDiskFormat_Vmdk, + Size: 1024, + Storage: "test", + WorldWideName: "0x500C0D0E0F101112", }}}, }}, }, @@ -4686,28 +4690,32 @@ func Test_ConfigQemu_Validate(t *testing.T) { {name: "Valid Disks Passthrough", input: ConfigQemu{Disks: &QemuStorages{ Ide: &QemuIdeDisks{Disk_0: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{ - AsyncIO: QemuDiskAsyncIO_IOuring, - Bandwidth: BandwidthValid3, - Cache: QemuDiskCache_DirectSync, - File: "test", + AsyncIO: QemuDiskAsyncIO_IOuring, + Bandwidth: BandwidthValid3, + Cache: QemuDiskCache_DirectSync, + File: "test", + WorldWideName: "0x5001A2B3C4D5E6F7", }}}, Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Passthrough: &QemuSataPassthrough{ - AsyncIO: QemuDiskAsyncIO_Native, - Bandwidth: BandwidthValid2, - Cache: "", - File: "test", + AsyncIO: QemuDiskAsyncIO_Native, + Bandwidth: BandwidthValid2, + Cache: "", + File: "test", + WorldWideName: "0x500B0A0908070605", }}}, Scsi: &QemuScsiDisks{Disk_0: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{ - AsyncIO: QemuDiskAsyncIO_Threads, - Bandwidth: BandwidthValid1, - Cache: QemuDiskCache_WriteBack, - File: "test", + AsyncIO: QemuDiskAsyncIO_Threads, + Bandwidth: BandwidthValid1, + Cache: QemuDiskCache_WriteBack, + File: "test", + WorldWideName: "0x500F1E2D3C4B5A69", }}}, VirtIO: &QemuVirtIODisks{Disk_0: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{ - AsyncIO: "", - Bandwidth: BandwidthValid0, - Cache: QemuDiskCache_WriteThrough, - File: "test", + AsyncIO: "", + Bandwidth: BandwidthValid0, + Cache: QemuDiskCache_WriteThrough, + File: "test", + WorldWideName: "0x5004A3B2C1D0E0F1", }}}, }}, }, @@ -5292,6 +5300,15 @@ func Test_ConfigQemu_Validate(t *testing.T) { }}}}}, err: errors.New(Error_QemuDisk_Storage), }, + {name: `Invalid Disks Disk Ide errors.New(Error_QemuWorldWideName_Invalid)`, + input: ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_0: &QemuIdeStorage{Disk: &QemuIdeDisk{ + Format: QemuDiskFormat_Raw, + Size: 32, + Storage: "Test", + WorldWideName: "0xG123456789ABCDE", + }}}}}, + err: errors.New(Error_QemuWorldWideName_Invalid), + }, // Invalid Disks Disk Sata {name: `Invalid Disks Disk Sata QemuDiskFormat("").Error()`, input: ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Disk: &QemuSataDisk{}}}}}, @@ -5370,6 +5387,15 @@ func Test_ConfigQemu_Validate(t *testing.T) { }}}}}, err: errors.New(Error_QemuDisk_Storage), }, + {name: `Invalid Disks Disk Sata errors.New(Error_QemuWorldWideName_Invalid)`, + input: ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Disk: &QemuSataDisk{ + Format: QemuDiskFormat_Raw, + Size: 32, + Storage: "Test", + WorldWideName: "500A1B2C3D4E5F60", + }}}}}, + err: errors.New(Error_QemuWorldWideName_Invalid), + }, // Invalid Disks Disk Scsi {name: `Invalid Disks Disk Scsi QemuDiskFormat("").Error()`, input: ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_0: &QemuScsiStorage{Disk: &QemuScsiDisk{}}}}}, @@ -5448,6 +5474,15 @@ func Test_ConfigQemu_Validate(t *testing.T) { }}}}}, err: errors.New(Error_QemuDisk_Storage), }, + {name: `Invalid Disks Disk Scsi errors.New(Error_QemuWorldWideName_Invalid)`, + input: ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_16: &QemuScsiStorage{Disk: &QemuScsiDisk{ + Format: QemuDiskFormat_Raw, + Size: 32, + Storage: "Test", + WorldWideName: "0x5009876543210DEFG", + }}}}}, + err: errors.New(Error_QemuWorldWideName_Invalid), + }, // Invalid Disks Disk VirtIO {name: `Invalid Disks Disk VirtIO QemuDiskFormat("").Error()`, input: ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_0: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{}}}}}, @@ -5526,6 +5561,15 @@ func Test_ConfigQemu_Validate(t *testing.T) { }}}}}, err: errors.New(Error_QemuDisk_Storage), }, + {name: `Invalid Disks Disk VirtIO errors.New(Error_QemuWorldWideName_Invalid)`, + input: ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_0: &QemuVirtIOStorage{Disk: &QemuVirtIODisk{ + Format: QemuDiskFormat_Raw, + Size: 32, + Storage: "Test", + WorldWideName: "500C0D0E0F10111", + }}}}}, + err: errors.New(Error_QemuWorldWideName_Invalid), + }, // Invalid Disks Passthrough Ide {name: `Invalid Disks Passthrough Ide QemuDiskAsyncIO("").Error()`, input: ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_0: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{AsyncIO: "invalid"}}}}}, @@ -5579,6 +5623,10 @@ func Test_ConfigQemu_Validate(t *testing.T) { input: ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_0: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{File: "/dev/disk/by-id/scsi1", Serial: QemuDiskSerial(test_data_qemu.QemuDiskSerial_Max_Illegal())}}}}}, err: errors.New(Error_QemuDiskSerial_IllegalLength), }, + {name: `Invalid Disks Passthrough Ide errors.New(Error_QemuWorldWideName_Invalid)`, + input: ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_1: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{File: "/dev/disk/by-id/scsi1", WorldWideName: "5001A2B3C4D5E6F7"}}}}}, + err: errors.New(Error_QemuWorldWideName_Invalid), + }, // Invalid Disks Passthrough Sata {name: `Invalid Disks Passthrough Sata QemuDiskAsyncIO("").Error()`, input: ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Passthrough: &QemuSataPassthrough{AsyncIO: "invalid"}}}}}, @@ -5632,6 +5680,10 @@ func Test_ConfigQemu_Validate(t *testing.T) { input: ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Passthrough: &QemuSataPassthrough{File: "/dev/disk/by-id/scsi1", Serial: QemuDiskSerial(test_data_qemu.QemuDiskSerial_Max_Illegal())}}}}}, err: errors.New(Error_QemuDiskSerial_IllegalLength), }, + {name: `Invalid Disks Passthrough Sata errors.New(Error_QemuWorldWideName_Invalid)`, + input: ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_1: &QemuSataStorage{Passthrough: &QemuSataPassthrough{File: "/dev/disk/by-id/scsi1", WorldWideName: "0x500B0A09080706050"}}}}}, + err: errors.New(Error_QemuWorldWideName_Invalid), + }, // Invalid Disks Passthrough Scsi {name: `Invalid Disks Passthrough Scsi QemuDiskAsyncIO("").Error()`, input: ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_0: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{AsyncIO: "invalid"}}}}}, @@ -5685,6 +5737,10 @@ func Test_ConfigQemu_Validate(t *testing.T) { input: ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_12: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{File: "/dev/disk/by-id/scsi1", Serial: QemuDiskSerial(test_data_qemu.QemuDiskSerial_Max_Illegal())}}}}}, err: errors.New(Error_QemuDiskSerial_IllegalLength), }, + {name: `Invalid Disks Passthrough Scsi errors.New(Error_QemuWorldWideName_Invalid)`, + input: ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_13: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{File: "/dev/disk/by-id/scsi1", WorldWideName: "500F1E2D3C4B5A69!"}}}}}, + err: errors.New(Error_QemuWorldWideName_Invalid), + }, // Invalid Disks Passthrough VirtIO {name: `Invalid Disks Passthrough VirtIO QemuDiskAsyncIO("").Error()`, input: ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_0: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{AsyncIO: "invalid"}}}}}, @@ -5738,6 +5794,10 @@ func Test_ConfigQemu_Validate(t *testing.T) { input: ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_12: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{File: "/dev/disk/by-id/scsi1", Serial: QemuDiskSerial(test_data_qemu.QemuDiskSerial_Max_Illegal())}}}}}, err: errors.New(Error_QemuDiskSerial_IllegalLength), }, + {name: `Invalid Disks Passthrough VirtIO errors.New(Error_QemuWorldWideName_Invalid)`, + input: ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_13: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{File: "/dev/disk/by-id/scsi1", WorldWideName: "0x5004A3B2C1D0E0F1#"}}}}}, + err: errors.New(Error_QemuWorldWideName_Invalid), + }, } for _, test := range testData { t.Run(test.name, func(*testing.T) { diff --git a/test/data/test_data_qemu/type_QemuWorldWideName.go b/test/data/test_data_qemu/type_QemuWorldWideName.go new file mode 100644 index 00000000..3c10ad18 --- /dev/null +++ b/test/data/test_data_qemu/type_QemuWorldWideName.go @@ -0,0 +1,112 @@ +package test_data_qemu + +func QemuWorldWideName_Legal() []string { + return []string{ + "", + "0x8F14641E7F4B27D6", + "0x43135F8B89D7E9D9", + "0x0C92E69424B1609D", + "0x55049C1C8DA23E50", + "0x9F70557F3A5D09BC", + "0x2C04D021E89E41FD", + "0x3D7071A0976895A0", + "0x7914EAC8244DB5A2", + "0x30A8A0D6A24B9563", + "0x1DA1CDD690CE41FE", + "0x79D8D06D781F8D16", + "0x821F901FEFEA690F", + "0x13A9628C95F19A4F", + "0x6D9E42EFDE9EB1D1", + "0x2D7167DFCD4C5B48", + "0x5F792FE5AD87513D", + "0x9B9B9E1508D0B8B9", + "0x1C179E26A7B1A040", + "0x4C5DB30D3E9B1C0A", + "0x7AED3B1457078D6A", + "0x6F64A1761AB78825", + "0x5D8EDD9C5B95C478", + "0x3C2857A432EC3E9B", + "0x1EE0843512C6B6BE", + "0x45272E11136D0B4F", + "0x08C7D3C6E51EF776", + "0x28B3B1B41D53A770", + "0x4A937430E15BCE2B", + "0x183B7321B0F62A80", + "0x38C24563EAD1C289", + "0x5B1DAF347BEEF152", + "0x0E60D51E5CB50D1A", + "0x30B2393E28A3EDE4", + "0x47954C1E3B5CAB46", + "0x68C0D3D016D68C23", + "0x933BB8B523C8ACF6", + "0x1F25C742A9FBE60D", + "0x09B3EFEF2C88FFAC", + "0x8B0D9F41A15B7FA6", + "0x6E2A86B5E950857C", + "0x3F90A27347DC4F36", + "0x17619BC0F9F02DBB", + "0x31D591AE875E8712", + "0x787E9C1D6D25C12F", + "0x586AF239D285F6D5", + "0x961DDAA98CC9A58C", + "0x241FD8850C9CCDF2", + "0x9A4D8EAEBC50E3A9", + "0x6A33FEC7390CFC45", + "0x1B3CE82A3F2C8EFA", + "0x42C22809DB71A0E1", + } +} + +func QemuWorldWideName_Illegal() []string { + return []string{ + "0x44556677EEFF", + "0x09876:54321", + "0x1AB2:3C4D", + "586AF239D285F6D5,", + "0x0A0B0C0D0E0F", + "0x12:34:56:78", + "0x98:76:54:32", + "0x00:11:22:33:44:55:66:77", + "0xAA:BB:CC:DD:EE:FF", + "0x1:2:3:4:5:6:7", + "0122334455667788", + "x9A9B9C9D9E9F", + "0x1A1B1C1D1E1F", + "0x11223344AABBCC", + "x44556677", + "0x0987:6543", + "0x1A:B2:3C:4D", + "0x55667788", + "0x0A:0B:0C:0D", + "0x12:34:56", + "0x98:76:54", + "0x00:11:22:33:44:55:66", + "0xAA:BB:CC:DD:EE", + "1:2:3:4:5:6", + "0x11223344556677", + "9A9B9C9D9E9", + "0x1A1B1C1D1E", + "0x11223344AABBC", + "0x44556677EE", + "0x098765:54321", + "0x1AB:2C4D", + "0x556677889", + "0x0A0B0C0D0", + "12:34:5:78", + "0x98:76:54:3", + "0x00:11:22:33:44:55:6", + "0xAA:BB:CC:DD:EE:F", + "1:2:3:4:5:6:7", + "0x1122334455667", + "0x9A9B9C9D9E", + "0x1A1B1C1D1", + "11223344AABB", + "0x44556677EEF", + "0x09876:5432", + "0x1AB2:C4D", + "0x5566778899,", + "0x0A0B0C0D", + "0x12:34:56:7", + "x98:76:54:2", + } +} From 32d9a2dcbed4a5720e35eba0e051061d0ed66948 Mon Sep 17 00:00:00 2001 From: Tinyblargon <76069640+Tinyblargon@users.noreply.github.com> Date: Wed, 21 Jun 2023 21:21:13 +0000 Subject: [PATCH 4/4] feat: validator `QemuWorldWideName` --- proxmox/config_qemu_disk.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/proxmox/config_qemu_disk.go b/proxmox/config_qemu_disk.go index 0176e719..8539e1c5 100644 --- a/proxmox/config_qemu_disk.go +++ b/proxmox/config_qemu_disk.go @@ -443,6 +443,9 @@ func (disk *qemuDisk) validate() (err error) { if err = disk.Serial.Validate(); err != nil { return } + if err = disk.WorldWideName.Validate(); err != nil { + return + } if disk.Disk { // disk if err = disk.Format.Validate(); err != nil { @@ -1016,6 +1019,17 @@ type qemuUpdateChanges struct { type QemuWorldWideName string +const Error_QemuWorldWideName_Invalid string = "world wide name should be prefixed with 0x followed by 8 hexadecimal values" + +var regexp_QemuWorldWideName = regexp.MustCompile(`^0x[0-9A-Fa-f]{16}$`) + +func (wwn QemuWorldWideName) Validate() error { + if wwn == "" || regexp_QemuWorldWideName.MatchString(string(wwn)) { + return nil + } + return errors.New(Error_QemuWorldWideName_Invalid) +} + func diskSubtypeSet(set bool) error { if set { return errors.New(Error_QemuDisk_MutuallyExclusive)