Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Example of how to attach a disk from one vm to another. #3503

Closed
Smithx10 opened this issue Jul 20, 2024 · 4 comments
Closed

Example of how to attach a disk from one vm to another. #3503

Smithx10 opened this issue Jul 20, 2024 · 4 comments

Comments

@Smithx10
Copy link

While trying to attempt some automation, we hit a snag where we could not figure out how to Add / Attach a vmdk from 1 vm to another.

Is there some simple steps on how to do this? I've had to no luck. An example in the documentation would be helpful.

Copy link
Contributor

Howdy 🖐   Smithx10 ! Thank you for your interest in this project. We value your feedback and will respond soon.

If you want to contribute to this project, please make yourself familiar with the CONTRIBUTION guidelines.

@dougm
Copy link
Member

dougm commented Aug 7, 2024

Hi @Smithx10 , are you looking to do this with govc or with the API?

@Smithx10
Copy link
Author

Smithx10 commented Aug 7, 2024

I found it here: Not sure if this is the only way, but it worked. Was a bit of a strange to get a disk from a VM and then have to override its size to 0 to Add it to another machine.

		// Need FileOperation=="" to add an existing disk, see object.VirtualMachine.configureDevice
		disk.CapacityInKB = 0
		disk.CapacityInBytes = 0
		if err = vm.AddDevice(ctx, d); err != nil {
			t.Error(err)
		}

// Need FileOperation=="" to add an existing disk, see object.VirtualMachine.configureDevice

@dougm
Copy link
Member

dougm commented Sep 9, 2024

Yes, that is a bit strange, you can use the spec+method underneath AddDevice to avoid that. But, you may want to considering using FCD (First Class Disk) instead. Recent example went in:
https://github.com/vmware/govmomi/blob/main/govc/disk/attach.go#L96
https://github.com/vmware/govmomi/blob/main/govc/disk/detach.go#L65

@vmware vmware locked and limited conversation to collaborators Oct 7, 2024
@tenthirtyam tenthirtyam converted this issue into discussion #3582 Oct 7, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants