Skip to content

Commit

Permalink
Fix Cloud-init resizing
Browse files Browse the repository at this point in the history
Cloud init is returning a disk size in MB and the function diskSizeGB was not able to convert it in GB so the new disk size was not the wanted one.
I have also added support for other units, will be useful for the future.
  • Loading branch information
V-Paranoiaque committed Aug 16, 2019
1 parent 080c8ad commit f9032bf
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,24 @@ func prepareDiskSize(

func diskSizeGB(dcSize interface{}) float64 {
var diskSize float64
// TODO support other units M/G/K
switch dcSize.(type) {
case string:
diskSizeGB := dcSize.(string)
diskSize, _ = strconv.ParseFloat(strings.Trim(diskSizeGB, "G"), 64)
diskString := strings.ToUpper(dcSize.(string))
re := regexp.MustCompile("([0-9]+)([A-Z]*)")
diskArray := re.FindStringSubmatch(diskString)

diskSize, _ = strconv.ParseFloat(diskArray[1], 64)

if len(diskArray) >= 3 {
switch diskArray[2] {
case "G", "GB":
//Nothing to do
case "M", "MB":
diskSize /= 1000
case "K", "KB":
diskSize /= 1000000
}
}
case float64:
diskSize = dcSize.(float64)
}
Expand Down

0 comments on commit f9032bf

Please sign in to comment.