feat: add onboot
This commit is contained in:
@@ -131,6 +131,9 @@ func (p *Plugin) Create(ctx context.Context, req *resource.CreateRequest) (*reso
|
|||||||
if props.Description != "" {
|
if props.Description != "" {
|
||||||
urlparams.Add("description", props.Description)
|
urlparams.Add("description", props.Description)
|
||||||
}
|
}
|
||||||
|
if props.OnBoot != 0 {
|
||||||
|
urlparams.Add("onboot", strconv.Itoa(props.OnBoot))
|
||||||
|
}
|
||||||
|
|
||||||
_, err = authenticatedRequest(http.MethodPost, config.URL+"/api2/json/nodes/"+config.NODE+"/lxc", createAuthorizationString(username, token), urlparams)
|
_, err = authenticatedRequest(http.MethodPost, config.URL+"/api2/json/nodes/"+config.NODE+"/lxc", createAuthorizationString(username, token), urlparams)
|
||||||
|
|
||||||
@@ -178,6 +181,7 @@ func (p *Plugin) Read(ctx context.Context, req *resource.ReadRequest) (*resource
|
|||||||
|
|
||||||
err = json.Unmarshal(data, &props)
|
err = json.Unmarshal(data, &props)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println("Error unmarshaling json: ", data)
|
||||||
return &resource.ReadResult{
|
return &resource.ReadResult{
|
||||||
ErrorCode: resource.OperationErrorCodeInvalidRequest,
|
ErrorCode: resource.OperationErrorCodeInvalidRequest,
|
||||||
}, err
|
}, err
|
||||||
@@ -191,6 +195,7 @@ func (p *Plugin) Read(ctx context.Context, req *resource.ReadRequest) (*resource
|
|||||||
Description: lxcdata.Description,
|
Description: lxcdata.Description,
|
||||||
Cores: lxcdata.Cores,
|
Cores: lxcdata.Cores,
|
||||||
Memory: lxcdata.Memory,
|
Memory: lxcdata.Memory,
|
||||||
|
OnBoot: lxcdata.OnBoot,
|
||||||
}
|
}
|
||||||
|
|
||||||
propsJSON, err := json.Marshal(properties)
|
propsJSON, err := json.Marshal(properties)
|
||||||
@@ -284,6 +289,9 @@ func (p *Plugin) Update(ctx context.Context, req *resource.UpdateRequest) (*reso
|
|||||||
"memory": {strconv.Itoa(desir.Memory)},
|
"memory": {strconv.Itoa(desir.Memory)},
|
||||||
"description": {desir.Description},
|
"description": {desir.Description},
|
||||||
}
|
}
|
||||||
|
if prior.OnBoot != desir.OnBoot {
|
||||||
|
urlparams.Add("onboot", strconv.Itoa(desir.OnBoot))
|
||||||
|
}
|
||||||
|
|
||||||
_, err = authenticatedRequest("PUT", config.URL+"/api2/json/nodes/"+config.NODE+"/lxc/"+desir.VMID+"/config", createAuthorizationString(username, token), urlparams)
|
_, err = authenticatedRequest("PUT", config.URL+"/api2/json/nodes/"+config.NODE+"/lxc/"+desir.VMID+"/config", createAuthorizationString(username, token), urlparams)
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ func TestRead(t *testing.T) {
|
|||||||
plugin := &Plugin{}
|
plugin := &Plugin{}
|
||||||
|
|
||||||
req := &resource.ReadRequest{
|
req := &resource.ReadRequest{
|
||||||
NativeID: strconv.Itoa(120),
|
NativeID: strconv.Itoa(200),
|
||||||
ResourceType: "PROXMOX::Service::LXC",
|
ResourceType: "PROXMOX::Service::LXC",
|
||||||
TargetConfig: testTargetConfig(),
|
TargetConfig: testTargetConfig(),
|
||||||
}
|
}
|
||||||
@@ -95,12 +95,14 @@ func TestRead(t *testing.T) {
|
|||||||
require.NoError(t, err, "json should be parsable")
|
require.NoError(t, err, "json should be parsable")
|
||||||
|
|
||||||
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, "testlxc", props["hostname"], "hostname should match")
|
||||||
require.Equal(t, strconv.Itoa(120), props["vmid"], "vmid should match")
|
require.Equal(t, strconv.Itoa(200), props["vmid"], "vmid should match")
|
||||||
const core_num float64 = 1
|
const core_num float64 = 1
|
||||||
require.Equal(t, core_num, props["cores"], "cores should match")
|
require.Equal(t, core_num, props["cores"], "cores should match")
|
||||||
const mem_num float64 = 192
|
const mem_num float64 = 512
|
||||||
require.Equal(t, mem_num, props["memory"], "memory should match")
|
require.Equal(t, mem_num, props["memory"], "memory should match")
|
||||||
|
const onboot float64 = 0
|
||||||
|
require.Equal(t, onboot, props["onboot"], "memory should match")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdate(t *testing.T) {
|
func TestUpdate(t *testing.T) {
|
||||||
@@ -123,6 +125,7 @@ func TestUpdate(t *testing.T) {
|
|||||||
"ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz",
|
"ostemplate": "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz",
|
||||||
"cores": 2,
|
"cores": 2,
|
||||||
"memory": 1024,
|
"memory": 1024,
|
||||||
|
"onboot": 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
req := &resource.UpdateRequest{
|
req := &resource.UpdateRequest{
|
||||||
@@ -153,6 +156,8 @@ func TestUpdate(t *testing.T) {
|
|||||||
require.Equal(t, core_num, props["cores"], "cores should have changed")
|
require.Equal(t, core_num, props["cores"], "cores should have changed")
|
||||||
const mem_num float64 = 1024
|
const mem_num float64 = 1024
|
||||||
require.Equal(t, mem_num, props["memory"], "memory should have changed")
|
require.Equal(t, mem_num, props["memory"], "memory should have changed")
|
||||||
|
const onboot float64 = 1
|
||||||
|
require.Equal(t, onboot, props["onboot"], "onboot should have changed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestList(t *testing.T) {
|
func TestList(t *testing.T) {
|
||||||
|
|||||||
@@ -40,4 +40,7 @@ class LXC extends formae.Resource {
|
|||||||
@formae.FieldHint {}
|
@formae.FieldHint {}
|
||||||
memory: Int
|
memory: Int
|
||||||
|
|
||||||
|
@formae.FieldHint {}
|
||||||
|
onboot: Int = 0
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
1
testdata/resource-update.pkl
vendored
1
testdata/resource-update.pkl
vendored
@@ -33,5 +33,6 @@ forma {
|
|||||||
ostemplate = "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz"
|
ostemplate = "local:vztmpl/alpine-3.22-default_20250617_amd64.tar.xz"
|
||||||
cores = 2
|
cores = 2
|
||||||
memory = 1024
|
memory = 1024
|
||||||
|
onboot = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
types.go
2
types.go
@@ -14,6 +14,7 @@ type LXCProperties struct {
|
|||||||
OSTemplate string `json:"ostemplate,omitempty"`
|
OSTemplate string `json:"ostemplate,omitempty"`
|
||||||
Cores int `json:"cores"`
|
Cores int `json:"cores"`
|
||||||
Memory int `json:"memory"`
|
Memory int `json:"memory"`
|
||||||
|
OnBoot int `json:"onboot"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReadRequest struct {
|
type ReadRequest struct {
|
||||||
@@ -71,6 +72,7 @@ type StatusLXCConfig struct {
|
|||||||
Swap int `json:"swap"`
|
Swap int `json:"swap"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Digest string `json:"digest"`
|
Digest string `json:"digest"`
|
||||||
|
OnBoot int `json:"onboot"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatusLXCConfigResponse struct {
|
type StatusLXCConfigResponse struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user