We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi! Sorry for i am asking here =\
I want to add existind HDD from one VM to another.
I am trying something like this. Get disks:
for _, device := range devices { currentDeviceLabel := device.GetVirtualDevice().DeviceInfo.GetDescription().Label if strings.Contains(strings.ToLower(currentDeviceLabel), "hard disk"){ disks = append(disks, device) } return disks
And try connect received disk to another VM:
func addDisk(vm *object.VirtualMachine, disk types.BaseVirtualDevice) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() spec := types.VirtualMachineConfigSpec{ DeviceChange : []types.BaseVirtualDeviceConfigSpec { &types.VirtualDeviceConfigSpec{ Operation: types.VirtualDeviceConfigSpecOperationAdd, FileOperation: types.VirtualDeviceConfigSpecFileOperationCreate, Device: disk, }, }, } result, err := vm.Reconfigure(ctx, spec) if err != nil { log.Fatal(fmt.Sprintf("err: %s", err.Error())) }
I get error: Cannot complete the operation because the file or folder [xxxxxx] xxxxxx/xxxxxx.vmdk already exists How i can add existing disk? Thanks!
Cannot complete the operation because the file or folder [xxxxxx] xxxxxx/xxxxxx.vmdk already exists
The text was updated successfully, but these errors were encountered:
Just don't specify FileOperation if the disk already exists.
The govc vm.disk.attach command does this using the VirtualDeviceList helpers: https://github.com/vmware/govmomi/blob/toolbox-archive/govc/vm/disk/attach.go#L64
In that command, CapacityInKB == 0, but in vm.disk.create CapacityInKB > 0: https://github.com/vmware/govmomi/blob/master/object/virtual_machine.go#L390
Sorry, something went wrong.
@dougm, it helped, thank you!
Working code, maybe it will be helpful for somebody:
spec := types.VirtualMachineConfigSpec{} config := &types.VirtualDeviceConfigSpec{ Device: disk, Operation: types.VirtualDeviceConfigSpecOperationAdd, } spec.DeviceChange = append(spec.DeviceChange, config) result, err := vm.Reconfigure(ctx, spec) if err != nil { log.Fatal(fmt.Sprintf("err: %s", err.Error())) }
No branches or pull requests
Hi! Sorry for i am asking here =\
I want to add existind HDD from one VM to another.
I am trying something like this. Get disks:
And try connect received disk to another VM:
I get error:
Cannot complete the operation because the file or folder [xxxxxx] xxxxxx/xxxxxx.vmdk already exists
How i can add existing disk? Thanks!
The text was updated successfully, but these errors were encountered: