Skip to content

Commit

Permalink
Feature: Optional Protection setting
Browse files Browse the repository at this point in the history
  • Loading branch information
xserrat committed Mar 10, 2024
1 parent 9c58332 commit d4a9e80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 16 additions & 2 deletions proxmox/config_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit d4a9e80

Please sign in to comment.