VMware {code} Community
exzted
Contributor
Contributor

copyVirtualDisk_Task doesn't work (Java SDK2.5 API)

Hi there,

i split up my previous thread because it covers two different questions.

Here is the 2nd question out of my first thread:

While discovering the 2.5 JAVA API i'm also trying to work with the VirtualDiskManager, but i'm stuck.

I don't see how to get this copyVirtualDisk_Task running. It always reports an error: One of the parameters supplied is invalid.

Here is an example:

ManagedObjectReference dc = getDatacenterOfCurrentHost(); // method which returns the mor of primary datacenter of current connected host. Should be always ha-datacenter if directly connected to host.

String sourcePath = "\[" + datastore + "] " + vmName + "/" + vmdk.getName(); // source path of a 2gbsparse vmdk

String destinationPath = "\[" + datastore + "] " + vmName + "/" + getNewName(vmdk); // destination the same as source but another name

VirtualDiskSpec vspec = new VirtualDiskSpec();

vspec.setDiskType(VirtualDiskType._preallocated);

vspec.setAdapterType(VirtualDiskAdapterType._lsiLogic);

ManagedObjectReference task = commPort.copyVirtualDisk_Task(sic.getVirtualDiskManager(), sourcePath, dc, destinationPath, null, vspec, Boolean.TRUE);

task always returning an error:

General fault caused by file.

One of the parameters supplied is invalid

AxisFault

faultCode: Server.generalException

faultSubcode:

faultString:

faultActor:

faultNode:

faultDetail:

exceptionName:com.vmware.vim25.FileFault

I'm not able to find my mistake.

If i change sourcePath, so that it's not an existing file in datastore, i get the correct error, that the webservice was unable to find that file.

Therefore the source and destination parameters should be right.

The ManagedObjectReference of the datacenter (dc) is of type Datacenter. It's name is ha-datacenter and the childPropertie "datastore" contains the datastore used in source and destination path.

I missed something out, but what...

Environment:

Communication is directly through VI3 SDK 2.5 to an ESXi host

The VirtualDiskManager-Object isn't null, like it would be while connecting through VC.

The virtual disk is a 2gb sparse vmdk, which should be converted to an preallocated (thick) vmdk.

Any ideas?

greets,

ex

Reply
0 Kudos
10 Replies
tos2k
Expert
Expert

Hi!

One more try:

Where do these constants like VirtualDiskType._preallocated come from?

The only fields in the vspec I am setting are same to yours, disktype has to be of thin, thick or sparse2Gb (case sensitiv!). For adatapterType I just got lsiLogic to work, do the others (which are available at yours?) work for you?

So possibly your adapterType/diskType values may be wrong?

Tos2k

pomattic
Contributor
Contributor

Something I found is that VirtualDiskSpec is extended by FileBackedVirtualDiskSpec and DeviceBackedVirtualDiskSpec.

Using FileBackedVirtuaDiskSpec I was able to get this function to work (of course first I successfully reproduced your error : )

ManagedObjectReference vdiskManagerRef = sic.getVirtualDiskManager();

ManagedObjectReference dataCenter = getDataCenter();

String src, dest;

FileBackedVirtualDiskSpec fbvspec= new FileBackedVirtualDiskSpec();

fbvspec.setAdapterType(VirtualDiskAdapterType._lsiLogic);

fbvspec.setCapacityKb(12000000);

fbvspec.setDiskType(VirtualDiskType._thin);

//VirtualDiskSpec vspec = new VirtualDiskSpec();

//vspec.setDiskType(VirtualDiskType._preallocated);

//vspec.setAdapterType(VirtualDiskAdapterType._lsiLogic);

src= "["] "+source;

dest= "["] "+destination;

ManagedObjectReference taskRef = connexion.copyVirtualDisk_Task(vdiskManagerRef, src, dataCenter, dest, null, fbvspec, Boolean.TRUE);

waitForCompletion(taskRef);

Hope that helps.

M@

Message was edited by: pomattic (spelling corrections) (and could someone tell me how to avoid the square bracket thing)

exzted
Contributor
Contributor

Great!

Thanks to you tos2k... it's working (but not as intended, see notes)

If i had known that this part of the api is as experimental as the cold fusion, i didn't spent so much time for trying this piece of very experimentel code.

Some Notes:

  • VirtualDiskManager only available on esx hosts, no VC (but known before the testing, only listed for a complete overview, for those finding this thread)

  • Overwriting is not supported, or doesn't work. Neither Boolean.TRUE, new Boolean(true), nor true is working for the parameter <force>. Everytime there is an error: file already exists.

  • Parameter <destSpec> is completly useless. It only supports diskType and adapterType as it is defined in the source vmdk. So this copyTask can ONLY copy a vmdk as it is. There seems to be no possibility to convert while copying, like the vmkfstools can do.

And the constants are mentioned in the RefGuide

A simple question before trying new experimental methods:

Is there a possibility to convert a virtual disk like the vmkfstools can do with die VI3 SDK2.5 API for Java?

Because of using ESXi-only i've got no service console to do it with vmkfstools.

Thanks in advance, and thanks to tos2k and pomattic.

ex

Message was edited by: exzted

pomattic, i wrote/posted before i've read your post. I will try your way and will report if it will work with conversion of vmdks. Maybe...

Reply
0 Kudos
exzted
Contributor
Contributor

@pomattic:

Does the same as VirtualDiskSpec. No conversion possible.

And to use a \[ you have to use the backslash for "escaping" Smiley Wink

Reply
0 Kudos
pomattic
Contributor
Contributor

I always like to get down to be as specific as possible. That is why I like those two extensions. But ya... Experimental eh... : )

M@

Should have figured out the backslash thing... (you'd think I could...)

Reply
0 Kudos
tos2k
Expert
Expert

The constants are not part of the VimSDK, as their containing enumerations do not exists, at least for .NET. But of course some documentation is better than nothing Smiley Wink

For me, the diskType attribute works adequate as an replacement for vmkfstools (dont have a complete overview what else can be done with vmkfstools)

Tos2k

Reply
0 Kudos
exzted
Contributor
Contributor

Some News:

Yeah, some feeling of success...

I was able to convert a sparse2gb vmdk into a monoflat vmdk through this magical api.

Is monoflat the same as a normal vmfs-thick vmdk? It's same size, only it's called monolithicFlat not vmfs in the vmdk-files.

Seems that the diskType-Strings got messed up, or something else. Some do work, others are ignored with an error.

I will test some other Strings for diskType...

You will hear about it here Smiley Wink

Reply
0 Kudos
exzted
Contributor
Contributor

It's magic. Smiley Happy

But also weird and strange.

Following parameters working for me:

Source: 500MB 2gbsparse vmdk => shrinked to 237MB (twoGbMaxExtentSparse)

Working parameters:

monoflat => converts to a thick vmdk 500MB (monolithicFlat)

monosparse => converts to a thin monolitic vmdk 235MB (no additional vmdk-header-file)

2gbsparse => seems to be a copy but other size 235MB (twoGbMaxExtentSparse)

thin => converts to a "thick" 500MB vmdk (vmfs)

So where to report those bugs...or when will be a new release of this api?

Edit:

Thin is a correct thin-provisioned vmdk (disk usage 310MB)

Conclusion: All thick-types don't work...

Reply
0 Kudos
exzted
Contributor
Contributor

I found a solution:

VirtualDiskSpec vspec = new VirtualDiskSpec();

vspec.setDiskType("");

An empty string will do the job.

This will convert/clone to thick.

Reply
0 Kudos
pomattic
Contributor
Contributor

That is some weird stuff...

Good to know for future though. Thanks for keeping us up to date and glad you got your solution.

M@

Reply
0 Kudos