Skip to content

Commit

Permalink
Merge pull request #293 from Tinyblargon/BugFix-Trim-Trailing-0
Browse files Browse the repository at this point in the history
fix: Trailing `0` and `.` not trimmed
  • Loading branch information
mleone87 authored Jan 9, 2024
2 parents db65649 + 1b7b2d6 commit 06f2d36
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 27 deletions.
8 changes: 4 additions & 4 deletions proxmox/config_qemu_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,17 @@ func (disk qemuDisk) mapToApiValues(vmID, LinkedVmId uint, currentStorage string
}

if disk.Bandwidth.MBps.ReadLimit.Concurrent != 0 {
settings = settings + fmt.Sprintf(",mbps_rd=%.2f", disk.Bandwidth.MBps.ReadLimit.Concurrent)
settings = settings + ",mbps_rd=" + floatToTrimmedString(float64(disk.Bandwidth.MBps.ReadLimit.Concurrent), 2)
}
if disk.Bandwidth.MBps.ReadLimit.Burst != 0 {
settings = settings + fmt.Sprintf(",mbps_rd_max=%.2f", disk.Bandwidth.MBps.ReadLimit.Burst)
settings = settings + ",mbps_rd_max=" + floatToTrimmedString(float64(disk.Bandwidth.MBps.ReadLimit.Burst), 2)
}

if disk.Bandwidth.MBps.WriteLimit.Concurrent != 0 {
settings = settings + fmt.Sprintf(",mbps_wr=%.2f", disk.Bandwidth.MBps.WriteLimit.Concurrent)
settings = settings + ",mbps_wr=" + floatToTrimmedString(float64(disk.Bandwidth.MBps.WriteLimit.Concurrent), 2)
}
if disk.Bandwidth.MBps.WriteLimit.Burst != 0 {
settings = settings + fmt.Sprintf(",mbps_wr_max=%.2f", disk.Bandwidth.MBps.WriteLimit.Burst)
settings = settings + ",mbps_wr_max=" + floatToTrimmedString(float64(disk.Bandwidth.MBps.WriteLimit.Burst), 2)
}

if !disk.Replicate {
Expand Down
46 changes: 23 additions & 23 deletions proxmox/config_qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
float10 := QemuDiskBandwidthMBpsLimitConcurrent(10.3)
float45 := QemuDiskBandwidthMBpsLimitConcurrent(45.23)
float79 := QemuDiskBandwidthMBpsLimitBurst(79.23)
float99 := QemuDiskBandwidthMBpsLimitBurst(99.2)
float99 := QemuDiskBandwidthMBpsLimitBurst(99.20)
uint1 := uint(1)
uint23 := QemuDiskBandwidthIopsLimitConcurrent(23)
uint34 := QemuDiskBandwidthIopsLimitConcurrent(34)
Expand Down Expand Up @@ -77,7 +77,7 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
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"},
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.3,mbps_rd_max=99.2,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}}}}},
Expand Down Expand Up @@ -137,11 +137,11 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
},
{name: "Create Disks.Ide.Disk_X.Disk.Bandwidth.MBps.ReadLimit.Burst",
config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_2: &QemuIdeStorage{Disk: &QemuIdeDisk{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Burst: float99}}}}}}}},
output: map[string]interface{}{"ide2": ",backup=0,mbps_rd_max=99.20,replicate=0"},
output: map[string]interface{}{"ide2": ",backup=0,mbps_rd_max=99.2,replicate=0"},
},
{name: "Create Disks.Ide.Disk_X.Disk.Bandwidth.MBps.ReadLimit.Concurrent",
config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_3: &QemuIdeStorage{Disk: &QemuIdeDisk{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Concurrent: float10}}}}}}}},
output: map[string]interface{}{"ide3": ",backup=0,mbps_rd=10.30,replicate=0"},
output: map[string]interface{}{"ide3": ",backup=0,mbps_rd=10.3,replicate=0"},
},
{name: "Create Disks.Ide.Disk_X.Disk.Bandwidth.MBps.WriteLimit",
config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_0: &QemuIdeStorage{Disk: &QemuIdeDisk{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{WriteLimit: QemuDiskBandwidthMBpsLimit{}}}}}}}},
Expand Down Expand Up @@ -214,7 +214,7 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
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,wwn=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.3,mbps_rd_max=99.2,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}}}}},
Expand Down Expand Up @@ -274,11 +274,11 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
},
{name: "Create Disks.Ide.Disk_X.Passthrough.Bandwidth.MBps.ReadLimit.Burst",
config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_2: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Burst: float99}}}}}}}},
output: map[string]interface{}{"ide2": ",backup=0,mbps_rd_max=99.20,replicate=0"},
output: map[string]interface{}{"ide2": ",backup=0,mbps_rd_max=99.2,replicate=0"},
},
{name: "Create Disks.Ide.Disk_X.Passthrough.Bandwidth.MBps.ReadLimit.Concurrent",
config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_3: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Concurrent: float10}}}}}}}},
output: map[string]interface{}{"ide3": ",backup=0,mbps_rd=10.30,replicate=0"},
output: map[string]interface{}{"ide3": ",backup=0,mbps_rd=10.3,replicate=0"},
},
{name: "Create Disks.Ide.Disk_X.Passthrough.Bandwidth.MBps.WriteLimit",
config: &ConfigQemu{Disks: &QemuStorages{Ide: &QemuIdeDisks{Disk_0: &QemuIdeStorage{Passthrough: &QemuIdePassthrough{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{WriteLimit: QemuDiskBandwidthMBpsLimit{}}}}}}}},
Expand Down Expand Up @@ -362,7 +362,7 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
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"},
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.3,mbps_rd_max=99.2,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}}}}},
Expand Down Expand Up @@ -422,11 +422,11 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
},
{name: "Create Disks.Sata.Disk_X.Disk.Bandwidth.MBps.ReadLimit.Burst",
config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_5: &QemuSataStorage{Disk: &QemuSataDisk{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Burst: float99}}}}}}}},
output: map[string]interface{}{"sata5": ",backup=0,mbps_rd_max=99.20,replicate=0"},
output: map[string]interface{}{"sata5": ",backup=0,mbps_rd_max=99.2,replicate=0"},
},
{name: "Create Disks.Sata.Disk_X.Disk.Bandwidth.MBps.ReadLimit.Concurrent",
config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Disk: &QemuSataDisk{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Concurrent: float10}}}}}}}},
output: map[string]interface{}{"sata0": ",backup=0,mbps_rd=10.30,replicate=0"},
output: map[string]interface{}{"sata0": ",backup=0,mbps_rd=10.3,replicate=0"},
},
{name: "Create Disks.Sata.Disk_X.Disk.Bandwidth.MBps.WriteLimit",
config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_1: &QemuSataStorage{Disk: &QemuSataDisk{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{WriteLimit: QemuDiskBandwidthMBpsLimit{}}}}}}}},
Expand Down Expand Up @@ -499,7 +499,7 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
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,wwn=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.3,mbps_rd_max=99.2,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}}}}},
Expand Down Expand Up @@ -559,11 +559,11 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
},
{name: "Create Disks.Sata.Disk_X.Passthrough.Bandwidth.MBps.ReadLimit.Burst",
config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_0: &QemuSataStorage{Passthrough: &QemuSataPassthrough{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Burst: float99}}}}}}}},
output: map[string]interface{}{"sata0": ",backup=0,mbps_rd_max=99.20,replicate=0"},
output: map[string]interface{}{"sata0": ",backup=0,mbps_rd_max=99.2,replicate=0"},
},
{name: "Create Disks.Sata.Disk_X.Passthrough.Bandwidth.MBps.ReadLimit.Concurrent",
config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_1: &QemuSataStorage{Passthrough: &QemuSataPassthrough{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Concurrent: float10}}}}}}}},
output: map[string]interface{}{"sata1": ",backup=0,mbps_rd=10.30,replicate=0"},
output: map[string]interface{}{"sata1": ",backup=0,mbps_rd=10.3,replicate=0"},
},
{name: "Create Disks.Sata.Disk_X.Passthrough.Bandwidth.MBps.WriteLimit",
config: &ConfigQemu{Disks: &QemuStorages{Sata: &QemuSataDisks{Disk_2: &QemuSataStorage{Passthrough: &QemuSataPassthrough{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{WriteLimit: QemuDiskBandwidthMBpsLimit{}}}}}}}},
Expand Down Expand Up @@ -649,7 +649,7 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
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"},
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.3,mbps_rd_max=99.2,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}}}}},
Expand Down Expand Up @@ -709,11 +709,11 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
},
{name: "Create Disks.Scsi.Disk_X.Disk.Bandwidth.MBps.ReadLimit.Burst",
config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_6: &QemuScsiStorage{Disk: &QemuScsiDisk{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Burst: float99}}}}}}}},
output: map[string]interface{}{"scsi6": ",backup=0,mbps_rd_max=99.20,replicate=0"},
output: map[string]interface{}{"scsi6": ",backup=0,mbps_rd_max=99.2,replicate=0"},
},
{name: "Create Disks.Scsi.Disk_X.Disk.Bandwidth.MBps.ReadLimit.Concurrent",
config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_7: &QemuScsiStorage{Disk: &QemuScsiDisk{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Concurrent: float10}}}}}}}},
output: map[string]interface{}{"scsi7": ",backup=0,mbps_rd=10.30,replicate=0"},
output: map[string]interface{}{"scsi7": ",backup=0,mbps_rd=10.3,replicate=0"},
},
{name: "Create Disks.Scsi.Disk_X.Disk.Bandwidth.MBps.WriteLimit",
config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_8: &QemuScsiStorage{Disk: &QemuScsiDisk{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{WriteLimit: QemuDiskBandwidthMBpsLimit{}}}}}}}},
Expand Down Expand Up @@ -796,7 +796,7 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
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"},
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.3,mbps_rd_max=99.2,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}}}}},
Expand Down Expand Up @@ -856,11 +856,11 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
},
{name: "Create Disks.Scsi.Disk_X.Passthrough.Bandwidth.MBps.ReadLimit.Burst",
config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_6: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Burst: float99}}}}}}}},
output: map[string]interface{}{"scsi6": ",backup=0,mbps_rd_max=99.20,replicate=0"},
output: map[string]interface{}{"scsi6": ",backup=0,mbps_rd_max=99.2,replicate=0"},
},
{name: "Create Disks.Scsi.Disk_X.Passthrough.Bandwidth.MBps.ReadLimit.Concurrent",
config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_7: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Concurrent: float10}}}}}}}},
output: map[string]interface{}{"scsi7": ",backup=0,mbps_rd=10.30,replicate=0"},
output: map[string]interface{}{"scsi7": ",backup=0,mbps_rd=10.3,replicate=0"},
},
{name: "Create Disks.Scsi.Disk_X.Passthrough.Bandwidth.MBps.WriteLimit",
config: &ConfigQemu{Disks: &QemuStorages{Scsi: &QemuScsiDisks{Disk_8: &QemuScsiStorage{Passthrough: &QemuScsiPassthrough{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{WriteLimit: QemuDiskBandwidthMBpsLimit{}}}}}}}},
Expand Down Expand Up @@ -953,7 +953,7 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
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"},
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.3,mbps_rd_max=99.2,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}}}}},
Expand Down Expand Up @@ -1103,7 +1103,7 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
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,wwn=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.3,mbps_rd_max=99.2,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}}}}},
Expand Down Expand Up @@ -1163,11 +1163,11 @@ func Test_ConfigQemu_mapToApiValues(t *testing.T) {
},
{name: "Create Disks.VirtIO.Disk_X.Passthrough.Bandwidth.MBps.ReadLimit.Burst",
config: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_6: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Burst: float99}}}}}}}},
output: map[string]interface{}{"virtio6": ",backup=0,mbps_rd_max=99.20,replicate=0"},
output: map[string]interface{}{"virtio6": ",backup=0,mbps_rd_max=99.2,replicate=0"},
},
{name: "Create Disks.VirtIO.Disk_X.Passthrough.Bandwidth.MBps.ReadLimit.Concurrent",
config: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_7: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{ReadLimit: QemuDiskBandwidthMBpsLimit{Concurrent: float10}}}}}}}},
output: map[string]interface{}{"virtio7": ",backup=0,mbps_rd=10.30,replicate=0"},
output: map[string]interface{}{"virtio7": ",backup=0,mbps_rd=10.3,replicate=0"},
},
{name: "Create Disks.VirtIO.Disk_X.Passthrough.Bandwidth.MBps.WriteLimit",
config: &ConfigQemu{Disks: &QemuStorages{VirtIO: &QemuVirtIODisks{Disk_8: &QemuVirtIOStorage{Passthrough: &QemuVirtIOPassthrough{Bandwidth: QemuDiskBandwidth{MBps: QemuDiskBandwidthMBps{WriteLimit: QemuDiskBandwidthMBpsLimit{}}}}}}}},
Expand Down
9 changes: 9 additions & 0 deletions proxmox/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ func keyExists(array []interface{}, key string) (existence bool) {
return false
}

// converts a float to a string with x number of decimals, and trims trailing zeros and the decimal point
func floatToTrimmedString(f float64, maxDecimals uint8) (s string) {
s = strings.TrimRight(strconv.FormatFloat(f, 'f', int(maxDecimals), 64), "0")
if s[len(s)-1:] == "." {
return s[:len(s)-1]
}
return
}

func splitStringOfSettings(settings string) map[string]interface{} {
settingValuePairs := strings.Split(settings, ",")
settingMap := map[string]interface{}{}
Expand Down
Loading

0 comments on commit 06f2d36

Please sign in to comment.