feat: add cores
This commit is contained in:
@@ -124,7 +124,7 @@ func (p *Plugin) Create(ctx context.Context, req *resource.CreateRequest) (*reso
|
|||||||
|
|
||||||
client := &http.Client{}
|
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 != "" {
|
if props.Description != "" {
|
||||||
arguments += "&description=" + props.Description
|
arguments += "&description=" + props.Description
|
||||||
}
|
}
|
||||||
@@ -211,6 +211,7 @@ func (p *Plugin) Read(ctx context.Context, req *resource.ReadRequest) (*resource
|
|||||||
VMID: req.NativeID,
|
VMID: req.NativeID,
|
||||||
Hostname: lxcdata.Hostname,
|
Hostname: lxcdata.Hostname,
|
||||||
Description: lxcdata.Description,
|
Description: lxcdata.Description,
|
||||||
|
Cores: lxcdata.Cores,
|
||||||
}
|
}
|
||||||
|
|
||||||
propsJSON, err := json.Marshal(properties)
|
propsJSON, err := json.Marshal(properties)
|
||||||
@@ -301,7 +302,7 @@ func (p *Plugin) Update(ctx context.Context, req *resource.UpdateRequest) (*reso
|
|||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
|
||||||
url := config.URL + "/api2/json/nodes/" + config.NODE + "/lxc/" + desir.VMID + "/config"
|
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))
|
argumentBuffer := bytes.NewBuffer([]byte(arguments))
|
||||||
request, err := http.NewRequest("PUT", url, argumentBuffer)
|
request, err := http.NewRequest("PUT", url, argumentBuffer)
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ func TestCreate(t *testing.T) {
|
|||||||
"hostname": "testlxc",
|
"hostname": "testlxc",
|
||||||
"description": "none",
|
"description": "none",
|
||||||
"ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz",
|
"ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz",
|
||||||
|
"cores": 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
propertiesJSON, err := json.Marshal(properties)
|
propertiesJSON, err := json.Marshal(properties)
|
||||||
@@ -107,6 +108,8 @@ func TestRead(t *testing.T) {
|
|||||||
require.NoError(t, err, "Properties should be valid JSON")
|
require.NoError(t, err, "Properties should be valid JSON")
|
||||||
require.Equal(t, "ntfy", props["hostname"], "hostname should match")
|
require.Equal(t, "ntfy", props["hostname"], "hostname should match")
|
||||||
require.Equal(t, strconv.Itoa(120), props["vmid"], "vmid 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) {
|
func TestUpdate(t *testing.T) {
|
||||||
@@ -118,6 +121,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
"hostname": "testlxc",
|
"hostname": "testlxc",
|
||||||
"description": "none",
|
"description": "none",
|
||||||
"ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz",
|
"ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz",
|
||||||
|
"cores": 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
desiredProperties, _ := json.Marshal(map[string]any{
|
desiredProperties, _ := json.Marshal(map[string]any{
|
||||||
@@ -125,6 +129,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
"hostname": "testlxc-updated",
|
"hostname": "testlxc-updated",
|
||||||
"description": "none",
|
"description": "none",
|
||||||
"ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz",
|
"ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz",
|
||||||
|
"cores": 2,
|
||||||
})
|
})
|
||||||
|
|
||||||
req := &resource.UpdateRequest{
|
req := &resource.UpdateRequest{
|
||||||
@@ -151,7 +156,8 @@ func TestUpdate(t *testing.T) {
|
|||||||
|
|
||||||
err = json.Unmarshal([]byte(readResult.Properties), &props)
|
err = json.Unmarshal([]byte(readResult.Properties), &props)
|
||||||
require.Equal(t, "testlxc-updated", props["hostname"], "hostname should have changed")
|
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) {
|
func TestList(t *testing.T) {
|
||||||
|
|||||||
@@ -34,4 +34,7 @@ class LXC extends formae.Resource {
|
|||||||
@formae.FieldHint {}
|
@formae.FieldHint {}
|
||||||
description: String?
|
description: String?
|
||||||
|
|
||||||
|
@formae.FieldHint {}
|
||||||
|
cores: Int
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
2
types.go
2
types.go
@@ -12,6 +12,7 @@ type LXCProperties struct {
|
|||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
OSTemplate string `json:"ostemplate,omitempty"`
|
OSTemplate string `json:"ostemplate,omitempty"`
|
||||||
|
Cores int `json:"cores"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReadRequest struct {
|
type ReadRequest struct {
|
||||||
@@ -61,6 +62,7 @@ type StatusGeneralResponse struct {
|
|||||||
|
|
||||||
type StatusLXCConfig struct {
|
type StatusLXCConfig struct {
|
||||||
Arch string `json:"arch"`
|
Arch string `json:"arch"`
|
||||||
|
Cores int `json:"cores"`
|
||||||
OSType string `json:"ostype"`
|
OSType string `json:"ostype"`
|
||||||
RootFS string `json:"rootfs"`
|
RootFS string `json:"rootfs"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
|
|||||||
Reference in New Issue
Block a user