Skip to content

Commit

Permalink
Fix non-working unit conversion
Browse files Browse the repository at this point in the history
Adjust package name to golang convention
  • Loading branch information
Steven committed Aug 15, 2018
1 parent d6f3707 commit 3ece023
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
4 changes: 2 additions & 2 deletions proxmox/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ func (c *Client) ResizeQemuDisk(vmr *VmRef, disk string, moreSizeGB int) (exitSt
return
}

func (c *Client) CreateQemuDisk(vmr *VmRef, vmId int, diskName string, diskSize int, unit sizeUnit.SizeUnit,
func (c *Client) CreateQemuDisk(vmr *VmRef, vmId int, diskName string, diskSize int, unit sizeunit.SizeUnit,
format string) error {
reqBody := ParamsToBody(map[string]string{
"filename": diskName,
"size": sizeUnit.FormatToShortString(diskSize, unit),
"size": sizeunit.FormatToShortString(diskSize, unit),
"format": format,
"vmid": strconv.Itoa(vmId),
})
Expand Down
12 changes: 3 additions & 9 deletions sizeunit/size_unit.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package sizeUnit
package sizeunit

import (
"fmt"
"strconv"
)

type SizeUnit uint64
type SizeUnit int64

const (
KB SizeUnit = 1 << (10 * (iota + 1))
Expand Down Expand Up @@ -34,11 +34,5 @@ func FormatToLongString(size int, sizeUnit SizeUnit) string {
}

func ConvertTo(size int, oldSizeUnit SizeUnit, newSizeUnit SizeUnit) (newSize int, newUnit SizeUnit) {
if oldSizeUnit < newSizeUnit {
return size / int(newSizeUnit), newSizeUnit
} else if newSizeUnit > oldSizeUnit {
return size * int(newSizeUnit), newSizeUnit
} else {
return size, newSizeUnit
}
return size * int(oldSizeUnit) / int(newSizeUnit), newSizeUnit
}

0 comments on commit 3ece023

Please sign in to comment.