From 49fbf7c5a737b8b203339c6b663db8d7f2c7cf34 Mon Sep 17 00:00:00 2001 From: George Page Date: Mon, 8 Apr 2024 20:29:27 +0800 Subject: [PATCH 1/2] Coerse string from PVE API to int --- api/qemu_type.go | 22 +++++++++++++++++++++- go.mod | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/api/qemu_type.go b/api/qemu_type.go index 188ffdb..1e3f600 100644 --- a/api/qemu_type.go +++ b/api/qemu_type.go @@ -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"` @@ -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 diff --git a/go.mod b/go.mod index 38d468f..e77d525 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/k8s-proxmox/proxmox-go +module github.com/gecgooden/proxmox-go go 1.20 From 4663dfb682db2e234f76635e32d17d026a520e9a Mon Sep 17 00:00:00 2001 From: George Page Date: Thu, 2 May 2024 20:34:52 +0800 Subject: [PATCH 2/2] Revert go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index e77d525..38d468f 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/gecgooden/proxmox-go +module github.com/k8s-proxmox/proxmox-go go 1.20