feat: add cores
Some checks failed
CI / build (push) Failing after 3m25s
CI / lint (push) Failing after 2m45s
CI / pkl-validate (push) Successful in 10s
CI / integration-tests (push) Has been skipped
CI / conformance-tests (latest) (push) Has been skipped

This commit is contained in:
2026-02-01 18:01:40 +01:00
parent 8fb5730e6d
commit e93eecc143
4 changed files with 15 additions and 3 deletions

View File

@@ -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)

View File

@@ -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) {

View File

@@ -34,4 +34,7 @@ class LXC extends formae.Resource {
@formae.FieldHint {}
description: String?
@formae.FieldHint {}
cores: Int
}

View File

@@ -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"`