mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-01 11:02:59 +00:00
* feat: add support for "args" flag for VM * switch from args to kvmarguments, update type * cosmetics: `kvmarguments` -> `kvm_arguments` also update doc to match description from the official PVE documentation. * fix(vm): Add parser for CustomEFIDisk * use parseDiskSize(&string) from utils.go for CustomEFIDisk * readd the remove space by github space * address linter errors, remove duplicated code, add unit test Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
package proxmox
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func ParseDiskSize(size *string) (int, error) {
|
|
if size == nil {
|
|
return 0, nil
|
|
}
|
|
|
|
if strings.HasSuffix(*size, "T") {
|
|
diskSize, err := strconv.Atoi(strings.TrimSuffix(*size, "T"))
|
|
if err != nil {
|
|
return -1, fmt.Errorf("failed to parse disk size: %w", err)
|
|
}
|
|
return int(math.Ceil(float64(diskSize) * 1024)), nil
|
|
}
|
|
|
|
if strings.HasSuffix(*size, "G") {
|
|
diskSize, err := strconv.Atoi(strings.TrimSuffix(*size, "G"))
|
|
if err != nil {
|
|
return -1, fmt.Errorf("failed to parse disk size: %w", err)
|
|
}
|
|
return diskSize, nil
|
|
}
|
|
|
|
if strings.HasSuffix(*size, "M") {
|
|
diskSize, err := strconv.Atoi(strings.TrimSuffix(*size, "M"))
|
|
if err != nil {
|
|
return -1, fmt.Errorf("failed to parse disk size: %w", err)
|
|
}
|
|
return int(math.Ceil(float64(diskSize) / 1024)), nil
|
|
}
|
|
|
|
return -1, fmt.Errorf("cannot parse disk size \"%s\"", *size)
|
|
}
|