VMware {code} Community
sochry
Enthusiast
Enthusiast

Deploying OVF from Template

Any idea as to why I receive a "Object of type 'System.Xml.XmlNode[]' cannot be converted to type 'VMware.Vim.HttpNfcLeaseState'." exception when converting the HttpNfcLease MOR to a MO with the GetView call? Thanks in advance.

try

{

OvfManager ovfManager = (OvfManager) vimClient.GetView(vimClient.ServiceContent.OvfManager, null);

OvfParseDescriptorParams pdp = new OvfParseDescriptorParams();

pdp.DeploymentOption = "";

pdp.Locale = "";

StreamReader ovfFileContents = new StreamReader(@"C:\VA-LAMP.ovf");

string ovfDescriptor = ovfFileContents.ReadToEnd();

ovfFileContents.Close();

OvfParseDescriptorResult ovfParseDescriptorResult = ovfManager.ParseDescriptor(ovfDescriptor, pdp);

Datastore dataStore = GetDataStore();

OvfCreateImportSpecParams cisp = new OvfCreateImportSpecParams();

cisp.DeploymentOption = "";

cisp.EntityName = "";

cisp.Locale = "";

OvfCreateImportSpecResult ovfCreateImportSpecResult = ovfManager.CreateImportSpec(ovfDescriptor, rp.MoRef, dataStore.MoRef, cisp);

HostSystem host = GetHost();

Datacenter datacenter = GetDataCenter();

ManagedObjectReference vmFolderMor = datacenter.VmFolder;

ManagedObjectReference httpNfcLeaseMor = rp.ImportVApp(ovfCreateImportSpecResult.ImportSpec, vmFolderMor, host.MoRef);

HttpNfcLease httpNfcLease = (HttpNfcLease)vimClient.GetView(httpNfcLeaseMor, null);

}

catch (Exception e)

{

//End up in here. Smiley Sad

}

0 Kudos
9 Replies
Steve_Jin
Expert
Expert

It's not clear why you got the exception when calling GetView() method. All you passed in there is an MOR object and null, and XmlNode[] should be out of picture toally...

My gut feeling is that there is something wrong with the de-serializer. You may want to searh MS forum on their web service engine.

Alternatively, you can try Java. We have a working sample at vijava.sf.net - posting nov 7.

Steve JIN

Author of VMware VI and vSphere SDK (Prentice Hall)

Creator of open source vSphere (VI) Java API(Tutorial, Testimonials, Download, Samples)

Blog: DoubleCloud.ORG ( Top 10 Best Practices,[Common Mistakes|http://www.doublecloud.org/2010/01/31/common-mistakes-using-vmware-vi-and-vsphere-sdk/], Tiny REST API)

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
sochry
Enthusiast
Enthusiast

Thanks for the response. I will search the MS forum and check out the vijava.sf.net site. Unforutnatley, Java is not an option at this point but your book has helped me in the past. I just convert to C# on the fly. Examples are always useful.

Socrates

0 Kudos
sochry
Enthusiast
Enthusiast

Thanks, there was indeed a bug in the de-serializer code. I have a workaround and have ported most of the Java example you provided to c#. The only problem I have is keeping the lease alive long enough to complete the upload of the VMDK files. Do you have the code that is behind this call:

leaseUpdater = new LeaseProgressUpdater(httpNfcLease, 5000);

leaseUpdater.start();

What keeps the lease alive? leaseUpdater.setPercent(progressPercent);?

0 Kudos
Steve_Jin
Expert
Expert

It's in the same directory as the samples:

Steve JIN

Author of VMware VI and vSphere SDK (Prentice Hall)

Creator of open source vSphere (VI) Java API(Tutorial, Testimonials, Download, Samples)

Blog: DoubleCloud.ORG ( Top 10 Best Practices,[Common Mistakes|http://www.doublecloud.org/2010/01/31/common-mistakes-using-vmware-vi-and-vsphere-sdk/], Tiny REST API)

Steve JIN Author of VMware VI and vSphere SDK; Creator of open source VI Java API (http://vijava.sf.net); Blogger at http://www.doublecloud.org
0 Kudos
sochry
Enthusiast
Enthusiast

Your quote "Two samples illustrating importing and exporting OVF from(to) local disk. You can easily adapt the code to import from a URL instead of local disk files."What all would need to change to import from a URL as this is what I need to do?

0 Kudos
grad2112
Contributor
Contributor

can you share the workaround to the de-serializer bug?

0 Kudos
grad2112
Contributor
Contributor

using this code, the problem i'm having is that the Httpnfclease state never changes from intitializing to ready.  In the vsphere client i can see the VM being created but the progress never changes.  Is there a way to refresh the lease state or is that done automatically by the HttpNfcLease class?

0 Kudos
burscikas
Contributor
Contributor

Hello,

could anyone share the way you use to upload vmdk files from url and not from local disk?

thanks in advance

0 Kudos
cstrawinski
Contributor
Contributor

I was looking for the workaround to the deserialization bug too and I just found it here:

http://www.lucd.info/2009/11/08/thick-to-thin-with-powercli-and-the-sdk/#comment-371

Basically, you use the PropertyCollector to manually obtain the HttpNfcLease properties. I found too if you need to use the methods, just manually create the object:

HttpNfcLease _nfcLease = new HttpNfcLease(_vimClient, _morNfcLease);

0 Kudos