Skip to content

Commit 2dcccf7

Browse files
authored
Merge pull request #11 from gecgooden/coersce-to-string-to-int
Support PVE 8's updated Memory typing
2 parents 328eed9 + 4663dfb commit 2dcccf7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

api/qemu_type.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,28 @@ package api
22

33
import (
44
"encoding/json"
5+
"strconv"
6+
"strings"
57
)
68

9+
type StringOrInt int
10+
11+
func (d *StringOrInt) UnmarshalJSON(b []byte) error {
12+
str := strings.Replace(string(b), "\"", "", -1)
13+
if str == "" {
14+
*d = StringOrInt(0)
15+
return nil
16+
}
17+
18+
parsed, err := strconv.ParseInt(str, 10, 64)
19+
if err != nil {
20+
return err
21+
}
22+
23+
*d = StringOrInt(parsed)
24+
return nil
25+
}
26+
727
type VirtualMachine struct {
828
Cpu float32 `json:",omitempty"`
929
Cpus int `json:"cpus,omitempty"`
@@ -496,7 +516,7 @@ type VirtualMachineConfig struct {
496516
// specifies the QEMU machine type
497517
Machine string `json:"machine,omitempty"`
498518
// amount of RAM for the VM in MiB : 16 ~
499-
Memory int `json:"memory,omitempty"`
519+
Memory StringOrInt `json:"memory,omitempty"`
500520
MigrateDowntime json.Number `json:"migrate_downtime,omitempty"`
501521
MigrateSpeed int `json:"migrate_speed,omitempty"`
502522
// name for VM. Only used on the configuration web interface

0 commit comments

Comments
 (0)