VMware {code} Community
daniellynn
Enthusiast
Enthusiast
Jump to solution

Some confusion about VirtualDiskManager

I'm coming across a problem with any method in the VirtualDiskManager class and since it's new, there doesn't seem to be any good example code out there.

First, I don't know if there's a real distinction, but I'm using C#.

In many of the methods in the API, the sytax definition will ask for an arguement "ManagedObjectReference _this" where it says that it's looking for the object that's calling it. That seems to be misleading. I've found that, for example, the function:

UnregisterVM(ManagedObjectReference _this)

you actually need to pass it a reference to the VM you want to unregister. In most cases, it's pretty intuitive, but I'm not clear on what it should reference in the VirtualDiskManager cases.

To give a concrete example, I'm trying to delete a virtual disk, so I'm running DeleteVirtualDisk_Task(). The code looks something like this:

service.DeleteVirtualDiskTask(???, "[datastore] Virtdisk/Virtdisk.vmdk", _dataCenterRef);

Documentation says the first arguement is ManagedObjectReference _this and it refers to the VirtualDiskManager that it's called against, but that has no properties of its own, so I don't understand how you would do that. So, not sure what to put there. Anyone use any of these tasks themselves and have any suggestions, or are there other ways to do it?

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
tos2k
Expert
Expert
Jump to solution

There are a few samples in this forums, I found 11 results, so keep on searching here!

Here my sample code

> servEsx.DeleteVirtualDisk_Task(servEsx.RetrieveServiceContent(ServiceInstance).virtualDiskManager, file, GetDefaultDatacenter(s));

where servEsx is the VimApi.VimService referencing en ESX server. The rest is pretty straight forward...

Tos2k

View solution in original post

Reply
0 Kudos
5 Replies
tos2k
Expert
Expert
Jump to solution

There are a few samples in this forums, I found 11 results, so keep on searching here!

Here my sample code

> servEsx.DeleteVirtualDisk_Task(servEsx.RetrieveServiceContent(ServiceInstance).virtualDiskManager, file, GetDefaultDatacenter(s));

where servEsx is the VimApi.VimService referencing en ESX server. The rest is pretty straight forward...

Tos2k

Reply
0 Kudos
daniellynn
Enthusiast
Enthusiast
Jump to solution

Thanks. That makes a lot of sense now. I was still encountering errors, which I traced ot the fact that my virtualDiskManger was null, but then I came across your other post:

http://communities.vmware.com/message/800719#800719

so I guess I'll have to open a separate connection to an ESX server for that.

Thanks again.

Reply
0 Kudos
tos2k
Expert
Expert
Jump to solution

Hi!

That is right. I hope I am not going too far when saying that VC of VI4 will provide a virtualdiskmanager then Smiley Wink

Tos2k

Reply
0 Kudos
daniellynn
Enthusiast
Enthusiast
Jump to solution

I've encountered one more oddity that maybe you know the answer to.

I've included my code below:

if (_dataCenterRef == null)

{

return "No dc";

}

if (ESXsic.virtualDiskManager == null)

{

return "no vdm";

}

ESXservice.DeleteVirtualDisk_Task(ESXsic.virtualDiskManager, "\[blueteamiscsi\] DantestVMforDeletion", _dataCenterRef);

and I've also tried passing it the path "\[blueteamiscsi\] DantestVMforDeletion/DantestVMforDeletion.vmdk" and in both cases, I get this error:

System.Web.Services.Protocols.SoapException: The request refers to an object that no longer exists or has never existed.

at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)

at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

at VimApi.VimService.DeleteVirtualDisk_Task(ManagedObjectReference _this, String name, ManagedObjectReference datacenter)

at HMSVMPortal.HMSVMPortal.DeleteVM(String DataCenterName, String VMName) in C:\Documents and Settings\dlynn\My Documents\Visual Studio 2005\Projects\WebService1\WebService1\HMSVMPortal.asmx.cs:line 836

Line 836 is the DeleteVirtualDisk_Task line. Since I check the disk manager and datacenter reference (and I use it successfully earlier) I'd have to assume it's a problem with the path, but I've checked that it's correct - not real clear what I could be missing though.

Thanks for any help you might be able to provide.

Reply
0 Kudos
tos2k
Expert
Expert
Jump to solution

Hi!

Three comments:

1) Consider that the moRef to the datacenter is different in VC and on the ESX directly, as an ESX server is just capable of only one datacenter. In fact the moRef for the datacenter on an/each ESX is same for all ESX's!

2) Consider that the virtualDiskManager has been introduced with ESX 3.5, so older versions of ESX do not have it!

3) DeleteVirtualDisk will delete virtual disks only, for deleting plain files and folder use DeleteDatastoreFile

HTH, Tos2k