Skip to content

Commit

Permalink
move pool config out of maptoAPI
Browse files Browse the repository at this point in the history
- Testing showed pool wasn't a supported option when Updating a QEMU VM (/config endpoint). Move pool setting out of maptoAPI, set only when creating a VM before calling CreateQemuVm
- Tested CloneVm and Update methods and confirmed they now handle Pools correctly
  • Loading branch information
mpywell committed Oct 21, 2024
1 parent f3a833e commit 94debce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
8 changes: 5 additions & 3 deletions proxmox/config_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ func (config ConfigQemu) mapToAPI(currentConfig ConfigQemu, version Version) (re
if config.Onboot != nil {
params["onboot"] = *config.Onboot
}
if config.Pool != nil {
params["pool"] = *config.Pool
}
if config.Protection != nil {
params["protection"] = *config.Protection
}
Expand Down Expand Up @@ -720,6 +717,11 @@ func (newConfig ConfigQemu) setAdvanced(currentConfig *ConfigQemu, rebootIfNeede
if err != nil {
return
}
// pool field unsupported by /nodes/%s/vms/%d/config used by update (currentConfig != nil).
// To be able to create directly in a configured pool, add pool to mapped params from ConfigQemu, before creating VM
if newConfig.Pool != nil && *newConfig.Pool != "" {
params["pool"] = *newConfig.Pool
}
exitStatus, err = client.CreateQemuVm(vmr.node, params)
if err != nil {
return false, fmt.Errorf("error creating VM: %v, error status: %s (params: %v)", err, exitStatus, params)
Expand Down
15 changes: 0 additions & 15 deletions proxmox/config_qemu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3485,21 +3485,6 @@ func Test_ConfigQemu_mapToAPI(t *testing.T) {
config: &ConfigQemu{Memory: &QemuMemory{Shares: util.Pointer(QemuMemoryShares(0))}},
currentConfig: ConfigQemu{Memory: &QemuMemory{Shares: util.Pointer(QemuMemoryShares(20000))}},
output: map[string]interface{}{"delete": "shares"}}}},
{category: `Pool`,
create: []test{
{name: `Pool personal`,
config: &ConfigQemu{Pool: util.Pointer(PoolName("personal"))},
output: map[string]interface{}{"pool": PoolName("personal")}}},
createUpdate: []test{
{name: `Pool shared`,
config: &ConfigQemu{Pool: util.Pointer(PoolName("shared"))},
currentConfig: ConfigQemu{Pool: util.Pointer(PoolName("personal"))},
output: map[string]interface{}{"pool": PoolName("shared")}}},
update: []test{
{name: `Pool shared`,
config: &ConfigQemu{Pool: util.Pointer(PoolName("shared"))},
currentConfig: ConfigQemu{Pool: util.Pointer(PoolName("personal"))},
output: map[string]interface{}{"pool": PoolName("shared")}}}},
{category: `Serials`,
createUpdate: []test{
{name: `delete non existing`,
Expand Down

0 comments on commit 94debce

Please sign in to comment.