From ca99733c9c4f50e753f6b9b74ee8c8ebb0edd790 Mon Sep 17 00:00:00 2001 From: ManInDark <61268856+ManInDark@users.noreply.github.com> Date: Tue, 3 Feb 2026 21:52:55 +0100 Subject: [PATCH] feat: add memory --- proxmox.go | 5 +++-- proxmox_test.go | 7 +++++++ schema/pkl/proxmox.pkl | 3 +++ testdata/resource-replace.pkl | 2 ++ testdata/resource-update.pkl | 2 ++ testdata/resource.pkl | 2 ++ types.go | 1 + 7 files changed, 20 insertions(+), 2 deletions(-) diff --git a/proxmox.go b/proxmox.go index 4fe2a33..9f1b718 100644 --- a/proxmox.go +++ b/proxmox.go @@ -124,7 +124,7 @@ func (p *Plugin) Create(ctx context.Context, req *resource.CreateRequest) (*reso client := &http.Client{} - arguments := "vmid=" + props.VMID + "&ostemplate=" + props.OSTemplate + "&hostname=" + props.Hostname + "&cores=" + strconv.Itoa(props.Cores) + arguments := "vmid=" + props.VMID + "&ostemplate=" + props.OSTemplate + "&hostname=" + props.Hostname + "&cores=" + strconv.Itoa(props.Cores) + "&memory=" + strconv.Itoa(props.Memory) if props.Description != "" { arguments += "&description=" + props.Description } @@ -212,6 +212,7 @@ func (p *Plugin) Read(ctx context.Context, req *resource.ReadRequest) (*resource Hostname: lxcdata.Hostname, Description: lxcdata.Description, Cores: lxcdata.Cores, + Memory: lxcdata.Memory, } propsJSON, err := json.Marshal(properties) @@ -302,7 +303,7 @@ func (p *Plugin) Update(ctx context.Context, req *resource.UpdateRequest) (*reso client := &http.Client{} url := config.URL + "/api2/json/nodes/" + config.NODE + "/lxc/" + desir.VMID + "/config" - arguments := "vmid=" + desir.VMID + "&hostname=" + desir.Hostname + "&description=" + desir.Description + "&cores=" + strconv.Itoa(desir.Cores) + arguments := "vmid=" + desir.VMID + "&hostname=" + desir.Hostname + "&description=" + desir.Description + "&cores=" + strconv.Itoa(desir.Cores) + "&memory=" + strconv.Itoa(desir.Memory) argumentBuffer := bytes.NewBuffer([]byte(arguments)) request, err := http.NewRequest("PUT", url, argumentBuffer) diff --git a/proxmox_test.go b/proxmox_test.go index 395bbdc..632a720 100644 --- a/proxmox_test.go +++ b/proxmox_test.go @@ -34,6 +34,7 @@ func TestCreate(t *testing.T) { "description": "none", "ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz", "cores": 1, + "memory": 512, } propertiesJSON, err := json.Marshal(properties) @@ -110,6 +111,8 @@ func TestRead(t *testing.T) { require.Equal(t, strconv.Itoa(120), props["vmid"], "vmid should match") const core_num float64 = 1 require.Equal(t, core_num, props["cores"], "cores should match") + const mem_num float64 = 192 + require.Equal(t, mem_num, props["memory"], "memory should match") } func TestUpdate(t *testing.T) { @@ -122,6 +125,7 @@ func TestUpdate(t *testing.T) { "description": "none", "ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz", "cores": 1, + "memory": 512, }) desiredProperties, _ := json.Marshal(map[string]any{ @@ -130,6 +134,7 @@ func TestUpdate(t *testing.T) { "description": "none", "ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz", "cores": 2, + "memory": 1024, }) req := &resource.UpdateRequest{ @@ -158,6 +163,8 @@ func TestUpdate(t *testing.T) { require.Equal(t, "testlxc-updated", props["hostname"], "hostname should have changed") const core_num float64 = 2 require.Equal(t, core_num, props["cores"], "cores should have changed") + const mem_num float64 = 1024 + require.Equal(t, mem_num, props["memory"], "memory should have changed") } func TestList(t *testing.T) { diff --git a/schema/pkl/proxmox.pkl b/schema/pkl/proxmox.pkl index df32e0f..0636082 100644 --- a/schema/pkl/proxmox.pkl +++ b/schema/pkl/proxmox.pkl @@ -37,4 +37,7 @@ class LXC extends formae.Resource { @formae.FieldHint {} cores: Int + @formae.FieldHint {} + memory: Int + } diff --git a/testdata/resource-replace.pkl b/testdata/resource-replace.pkl index 7adfdda..348dd38 100644 --- a/testdata/resource-replace.pkl +++ b/testdata/resource-replace.pkl @@ -31,5 +31,7 @@ forma { hostname = "test-lxc" description = "some other description" ostemplate = "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz" + cores = 1 + memory = 512 } } diff --git a/testdata/resource-update.pkl b/testdata/resource-update.pkl index 9290ffa..ec05247 100644 --- a/testdata/resource-update.pkl +++ b/testdata/resource-update.pkl @@ -31,5 +31,7 @@ forma { hostname = "test-lxc" description = "some other description" ostemplate = "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz" + cores = 2 + memory = 1024 } } diff --git a/testdata/resource.pkl b/testdata/resource.pkl index f199d5c..23e97f9 100644 --- a/testdata/resource.pkl +++ b/testdata/resource.pkl @@ -33,5 +33,7 @@ forma { hostname = "test-lxc" description = "no description provided" ostemplate = "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz" + cores = 1 + memory = 512 } } diff --git a/types.go b/types.go index 8cec511..b106a2b 100644 --- a/types.go +++ b/types.go @@ -13,6 +13,7 @@ type LXCProperties struct { Description string `json:"description,omitempty"` OSTemplate string `json:"ostemplate,omitempty"` Cores int `json:"cores"` + Memory int `json:"memory"` } type ReadRequest struct {