Skip to content

Commit

Permalink
Merge pull request #320 from xserrat/Feature-#319
Browse files Browse the repository at this point in the history
Feature: Optional Protection setting
  • Loading branch information
Tinyblargon committed Mar 18, 2024
2 parents 9c58332 + 7c0a64b commit a76eb23
Show file tree
Hide file tree
Showing 2 changed files with 23 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
21 changes: 19 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 @@ -361,6 +368,9 @@ func (config ConfigQemu) mapToApiValues(currentConfig ConfigQemu) (rebootRequire
if config.Onboot != nil {
params["onboot"] = *config.Onboot
}
if config.Protection != nil {
params["protection"] = *config.Protection
}
if config.QemuOs != "" {
params["ostype"] = config.QemuOs
}
Expand Down Expand Up @@ -569,6 +579,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 +1097,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 a76eb23

Please sign in to comment.