Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Optional Protection setting #320

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've update this JSON sample because with the previous structure I've got an error during the Unmarshal:

./proxmox-api-go installQemu proxmox-node-name < qemu1.json
2024/03/10 11:41:02 json: cannot unmarshal string into Go struct field ConfigQemu.iso of type proxmox.IsoFile

"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
Loading