diff --git a/proxmox/config_qemu.go b/proxmox/config_qemu.go index 4816a1b7..8f7db098 100644 --- a/proxmox/config_qemu.go +++ b/proxmox/config_qemu.go @@ -40,6 +40,7 @@ type ConfigQemu struct { Description *string `json:"description,omitempty"` Disks *QemuStorages `json:"disks,omitempty"` EFIDisk QemuDevice `json:"efidisk,omitempty"` // TODO should be a struct + Storage string `json:"storage,omitempty"` // this value is only used when doing a full clone and is never returned FullClone *int `json:"fullclone,omitempty"` // TODO should probably be a bool HaGroup string `json:"hagroup,omitempty"` HaState string `json:"hastate,omitempty"` // TODO should be custom type with enum @@ -849,13 +850,16 @@ storage:xxx */ func (config ConfigQemu) CloneVm(sourceVmr *VmRef, vmr *VmRef, client *Client) (err error) { vmr.SetVmType("qemu") - var storage string + storage := config.Storage fullClone := "1" if config.FullClone != nil { fullClone = strconv.Itoa(*config.FullClone) } - if disk0Storage, ok := config.QemuDisks[0]["storage"].(string); ok && len(disk0Storage) > 0 { - storage = disk0Storage + // if storage is not set, use the storage of the first disk + if storage == "" && len(config.QemuDisks) > 0 { + if disk0Storage, ok := config.QemuDisks[0]["storage"].(string); ok && len(disk0Storage) > 0 { + storage = disk0Storage + } } params := map[string]interface{}{ "newid": vmr.vmId, diff --git a/test/api/Qemu/qemu_clone_test.go b/test/api/Qemu/qemu_clone_test.go index 5088de8d..655eca26 100644 --- a/test/api/Qemu/qemu_clone_test.go +++ b/test/api/Qemu/qemu_clone_test.go @@ -35,6 +35,27 @@ func Test_Clone_Qemu_VM(t *testing.T) { } +func Test_Clone_Qemu_VM_To_Different_Storage(t *testing.T) { + Test := api_test.Test{} + _ = Test.CreateTest() + config := _create_vm_spec(false) + + config.Create(_create_vmref(), Test.GetClient()) + + cloneConfig := _create_vm_spec(false) + + fullClone := 1 + + cloneConfig.Name = "test-qemu02" + cloneConfig.FullClone = &fullClone + cloneConfig.Storage = "other-storage" + + err := cloneConfig.CloneVm(_create_vmref(), _create_clone_vmref(), Test.GetClient()) + + require.NoError(t, err) + +} + func Test_Qemu_VM_Is_Cloned(t *testing.T) { Test := api_test.Test{} _ = Test.CreateTest()