Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PVE 8's updated Memory typing #11

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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