From e93eecc143310246eb5c868fc53c1f17800ca46b Mon Sep 17 00:00:00 2001 From: ManInDark <61268856+ManInDark@users.noreply.github.com> Date: Sun, 1 Feb 2026 18:01:40 +0100 Subject: [PATCH] feat: add cores --- proxmox.go | 5 +++-- proxmox_test.go | 8 +++++++- schema/pkl/proxmox.pkl | 3 +++ types.go | 2 ++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/proxmox.go b/proxmox.go index 959dbc5..4fe2a33 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 + arguments := "vmid=" + props.VMID + "&ostemplate=" + props.OSTemplate + "&hostname=" + props.Hostname + "&cores=" + strconv.Itoa(props.Cores) if props.Description != "" { arguments += "&description=" + props.Description } @@ -211,6 +211,7 @@ func (p *Plugin) Read(ctx context.Context, req *resource.ReadRequest) (*resource VMID: req.NativeID, Hostname: lxcdata.Hostname, Description: lxcdata.Description, + Cores: lxcdata.Cores, } propsJSON, err := json.Marshal(properties) @@ -301,7 +302,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 + arguments := "vmid=" + desir.VMID + "&hostname=" + desir.Hostname + "&description=" + desir.Description + "&cores=" + strconv.Itoa(desir.Cores) argumentBuffer := bytes.NewBuffer([]byte(arguments)) request, err := http.NewRequest("PUT", url, argumentBuffer) diff --git a/proxmox_test.go b/proxmox_test.go index cb564bf..395bbdc 100644 --- a/proxmox_test.go +++ b/proxmox_test.go @@ -33,6 +33,7 @@ func TestCreate(t *testing.T) { "hostname": "testlxc", "description": "none", "ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz", + "cores": 1, } propertiesJSON, err := json.Marshal(properties) @@ -107,6 +108,8 @@ func TestRead(t *testing.T) { require.NoError(t, err, "Properties should be valid JSON") require.Equal(t, "ntfy", props["hostname"], "hostname should match") 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") } func TestUpdate(t *testing.T) { @@ -118,6 +121,7 @@ func TestUpdate(t *testing.T) { "hostname": "testlxc", "description": "none", "ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz", + "cores": 1, }) desiredProperties, _ := json.Marshal(map[string]any{ @@ -125,6 +129,7 @@ func TestUpdate(t *testing.T) { "hostname": "testlxc-updated", "description": "none", "ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz", + "cores": 2, }) req := &resource.UpdateRequest{ @@ -151,7 +156,8 @@ func TestUpdate(t *testing.T) { err = json.Unmarshal([]byte(readResult.Properties), &props) require.Equal(t, "testlxc-updated", props["hostname"], "hostname should have changed") - // test if update has happened + const core_num float64 = 2 + require.Equal(t, core_num, props["cores"], "cores should have changed") } func TestList(t *testing.T) { diff --git a/schema/pkl/proxmox.pkl b/schema/pkl/proxmox.pkl index 15288a1..df32e0f 100644 --- a/schema/pkl/proxmox.pkl +++ b/schema/pkl/proxmox.pkl @@ -34,4 +34,7 @@ class LXC extends formae.Resource { @formae.FieldHint {} description: String? + @formae.FieldHint {} + cores: Int + } diff --git a/types.go b/types.go index e4a7fcd..8cec511 100644 --- a/types.go +++ b/types.go @@ -12,6 +12,7 @@ type LXCProperties struct { Hostname string `json:"hostname"` Description string `json:"description,omitempty"` OSTemplate string `json:"ostemplate,omitempty"` + Cores int `json:"cores"` } type ReadRequest struct { @@ -61,6 +62,7 @@ type StatusGeneralResponse struct { type StatusLXCConfig struct { Arch string `json:"arch"` + Cores int `json:"cores"` OSType string `json:"ostype"` RootFS string `json:"rootfs"` Hostname string `json:"hostname"`