From d4a9e80446339a064271d7adae737ff543728566 Mon Sep 17 00:00:00 2001 From: Xavier Serrat Bordas Date: Sun, 10 Mar 2024 12:07:56 +0100 Subject: [PATCH] Feature: Optional Protection setting --- README.md | 5 ++++- proxmox/config_qemu.go | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a58d69a0..9833eeba 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,10 @@ createQemu JSON Sample: "os": "l26", "cores": 2, "sockets": 1, - "iso": "local:iso/ubuntu-14.04.5-server-amd64.iso", + "iso": { + "storage": "local", + "file": "ubuntu-14.04.5-server-amd64.iso" + }, "disk": { "0": { "type": "virtio", diff --git a/proxmox/config_qemu.go b/proxmox/config_qemu.go index 48956a8b..ad26b834 100644 --- a/proxmox/config_qemu.go +++ b/proxmox/config_qemu.go @@ -64,7 +64,8 @@ type ConfigQemu struct { Nameserver string `json:"nameserver,omitempty"` // TODO should be part of a cloud-init struct (cloud-init option) Node string `json:"node,omitempty"` // Only returned setting it has no effect, set node in the VmRef instead Onboot *bool `json:"onboot,omitempty"` - Pool string `json:"pool,omitempty"` // TODO should be custom type as there are character and length limitations + Pool string `json:"pool,omitempty"` // TODO should be custom type as there are character and length limitations + Protection *bool `json:"protection,omitempty"` QemuCores int `json:"cores,omitempty"` // TODO should be uint QemuCpu string `json:"cpu,omitempty"` // TODO should be custom type with enum QemuDisks QemuDevices `json:"disk,omitempty"` // DEPRECATED use Disks *QemuStorages instead @@ -171,6 +172,10 @@ func (config ConfigQemu) CreateVm(vmr *VmRef, client *Client) (err error) { params["scsihw"] = config.Scsihw } + if config.Protection != nil { + params["protection"] = *config.Protection + } + err = config.CreateQemuMachineParam(params) if err != nil { log.Printf("[ERROR] %q", err) @@ -247,6 +252,9 @@ func (config *ConfigQemu) defaults() { if config.Ipconfig == nil { config.Ipconfig = IpconfigMap{} } + if config.Protection == nil { + config.Protection = util.Pointer(false) + } if config.QemuCores == 0 { config.QemuCores = 1 } @@ -289,7 +297,6 @@ func (config *ConfigQemu) defaults() { if config.Tablet == nil { config.Tablet = util.Pointer(true) } - } func (config ConfigQemu) mapToApiValues(currentConfig ConfigQemu) (rebootRequired bool, params map[string]interface{}, err error) { @@ -569,6 +576,9 @@ func (ConfigQemu) mapToStruct(vmr *VmRef, params map[string]interface{}) (*Confi config.QemuVcpus = vCpu } } + if _, isSet := params["protection"]; isSet { + config.Protection = util.Pointer(Itob(int(params["protection"].(float64)))) + } if _, isSet := params["scsihw"]; isSet { config.Scsihw = params["scsihw"].(string) } @@ -1084,6 +1094,10 @@ func (config ConfigQemu) UpdateConfig(vmr *VmRef, client *Client) (err error) { configParams["onboot"] = *config.Onboot } + if config.Protection != nil { + configParams["protection"] = *config.Protection + } + if config.Tablet != nil { configParams["tablet"] = *config.Tablet }