Skip to content

Commit

Permalink
Merge pull request #11 from gecgooden/coersce-to-string-to-int
Browse files Browse the repository at this point in the history
Support PVE 8's updated Memory typing
  • Loading branch information
sp-yduck authored Jun 26, 2024
2 parents 328eed9 + 4663dfb commit 2dcccf7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion api/qemu_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@ package api

import (
"encoding/json"
"strconv"
"strings"
)

type StringOrInt int

func (d *StringOrInt) UnmarshalJSON(b []byte) error {
str := strings.Replace(string(b), "\"", "", -1)
if str == "" {
*d = StringOrInt(0)
return nil
}

parsed, err := strconv.ParseInt(str, 10, 64)
if err != nil {
return err
}

*d = StringOrInt(parsed)
return nil
}

type VirtualMachine struct {
Cpu float32 `json:",omitempty"`
Cpus int `json:"cpus,omitempty"`
Expand Down Expand Up @@ -496,7 +516,7 @@ type VirtualMachineConfig struct {
// specifies the QEMU machine type
Machine string `json:"machine,omitempty"`
// amount of RAM for the VM in MiB : 16 ~
Memory int `json:"memory,omitempty"`
Memory StringOrInt `json:"memory,omitempty"`
MigrateDowntime json.Number `json:"migrate_downtime,omitempty"`
MigrateSpeed int `json:"migrate_speed,omitempty"`
// name for VM. Only used on the configuration web interface
Expand Down

0 comments on commit 2dcccf7

Please sign in to comment.